From c7d631bbfa438482e875cbfb6d703086dd5b0788 Mon Sep 17 00:00:00 2001 From: Abhisek Dwivedi Date: Fri, 12 Apr 2024 09:57:41 +0530 Subject: [PATCH] Return command status for set-config commands --- deployment/aeroinfo.go | 4 ++-- deployment/cluster.go | 19 +++++++++++++------ test/containers.go | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/deployment/aeroinfo.go b/deployment/aeroinfo.go index 0157489..16f7deb 100644 --- a/deployment/aeroinfo.go +++ b/deployment/aeroinfo.go @@ -61,10 +61,10 @@ func SetMigrateFillDelay(log logr.Logger, policy *aero.ClientPolicy, allHosts [] // SetConfigCommandsOnHosts runs set config command for dynamic config on all the given cluster nodes func SetConfigCommandsOnHosts(log logr.Logger, policy *aero.ClientPolicy, allHosts, selectedHosts []*HostConn, - cmds []string) error { + cmds []string) (map[string]bool, error) { c, err := newCluster(log, policy, allHosts, selectedHosts) if err != nil { - return fmt.Errorf("unable to create a cluster copy for running aeroinfo: %v", err) + return nil, fmt.Errorf("unable to create a cluster copy for running aeroinfo: %v", err) } return c.setConfigCommandsOnHosts(cmds, selectedHosts) diff --git a/deployment/cluster.go b/deployment/cluster.go index 9370630..f2e31c5 100644 --- a/deployment/cluster.go +++ b/deployment/cluster.go @@ -852,7 +852,7 @@ func (c *cluster) setMigrateFillDelay(migrateFillDelay int, hosts []*HostConn) e cmd := fmt.Sprintf("set-config:context=service;migrate-fill-delay=%d", migrateFillDelay) - if err := c.setConfigCommandsOnHosts([]string{cmd}, hosts); err != nil { + if _, err := c.setConfigCommandsOnHosts([]string{cmd}, hosts); err != nil { return err } @@ -862,36 +862,43 @@ func (c *cluster) setMigrateFillDelay(migrateFillDelay int, hosts []*HostConn) e } // setConfigCommandsOnHosts runs the set-config commands on the hosts. -func (c *cluster) setConfigCommandsOnHosts(cmds []string, hosts []*HostConn) error { +func (c *cluster) setConfigCommandsOnHosts(cmds []string, hosts []*HostConn) (map[string]bool, error) { hostIDs := getHostIDsFromHostConns(hosts) + cmdStatusMap := map[string]bool{} log := c.log.WithValues("nodes", hostIDs) log.V(1).Info("Running set-config") // Run all set-config commands on all hosts for _, cmd := range cmds { + // insert command in the status map + cmdStatusMap[cmd] = false + infoResults, iErr := c.infoOnHosts(hostIDs, cmd) if iErr != nil { - return iErr + return cmdStatusMap, iErr } for id, info := range infoResults { output, err := info.toString(cmd) if err != nil { - return fmt.Errorf( + return cmdStatusMap, fmt.Errorf( "ServerError: failed to execute set-config command %s on node %s: %v", cmd, id, err) } if !strings.EqualFold(output, "ok") { - return fmt.Errorf("ServerError: failed to execute set-config"+ + return cmdStatusMap, fmt.Errorf("ServerError: failed to execute set-config"+ " command %s on node %s: %v", cmd, id, output) } } + + // update command status in the status map + cmdStatusMap[cmd] = true } log.V(1).Info("Finished running set-config") - return nil + return cmdStatusMap, nil } func (c *cluster) findHost(hostID string) (*host, error) { diff --git a/test/containers.go b/test/containers.go index e0b4664..543c493 100644 --- a/test/containers.go +++ b/test/containers.go @@ -23,7 +23,7 @@ var PortStart = 10000 var IP = "127.0.0.1" var WordDirAbs = "test/work" var Image = "aerospike/aerospike-server-enterprise:7.0.0.2" -var ContainerPrefix = "aerospike_mgmt_lib_test_" //nolint:gosec // This is not a credential +var ContainerPrefix = "aerospike_mgmt_lib_test_" var User = "admin" var Password = "admin"