From fcaee7ff65fd08f3cc71e4002fc1e5a22317a17b Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 10 May 2023 12:31:44 +0530 Subject: [PATCH] JIRA: PMK-5805 (#350) Allow decommission for partial installation of hostagent Similar fix implemented in prep-node --- pkg/pmk/checkNode.go | 23 ++++++++++------------- pkg/pmk/decomissionNode.go | 17 +++++++---------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/pkg/pmk/checkNode.go b/pkg/pmk/checkNode.go index 0aaab11..2e64d85 100644 --- a/pkg/pmk/checkNode.go +++ b/pkg/pmk/checkNode.go @@ -86,21 +86,18 @@ func CheckNode(ctx objects.Config, allClients client.Client, auth keystone.Keyst if !v.Result { zap.S().Debug("Platform9 Packages are present") zap.S().Debug("Checking if host is connected or not") - ip, err := allClients.Executor.RunWithStdout("bash", "-c", "hostname -I") + // Directly use host_id instead of relying on IP to get host details + // host_id file is created as part hostagent installation. File missing should mean + // that installation was partial + cmd := `grep host_id /etc/pf9/host_id.conf | cut -d '=' -f2` + hostID, err := allClients.Executor.RunWithStdout("bash", "-c", cmd) if err != nil { - zap.S().Debug("Failed to get host ip") + zap.S().Debugf("Unable to get host id %s", err.Error()) } - ip = strings.Split(ip, " ")[0] - ip = strings.TrimSpace(ip) - var add = []string{ip} - id := allClients.Resmgr.GetHostId(auth.Token, add) - //If node is already connected then resmgr will return hostID - //If hostID is empty then host could be connected to other DU - var connected bool - if len(id) != 0 { - connected = allClients.Resmgr.HostStatus(auth.Token, id[0]) - } else { - zap.S().Fatalf("Hostagent is installed on this host, but this host is not part of the DU %s specified in the config", ctx.Fqdn) + hostID = strings.TrimSpace(hostID) + connected := false + if len(hostID) != 0 { + connected = allClients.Resmgr.HostStatus(auth.Token, hostID) } if connected { zap.S().Debug("Node is already connected") diff --git a/pkg/pmk/decomissionNode.go b/pkg/pmk/decomissionNode.go index d374989..db78dee 100644 --- a/pkg/pmk/decomissionNode.go +++ b/pkg/pmk/decomissionNode.go @@ -80,16 +80,6 @@ func DecommissionNode(cfg *objects.Config, nc objects.NodeConfig, removePf9 bool zap.S().Debug("Failed to get keystone %s", err.Error()) } - // Directly use host_id instead of relying on IP to get host details - cmd := `grep host_id /etc/pf9/host_id.conf | cut -d '=' -f2` - hostID, err := c.Executor.RunWithStdout("bash", "-c", cmd) - if err != nil { - zap.S().Fatalf("Unable to get host id %s", err.Error()) - } - if len(hostID) == 0 { - zap.S().Fatalf("Invalid host id found") - } - hostID = strings.TrimSpace(hostID) hostOS, err := ValidatePlatform(c.Executor) if err != nil { zap.S().Fatalf("Error getting OS version") @@ -104,6 +94,13 @@ func DecommissionNode(cfg *objects.Config, nc objects.NodeConfig, removePf9 bool //check if node is connected to any cluster var nodeInfo qbert.Node var nodeConnectedToDU bool + // Directly use host_id instead of relying on IP to get host details + cmd := `grep host_id /etc/pf9/host_id.conf | cut -d '=' -f2` + hostID, err := c.Executor.RunWithStdout("bash", "-c", cmd) + if err != nil { + zap.S().Debugf("Unable to get host id %s", err.Error()) + } + hostID = strings.TrimSpace(hostID) if len(hostID) != 0 { nodeConnectedToDU = true nodeInfo, err = c.Qbert.GetNodeInfo(auth.Token, auth.ProjectID, hostID)