From 232206f65cc5880c159a28f8d25943c528cdcfbc Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 18:48:25 +0530 Subject: [PATCH 01/12] ci: add asup validation check --- integration/test/docker_installer_test.go | 20 ++++++++++++++++++++ integration/test/installer/harvest.go | 14 ++++++++++++++ integration/test/installer/native.go | 4 +++- integration/test/installer/rpm.go | 3 +++ integration/test/utils/utils.go | 11 +++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/integration/test/docker_installer_test.go b/integration/test/docker_installer_test.go index 720906a21..9289a7972 100644 --- a/integration/test/docker_installer_test.go +++ b/integration/test/docker_installer_test.go @@ -8,6 +8,7 @@ import ( "github.com/Netapp/harvest-automation/test/installer" "github.com/Netapp/harvest-automation/test/setup" "github.com/Netapp/harvest-automation/test/utils" + "strings" "testing" ) @@ -27,4 +28,23 @@ func TestDockerInstall(t *testing.T) { docker.CopyFile(containerId, fileRestName, installer.HarvestHome+"/"+setup.RestPerfDefaultFile) } docker.ReStartContainers("poller") + ids := docker.GetContainerID("poller") + id := ids[0] + if !isValidAsup(id) { + panic("Asup validation failed") + } +} + +func isValidAsup(containerName string) bool { + out, err := utils.Execute("docker", "container", "exec", containerName, "autosupport/asup", "--version") + if err != nil { + fmt.Printf("error %s\n", err) + return false + } + if !strings.Contains(out, "endpoint:stable") { + fmt.Printf("asup endpoint is not stable %s\n", out) + return false + } + fmt.Printf("asup validation successful %s\n", out) + return true } diff --git a/integration/test/installer/harvest.go b/integration/test/installer/harvest.go index 65d28600d..e03e63508 100644 --- a/integration/test/installer/harvest.go +++ b/integration/test/installer/harvest.go @@ -82,3 +82,17 @@ func (h *Harvest) GetPollerInfo() []core.Poller { } return pollerArray } + +func (d *Harvest) IsValidAsup(asupExecPath string) bool { + out, err := utils.Execute(asupExecPath, "--version") + if err != nil { + fmt.Printf("error %s\n", err) + return false + } + if !strings.Contains(out, "endpoint:stable") { + fmt.Printf("asup endpoint is not stable %s\n", out) + return false + } + fmt.Printf("asup validation successfull %s\n", out) + return true +} diff --git a/integration/test/installer/native.go b/integration/test/installer/native.go index d3a018200..a13e34762 100644 --- a/integration/test/installer/native.go +++ b/integration/test/installer/native.go @@ -39,7 +39,9 @@ func (n *Native) Install() bool { } harvestObj.Start() status := harvestObj.AllRunning() - return status + asupExecPath := HarvestHome + "/" + "autosupport/asup" + isValidAsup := harvestObj.IsValidAsup(asupExecPath) + return status && isValidAsup } func (n *Native) Upgrade() bool { diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index bf9e0e794..9f890ad64 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -39,6 +39,9 @@ func (r *RPM) Install() bool { } //use file directly from the repo harvestObj.Start() status := harvestObj.AllRunning() + asupExecPath := HarvestHome + "/" + "autosupport/asup" + isValidAsup := harvestObj.IsValidAsup(asupExecPath) + return status && isValidAsup return status } diff --git a/integration/test/utils/utils.go b/integration/test/utils/utils.go index 9287719d5..a3b89eb8f 100644 --- a/integration/test/utils/utils.go +++ b/integration/test/utils/utils.go @@ -2,6 +2,7 @@ package utils import ( "bytes" + "context" "encoding/json" "fmt" "github.com/netapp/harvest/v2/pkg/conf" @@ -388,3 +389,13 @@ func MarshalStack(err error) interface{} { } return string(trace) } + +func Execute(command string, args ...string) (out string, err error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + var outb []byte + cmd := exec.CommandContext(ctx, command, args...) + outb, err = cmd.Output() + return string(outb), err +} From 0ae192e3a593207026af839a4394729bc979788f Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 21:26:10 +0530 Subject: [PATCH 02/12] ci: add asup validation check --- integration/test/docker_installer_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/integration/test/docker_installer_test.go b/integration/test/docker_installer_test.go index 9289a7972..2ba4db480 100644 --- a/integration/test/docker_installer_test.go +++ b/integration/test/docker_installer_test.go @@ -29,10 +29,15 @@ func TestDockerInstall(t *testing.T) { } docker.ReStartContainers("poller") ids := docker.GetContainerID("poller") - id := ids[0] - if !isValidAsup(id) { - panic("Asup validation failed") + if len(ids) > 0 { + id := ids[0] + if !isValidAsup(id) { + panic("Asup validation failed") + } + } else { + panic("No pollers running") } + } func isValidAsup(containerName string) bool { From 519a76ce2b4c35b58e02c8c3a1c8f58b03cf7689 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 21:49:37 +0530 Subject: [PATCH 03/12] ci: spelling --- integration/test/installer/harvest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/installer/harvest.go b/integration/test/installer/harvest.go index e03e63508..c10aa1ab0 100644 --- a/integration/test/installer/harvest.go +++ b/integration/test/installer/harvest.go @@ -93,6 +93,6 @@ func (d *Harvest) IsValidAsup(asupExecPath string) bool { fmt.Printf("asup endpoint is not stable %s\n", out) return false } - fmt.Printf("asup validation successfull %s\n", out) + fmt.Printf("asup validation successful %s\n", out) return true } From 949eaea5b19d24644801b5e8002165d447a1529c Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 22:11:10 +0530 Subject: [PATCH 04/12] ci: address review comments --- integration/test/installer/native.go | 2 +- integration/test/installer/rpm.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/test/installer/native.go b/integration/test/installer/native.go index a13e34762..b8a658d82 100644 --- a/integration/test/installer/native.go +++ b/integration/test/installer/native.go @@ -39,7 +39,7 @@ func (n *Native) Install() bool { } harvestObj.Start() status := harvestObj.AllRunning() - asupExecPath := HarvestHome + "/" + "autosupport/asup" + asupExecPath := HarvestHome + "/autosupport/asup" isValidAsup := harvestObj.IsValidAsup(asupExecPath) return status && isValidAsup } diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index 9f890ad64..285c243e4 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -39,7 +39,7 @@ func (r *RPM) Install() bool { } //use file directly from the repo harvestObj.Start() status := harvestObj.AllRunning() - asupExecPath := HarvestHome + "/" + "autosupport/asup" + asupExecPath := HarvestHome + "/autosupport/asup" isValidAsup := harvestObj.IsValidAsup(asupExecPath) return status && isValidAsup return status From 4f651a62b9acadcc4ebeeadcb5162c4337314e5e Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 22:24:16 +0530 Subject: [PATCH 05/12] ci: address review comments --- integration/test/grafana/grafana_mgr.go | 4 ++-- integration/test/installer/docker.go | 2 +- integration/test/installer/harvest.go | 10 +++++----- integration/test/installer/native.go | 2 +- integration/test/installer/rpm.go | 10 ++++++---- integration/test/utils/utils.go | 21 +++++++-------------- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/integration/test/grafana/grafana_mgr.go b/integration/test/grafana/grafana_mgr.go index c332334fd..bf2642543 100644 --- a/integration/test/grafana/grafana_mgr.go +++ b/integration/test/grafana/grafana_mgr.go @@ -34,10 +34,10 @@ func (g *GrafanaMgr) Import(jsonDir string) (bool, string) { if !docker.IsDockerBasedPoller() { //assuming non docker based harvest grafana log.Println("It is non docker based harvest") - importOutput = utils.Exec(installer.HarvestHome, "bin/harvest", nil, "grafana", "import", "--addr", utils.GetGrafanaURL(), directoryOption, jsonDir) + importOutput, _ = utils.Exec(installer.HarvestHome, "bin/harvest", nil, "grafana", "import", "--addr", utils.GetGrafanaURL(), directoryOption, jsonDir) } else { params := []string{"exec", containerIDs[0], "bin/harvest", "grafana", "import", "--addr", "grafana:3000", directoryOption, jsonDir} - importOutput = utils.Run("docker", params...) + importOutput, _ = utils.Run("docker", params...) } if re.MatchString(importOutput) { status = false diff --git a/integration/test/installer/docker.go b/integration/test/installer/docker.go index 9a743b7ff..75d21d6fd 100644 --- a/integration/test/installer/docker.go +++ b/integration/test/installer/docker.go @@ -38,7 +38,7 @@ func (d *Docker) Install() bool { log.Println("Unable to download " + d.path) panic(err) } - imageInfo := utils.Run("docker", "load", "-i", tarFileName) + imageInfo, _ := utils.Run("docker", "load", "-i", tarFileName) imageInfoArray := strings.Split(imageInfo, ":") if len(imageInfoArray) != 3 { panic("docker loaded image has invalid output format") diff --git a/integration/test/installer/harvest.go b/integration/test/installer/harvest.go index c10aa1ab0..bb121e1a4 100644 --- a/integration/test/installer/harvest.go +++ b/integration/test/installer/harvest.go @@ -16,21 +16,21 @@ type Harvest struct { } func (h *Harvest) Start() { - status := utils.Exec(HarvestHome, HarvestBin, nil, "start") + status, _ := utils.Exec(HarvestHome, HarvestBin, nil, "start") fmt.Println(status) time.Sleep(30 * time.Second) h.AllRunning() } func (h *Harvest) StartByHarvestUser() { - status := utils.Exec(HarvestHome, "sudo", nil, "-u", "harvest", HarvestBin, "start") + status, _ := utils.Exec(HarvestHome, "sudo", nil, "-u", "harvest", HarvestBin, "start") fmt.Println(status) time.Sleep(30 * time.Second) h.AllRunning() } func (h *Harvest) Stop() { - status := utils.Exec(HarvestHome, HarvestBin, nil, "stop") + status, _ := utils.Exec(HarvestHome, HarvestBin, nil, "stop") fmt.Println(status) } @@ -56,7 +56,7 @@ func (h *Harvest) AllStopped() bool { func (h *Harvest) GetPollerInfo() []core.Poller { log.Println("Getting all pollers details") - harvestStatus := utils.Exec(HarvestHome, HarvestBin, nil, "status") + harvestStatus, _ := utils.Exec(HarvestHome, HarvestBin, nil, "status") fmt.Println(harvestStatus) rows := strings.Split(harvestStatus, "\n") var pollerArray []core.Poller @@ -84,7 +84,7 @@ func (h *Harvest) GetPollerInfo() []core.Poller { } func (d *Harvest) IsValidAsup(asupExecPath string) bool { - out, err := utils.Execute(asupExecPath, "--version") + out, err := utils.Exec("", asupExecPath, nil, "--version") if err != nil { fmt.Printf("error %s\n", err) return false diff --git a/integration/test/installer/native.go b/integration/test/installer/native.go index b8a658d82..fb8778002 100644 --- a/integration/test/installer/native.go +++ b/integration/test/installer/native.go @@ -27,7 +27,7 @@ func (n *Native) Install() bool { log.Println("Downloaded: " + n.path) Uninstall() log.Println("Installing " + tarFileName) - unTarOutput := utils.Run("tar", "-xf", tarFileName, "--one-top-level=harvest", "--strip-components", "1", "-C", "/opt") + unTarOutput, _ := utils.Run("tar", "-xf", tarFileName, "--one-top-level=harvest", "--strip-components", "1", "-C", "/opt") log.Println(unTarOutput) utils.RemoveSafely(HarvestHome + "/" + harvestFile) utils.UseCertFile(HarvestHome) diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index 285c243e4..4ccf79944 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -28,7 +28,7 @@ func (r *RPM) Install() bool { Uninstall() harvestObj := new(Harvest) log.Println("Installing " + rpmFileName) - installOutput := utils.Run("yum", "install", "-y", rpmFileName) + installOutput, _ := utils.Run("yum", "install", "-y", rpmFileName) log.Println(installOutput) log.Println("Stopping harvest") harvestObj.Stop() @@ -53,14 +53,16 @@ func (r *RPM) Upgrade() bool { utils.PanicIfNotNil(fmt.Errorf("pollers are not in a running state before upgrade")) } versionCmd := []string{"-qa", "harvest"} - previousVersion := strings.TrimSpace(utils.Run("rpm", versionCmd...)) + out, _ := utils.Run("rpm", versionCmd...) + previousVersion := strings.TrimSpace(out) err := utils.DownloadFile(rpmFileName, r.path) utils.PanicIfNotNil(err) log.Println("Downloaded: " + r.path) log.Println("Updating " + rpmFileName) - installOutput := utils.Run("yum", "upgrade", "-y", rpmFileName) + installOutput, _ := utils.Run("yum", "upgrade", "-y", rpmFileName) log.Println(installOutput) - installedVersion := strings.TrimSpace(utils.Run("rpm", versionCmd...)) + out, _ = utils.Run("rpm", versionCmd...) + installedVersion := strings.TrimSpace(out) if previousVersion == installedVersion { utils.PanicIfNotNil(fmt.Errorf("upgrade is failed")) } diff --git a/integration/test/utils/utils.go b/integration/test/utils/utils.go index a3b89eb8f..66d0b9cbd 100644 --- a/integration/test/utils/utils.go +++ b/integration/test/utils/utils.go @@ -25,7 +25,7 @@ const ( GrafanaTokeKey = "grafana_api_token" ) -func Run(command string, arg ...string) string { +func Run(command string, arg ...string) (string, error) { return Exec("", command, nil, arg...) } @@ -44,13 +44,16 @@ func GetConfigDir() string { return "/u/mpeg/harvest" } -func Exec(dir string, command string, env []string, arg ...string) string { +func Exec(dir string, command string, env []string, arg ...string) (string, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + cmdString := command + " " for _, param := range arg { cmdString = cmdString + param + " " } fmt.Println("CMD : " + cmdString) - cmd := exec.Command(command, arg...) + cmd := exec.CommandContext(ctx, command, arg...) cmd.Env = os.Environ() for _, v := range env { cmd.Env = append(cmd.Env, v) @@ -71,7 +74,7 @@ func Exec(dir string, command string, env []string, arg ...string) string { fmt.Println(err) } fmt.Println("-------------------------") - return out.String() + return out.String(), err } // DownloadFile will download a url to a local file. It's efficient because it will @@ -389,13 +392,3 @@ func MarshalStack(err error) interface{} { } return string(trace) } - -func Execute(command string, args ...string) (out string, err error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - var outb []byte - cmd := exec.CommandContext(ctx, command, args...) - outb, err = cmd.Output() - return string(outb), err -} From e0ea5530bc9d0e0b12b9f27ba4cbcb62525c459a Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 22:53:02 +0530 Subject: [PATCH 06/12] ci: address review comments --- integration/test/docker_installer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/docker_installer_test.go b/integration/test/docker_installer_test.go index 2ba4db480..cde214b32 100644 --- a/integration/test/docker_installer_test.go +++ b/integration/test/docker_installer_test.go @@ -41,7 +41,7 @@ func TestDockerInstall(t *testing.T) { } func isValidAsup(containerName string) bool { - out, err := utils.Execute("docker", "container", "exec", containerName, "autosupport/asup", "--version") + out, err := utils.Exec("", docker, nil, "container", "exec", containerName, "autosupport/asup", "--version") if err != nil { fmt.Printf("error %s\n", err) return false From 19a6c93dea9e3847cdc58d3c1b535d872b7435c6 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 14 Apr 2023 23:32:34 +0530 Subject: [PATCH 07/12] ci: address review comments --- integration/test/docker_installer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/docker_installer_test.go b/integration/test/docker_installer_test.go index cde214b32..844342ce4 100644 --- a/integration/test/docker_installer_test.go +++ b/integration/test/docker_installer_test.go @@ -41,7 +41,7 @@ func TestDockerInstall(t *testing.T) { } func isValidAsup(containerName string) bool { - out, err := utils.Exec("", docker, nil, "container", "exec", containerName, "autosupport/asup", "--version") + out, err := utils.Exec("", "docker", nil, "container", "exec", containerName, "autosupport/asup", "--version") if err != nil { fmt.Printf("error %s\n", err) return false From 0d4160f0761c2718d32e440658434fa854493023 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Sat, 15 Apr 2023 00:41:56 +0530 Subject: [PATCH 08/12] ci: address review comments --- integration/test/grafana/grafana_mgr.go | 13 +++++++++++-- integration/test/installer/docker.go | 6 +++++- integration/test/installer/harvest.go | 26 ++++++++++++++++++++----- integration/test/installer/native.go | 6 +++++- integration/test/installer/rpm.go | 14 ++++++++++--- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/integration/test/grafana/grafana_mgr.go b/integration/test/grafana/grafana_mgr.go index bf2642543..2051d6330 100644 --- a/integration/test/grafana/grafana_mgr.go +++ b/integration/test/grafana/grafana_mgr.go @@ -16,6 +16,7 @@ func (g *GrafanaMgr) Import(jsonDir string) (bool, string) { var ( importOutput string status bool + err error ) log.Println("Verify Grafana and Prometheus are configured") var re = regexp.MustCompile(`404|not-found|error`) @@ -34,10 +35,18 @@ func (g *GrafanaMgr) Import(jsonDir string) (bool, string) { if !docker.IsDockerBasedPoller() { //assuming non docker based harvest grafana log.Println("It is non docker based harvest") - importOutput, _ = utils.Exec(installer.HarvestHome, "bin/harvest", nil, "grafana", "import", "--addr", utils.GetGrafanaURL(), directoryOption, jsonDir) + importOutput, err = utils.Exec(installer.HarvestHome, "bin/harvest", nil, "grafana", "import", "--addr", utils.GetGrafanaURL(), directoryOption, jsonDir) + if err != nil { + log.Printf("error %s", err) + panic(err) + } } else { params := []string{"exec", containerIDs[0], "bin/harvest", "grafana", "import", "--addr", "grafana:3000", directoryOption, jsonDir} - importOutput, _ = utils.Run("docker", params...) + importOutput, err = utils.Run("docker", params...) + if err != nil { + log.Printf("error %s", err) + panic(err) + } } if re.MatchString(importOutput) { status = false diff --git a/integration/test/installer/docker.go b/integration/test/installer/docker.go index 75d21d6fd..5360f4e61 100644 --- a/integration/test/installer/docker.go +++ b/integration/test/installer/docker.go @@ -38,7 +38,11 @@ func (d *Docker) Install() bool { log.Println("Unable to download " + d.path) panic(err) } - imageInfo, _ := utils.Run("docker", "load", "-i", tarFileName) + imageInfo, err := utils.Run("docker", "load", "-i", tarFileName) + if err != nil { + log.Printf("error %s", err) + panic(err) + } imageInfoArray := strings.Split(imageInfo, ":") if len(imageInfoArray) != 3 { panic("docker loaded image has invalid output format") diff --git a/integration/test/installer/harvest.go b/integration/test/installer/harvest.go index bb121e1a4..ef86fdc1f 100644 --- a/integration/test/installer/harvest.go +++ b/integration/test/installer/harvest.go @@ -16,21 +16,33 @@ type Harvest struct { } func (h *Harvest) Start() { - status, _ := utils.Exec(HarvestHome, HarvestBin, nil, "start") + status, err := utils.Exec(HarvestHome, HarvestBin, nil, "start") + if err != nil { + log.Printf("error %s", err) + panic(err) + } fmt.Println(status) time.Sleep(30 * time.Second) h.AllRunning() } func (h *Harvest) StartByHarvestUser() { - status, _ := utils.Exec(HarvestHome, "sudo", nil, "-u", "harvest", HarvestBin, "start") + status, err := utils.Exec(HarvestHome, "sudo", nil, "-u", "harvest", HarvestBin, "start") + if err != nil { + log.Printf("error %s", err) + panic(err) + } fmt.Println(status) time.Sleep(30 * time.Second) h.AllRunning() } func (h *Harvest) Stop() { - status, _ := utils.Exec(HarvestHome, HarvestBin, nil, "stop") + status, err := utils.Exec(HarvestHome, HarvestBin, nil, "stop") + if err != nil { + log.Printf("error %s", err) + panic(err) + } fmt.Println(status) } @@ -56,7 +68,11 @@ func (h *Harvest) AllStopped() bool { func (h *Harvest) GetPollerInfo() []core.Poller { log.Println("Getting all pollers details") - harvestStatus, _ := utils.Exec(HarvestHome, HarvestBin, nil, "status") + harvestStatus, err := utils.Exec(HarvestHome, HarvestBin, nil, "status") + if err != nil { + log.Printf("error %s", err) + panic(err) + } fmt.Println(harvestStatus) rows := strings.Split(harvestStatus, "\n") var pollerArray []core.Poller @@ -83,7 +99,7 @@ func (h *Harvest) GetPollerInfo() []core.Poller { return pollerArray } -func (d *Harvest) IsValidAsup(asupExecPath string) bool { +func (h *Harvest) IsValidAsup(asupExecPath string) bool { out, err := utils.Exec("", asupExecPath, nil, "--version") if err != nil { fmt.Printf("error %s\n", err) diff --git a/integration/test/installer/native.go b/integration/test/installer/native.go index fb8778002..29491ff48 100644 --- a/integration/test/installer/native.go +++ b/integration/test/installer/native.go @@ -27,7 +27,11 @@ func (n *Native) Install() bool { log.Println("Downloaded: " + n.path) Uninstall() log.Println("Installing " + tarFileName) - unTarOutput, _ := utils.Run("tar", "-xf", tarFileName, "--one-top-level=harvest", "--strip-components", "1", "-C", "/opt") + unTarOutput, err := utils.Run("tar", "-xf", tarFileName, "--one-top-level=harvest", "--strip-components", "1", "-C", "/opt") + if err != nil { + log.Printf("error %s", err) + panic(err) + } log.Println(unTarOutput) utils.RemoveSafely(HarvestHome + "/" + harvestFile) utils.UseCertFile(HarvestHome) diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index 4ccf79944..608b7ce15 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -28,7 +28,11 @@ func (r *RPM) Install() bool { Uninstall() harvestObj := new(Harvest) log.Println("Installing " + rpmFileName) - installOutput, _ := utils.Run("yum", "install", "-y", rpmFileName) + installOutput, err := utils.Run("yum", "install", "-y", rpmFileName) + if err != nil { + log.Printf("error %s", err) + panic(err) + } log.Println(installOutput) log.Println("Stopping harvest") harvestObj.Stop() @@ -53,9 +57,13 @@ func (r *RPM) Upgrade() bool { utils.PanicIfNotNil(fmt.Errorf("pollers are not in a running state before upgrade")) } versionCmd := []string{"-qa", "harvest"} - out, _ := utils.Run("rpm", versionCmd...) + out, err := utils.Run("rpm", versionCmd...) + if err != nil { + log.Printf("error %s", err) + panic(err) + } previousVersion := strings.TrimSpace(out) - err := utils.DownloadFile(rpmFileName, r.path) + err = utils.DownloadFile(rpmFileName, r.path) utils.PanicIfNotNil(err) log.Println("Downloaded: " + r.path) log.Println("Updating " + rpmFileName) From f7049f60d2af8be7801c73b2717f7558e3158d53 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Sat, 15 Apr 2023 01:21:49 +0530 Subject: [PATCH 09/12] ci: address review comments --- integration/test/installer/install_utils.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integration/test/installer/install_utils.go b/integration/test/installer/install_utils.go index 51942cc31..d6431d592 100644 --- a/integration/test/installer/install_utils.go +++ b/integration/test/installer/install_utils.go @@ -24,8 +24,10 @@ func UninstallNativePkg() { log.Println("Uninstalling native pkg if any") if utils.FileExists(HarvestHome) { harvestObj := new(Harvest) - if harvestObj.AllRunning() { - harvestObj.Stop() + if utils.FileExists(HarvestHome + "bin/harvest") { + if harvestObj.AllRunning() { + harvestObj.Stop() + } } utils.Run("rm", "-rf", HarvestHome) } else { From f725f4565a88d8bb7ab55d1790ce21dc8c3926a2 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Sat, 15 Apr 2023 01:22:04 +0530 Subject: [PATCH 10/12] ci: address review comments --- integration/test/installer/install_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/installer/install_utils.go b/integration/test/installer/install_utils.go index d6431d592..f8d4be621 100644 --- a/integration/test/installer/install_utils.go +++ b/integration/test/installer/install_utils.go @@ -24,7 +24,7 @@ func UninstallNativePkg() { log.Println("Uninstalling native pkg if any") if utils.FileExists(HarvestHome) { harvestObj := new(Harvest) - if utils.FileExists(HarvestHome + "bin/harvest") { + if utils.FileExists(HarvestHome + "/bin/harvest") { if harvestObj.AllRunning() { harvestObj.Stop() } From 30905dd0b1778c28c1d537cfa325b8b4a4e2bd37 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Sat, 15 Apr 2023 01:41:12 +0530 Subject: [PATCH 11/12] ci: address review comments --- integration/test/utils/utils.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/integration/test/utils/utils.go b/integration/test/utils/utils.go index 66d0b9cbd..9aecc1b9c 100644 --- a/integration/test/utils/utils.go +++ b/integration/test/utils/utils.go @@ -2,7 +2,6 @@ package utils import ( "bytes" - "context" "encoding/json" "fmt" "github.com/netapp/harvest/v2/pkg/conf" @@ -45,15 +44,12 @@ func GetConfigDir() string { } func Exec(dir string, command string, env []string, arg ...string) (string, error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - cmdString := command + " " for _, param := range arg { cmdString = cmdString + param + " " } fmt.Println("CMD : " + cmdString) - cmd := exec.CommandContext(ctx, command, arg...) + cmd := exec.Command(command, arg...) cmd.Env = os.Environ() for _, v := range env { cmd.Env = append(cmd.Env, v) From a7e92f58a8f8c70e6d1c4fb58d681c0f41f7107e Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Sat, 15 Apr 2023 02:03:18 +0530 Subject: [PATCH 12/12] ci: address review comments --- integration/test/installer/rpm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index 608b7ce15..6ea8f43aa 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -79,5 +79,7 @@ func (r *RPM) Upgrade() bool { harvestObj.Stop() harvestObj.Start() status := harvestObj.AllRunning() - return status + asupExecPath := HarvestHome + "/autosupport/asup" + isValidAsup := harvestObj.IsValidAsup(asupExecPath) + return status && isValidAsup }