diff --git a/integration/Jenkinsfile b/integration/Jenkinsfile index 0d83fb084..d9814085f 100644 --- a/integration/Jenkinsfile +++ b/integration/Jenkinsfile @@ -284,7 +284,7 @@ def void stopAndRemoveDockers() { sh ''' for container_id in $(docker ps -a -q);do docker stop $container_id;done for container_id in $(docker ps -a -q);do docker rm $container_id;done - docker system prune --all --force --volumes + docker system prune --force --volumes volumes=$(docker volume ls -qf dangling=true) if [ "$volumes" ]; then docker volume rm $volumes diff --git a/integration/test/installer/grafana.go b/integration/test/installer/grafana.go index 0eb3cc709..d5ecac7f2 100644 --- a/integration/test/installer/grafana.go +++ b/integration/test/installer/grafana.go @@ -22,21 +22,26 @@ func (g *Grafana) Install() bool { g.image = "grafana/grafana:8.1.8" slog.Info("Grafana image : " + g.image) imageName := "grafana" - _ = docker.StopContainers(imageName) - cmd := exec.Command("docker", "run", "-d", "-e", "GF_LOG_LEVEL=debug", "-p", utils.GrafanaPort+":"+utils.GrafanaPort, g.image) //nolint:gosec + err := docker.StopContainers(imageName) + if err != nil { + slog.Warn("Error while stopping Grafana container", slog.Any("err", err)) + } + cmd := exec.Command("docker", "run", "-d", "--name", "grafana", "-e", "GF_LOG_LEVEL=debug", "-p", utils.GrafanaPort+":"+utils.GrafanaPort, g.image) //nolint:gosec cmd.Stdout = os.Stdout - err := cmd.Start() + cmd.Stderr = os.Stderr + err = cmd.Start() utils.PanicIfNotNil(err) waitCount := 0 - maxWaitCount := 15 + maxWaitCount := 3 for waitCount < maxWaitCount { waitCount++ time.Sleep(1 * time.Minute) if utils.IsURLReachable("http://localhost:" + utils.GrafanaPort) { return true } + slog.Info("Grafana is not yet reachable.", slog.Int("waitCount", waitCount), slog.Int("maxWaitCount", maxWaitCount)) } - slog.Info("Reached maximum timeout. Grafana is failed to start", slog.Int("maxWaitCount", maxWaitCount)) + slog.Info("Reached maximum wait count. Grafana failed to start") return false } diff --git a/integration/test/installer/harvest.go b/integration/test/installer/harvest.go index dd8836656..c07b8a1f0 100644 --- a/integration/test/installer/harvest.go +++ b/integration/test/installer/harvest.go @@ -36,10 +36,16 @@ func (h *Harvest) Stop() { fmt.Println(status) } -func (h *Harvest) AllRunning() bool { +func (h *Harvest) AllRunning(ignoring ...string) bool { pollerArray := h.GetPollerInfo() +outer: for _, poller := range pollerArray { if poller.Status != "running" { + for _, ignore := range ignoring { + if strings.Contains(poller.Poller, ignore) { + continue outer + } + } return false } } diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index 018f79f07..033ffb379 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -41,7 +41,7 @@ func (r *RPM) Install() bool { return false } // use file directly from the repo harvestObj.Start() - status := harvestObj.AllRunning() + status := harvestObj.AllRunning("keyperf") asupExecPath := HarvestHome + "/autosupport/asup" isValidAsup := harvestObj.IsValidAsup(asupExecPath) return status && isValidAsup @@ -51,7 +51,7 @@ func (r *RPM) Upgrade() bool { rpmFileName := "harvest.rpm" utils.RemoveSafely(rpmFileName) harvestObj := new(Harvest) - if !harvestObj.AllRunning() { + if !harvestObj.AllRunning("keyperf") { utils.PanicIfNotNil(errors.New("pollers are not in a running state before upgrade")) } versionCmd := []string{"-qa", "harvest"} diff --git a/integration/test/rpm_installer_test.go b/integration/test/rpm_installer_test.go index 4fa133a84..19e2076cc 100644 --- a/integration/test/rpm_installer_test.go +++ b/integration/test/rpm_installer_test.go @@ -3,7 +3,7 @@ package main import ( "github.com/Netapp/harvest-automation/test/installer" "github.com/Netapp/harvest-automation/test/utils" - "log" + "log/slog" "os" "testing" ) @@ -16,7 +16,7 @@ func TestRHELInstall(t *testing.T) { } installObject, err := installer.GetInstaller(installer.GRAFANA, "grafana/grafana") if err != nil { - log.Println("Unable to initialize installer object for " + installer.GRAFANA) + slog.Error("Unable to initialize installer object", slog.String("object", installer.GRAFANA)) panic(err) } if !installObject.Install() { @@ -27,24 +27,24 @@ func TestRHELInstall(t *testing.T) { installObject, err2 := installer.GetInstaller(installer.RHEL, path) if err2 != nil { - log.Println("Unable to initialize installer object") + slog.Error("Unable to initialize installer object", slog.String("object", installer.RHEL)) panic(err2) } if installObject.Install() { - log.Println("Installation is successful..") + slog.Info("Installation is successful..") } else { - log.Println("Setup completed") - panic("installation is failed.") + slog.Error("Installation failed") + panic("installation failed.") } harvestObj := new(installer.Harvest) - if harvestObj.AllRunning() { - log.Println("All pollers are running") + if harvestObj.AllRunning("keyperf") { + slog.Info("All pollers but keyperf are running") } else { t.Errorf("One or more pollers are not running.") } installObject, err = installer.GetInstaller(installer.PROMETHEUS, "prom/prometheus") if err != nil { - log.Println("Unable to initialize installer object for " + installer.PROMETHEUS) + slog.Error("Unable to initialize installer object", slog.String("object", installer.PROMETHEUS)) panic(err) } if !installObject.Install() { @@ -58,11 +58,11 @@ func TestRHELStop(t *testing.T) { var path = os.Getenv("BUILD_PATH") installObject, err2 := installer.GetInstaller(installer.RHEL, path) if err2 != nil { - log.Println("Unable to initialize installer object") + slog.Info("Unable to initialize installer object") panic(err2) } if installObject.Stop() { - log.Println("Stop is successful..") + slog.Info("Stop is successful..") } else { panic("Stop is failed.") } diff --git a/integration/test/utils/utils.go b/integration/test/utils/utils.go index f2b2894b9..146cef172 100644 --- a/integration/test/utils/utils.go +++ b/integration/test/utils/utils.go @@ -2,9 +2,11 @@ package utils import ( "bytes" + "context" "encoding/json" "errors" "fmt" + "github.com/carlmjohnson/requests" "github.com/netapp/harvest/v2/cmd/tools/grafana" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/slogx" @@ -179,12 +181,8 @@ func WaitForGrafana() bool { } func IsURLReachable(url string) bool { - response, err := http.Get(url) //nolint:gosec - if err != nil { - return false - } - defer response.Body.Close() - return response.StatusCode == http.StatusOK + err := requests.URL(url).Fetch(context.Background()) + return err == nil } func AddPrometheusToGrafana() { diff --git a/jenkins/artifacts/jenkinsfile b/jenkins/artifacts/jenkinsfile index f906566bc..325cdb258 100644 --- a/jenkins/artifacts/jenkinsfile +++ b/jenkins/artifacts/jenkinsfile @@ -384,7 +384,7 @@ def void stopAndRemoveDockers() { rm -rf /opt/home/nightly/ mkdir -p /opt/home/nightly/ for container_id in $(docker ps -a -q);do docker stop $container_id;done - docker system prune --all --force --volumes + docker system prune --force --volumes volumes=$(docker volume ls -qf dangling=true) if [ "$volumes" ]; then docker volume rm $volumes