From 2844d6c21601e5d9c06722a03a5b832540f73ccb Mon Sep 17 00:00:00 2001 From: bizhiyuan Date: Thu, 12 Dec 2024 17:15:05 +0800 Subject: [PATCH] fix the ids list of ExtractHbInfo --- models/heartbeat.go | 8 ++++++-- utils/command.go | 3 ++- utils/host.go | 6 +++--- utils/host_test.go | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/models/heartbeat.go b/models/heartbeat.go index cf6855d..742743d 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -228,7 +228,6 @@ type HBInfo struct { // ExtractHbInfo reorganizes heartbeat information format func ExtractHbInfo(hbInfo []map[string]string) ([]map[string]string, []string) { var hbDictList []map[string]string - var ids []string if len(hbInfo) == 0 { return nil, nil @@ -251,7 +250,7 @@ func ExtractHbInfo(hbInfo []map[string]string) ([]map[string]string, []string) { } hbDictList = append(hbDictList, hbDict) } - return hbDictList, ids + return hbDictList, numIds } // get net heartbeat info from corosync conf @@ -470,6 +469,11 @@ func GetConnectedNetLinksId() []string { return ConnectedLinkIds } +func SyncCorosyncConf() error { + _, err := utils.RunCommand(utils.CmdSyncCorosyncConf) + return err +} + func GetCurrentLinkIds() []string { linksInfo, _ := ExtractHbInfoFromConf() ids := make([]string, 0, len(linksInfo)) diff --git a/utils/command.go b/utils/command.go index 81f3505..1cf5d08 100644 --- a/utils/command.go +++ b/utils/command.go @@ -33,7 +33,7 @@ const ( CmdQueryConstraints = "cibadmin --query --scope constraints" CmdQueryResourcesById = "cibadmin --query --scope resources|grep 'id=\"%s\"'" - CmdStartCluster = "pcs cluster start " + CmdStartCluster = "pcs cluster start --all " CmdStopClusterLocal = "pcs cluster stop " CmdStopCluster = "pcs cluster stop --all" CmdSetupCluster = "pcs cluster setup hacluster" @@ -98,6 +98,7 @@ const ( CmdHbStatusS = "corosync-cfgtool -s" CmdUpdateLink = "pcs cluster link update %s %s" CmdUpdateLinkForce = CmdUpdateLink + " --force" + CmdSyncCorosyncConf = "pcs cluster sync" ) // RunCommand runs the command and get the result diff --git a/utils/host.go b/utils/host.go index c45b4ba..e2aaab0 100644 --- a/utils/host.go +++ b/utils/host.go @@ -20,7 +20,7 @@ import ( ) func GetNodeList() ([]map[string]string, error) { - config, err := getCorosyncConfig() + config, err := GetCorosyncConfig() if err != nil { return nil, errors.New("read config from /etc/corosync/corosync.conf failed") } @@ -39,7 +39,7 @@ type CorosyncConfig struct { Logging map[string]interface{} } -func getCorosyncConfig() (CorosyncConfig, error) { +func GetCorosyncConfig() (CorosyncConfig, error) { var result CorosyncConfig f, err := os.Open(settings.CorosyncConfFile) if err != nil { @@ -169,7 +169,7 @@ func getCorosyncConfig() (CorosyncConfig, error) { return result, nil } -func setCorosyncConfig(conf CorosyncConfig, confFile string) error { +func SetCorosyncConfig(conf CorosyncConfig, confFile string) error { var sb strings.Builder // Write totem section sb.WriteString("totem {\n") diff --git a/utils/host_test.go b/utils/host_test.go index cb017e2..64b710d 100644 --- a/utils/host_test.go +++ b/utils/host_test.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * ha-api licensed under the Mulan Permissive Software License, Version 2. + * ha-api licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: yangzhao_kl * Date: Fri Jan 22 17:27:48 2021 +0800 @@ -13,7 +13,7 @@ import ( ) func TestGetCorosyncConfig(t *testing.T) { - result, err := getCorosyncConfig() + result, err := GetCorosyncConfig() if err != nil { fmt.Println(err) return -- Gitee