From d8113a739e86bff34875c425cf6e7b1e14852a71 Mon Sep 17 00:00:00 2001 From: Maayan Hadasi Date: Thu, 21 Sep 2023 14:20:05 +0300 Subject: [PATCH 1/2] Modifying metrics so tests can be executed against OpenShift cluster Signed-off-by: Maayan Hadasi --- config/config.json | 1 + config/configuration.go | 1 + e2e/metrics/metrics_utils.go | 41 ++++++++++++++++++++++++------------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/config/config.json b/config/config.json index eb857da..99cb40c 100644 --- a/config/config.json +++ b/config/config.json @@ -1,4 +1,5 @@ { + "KUBECONFIG": "", "RETRY_NUM": "10", "KEEP": "0" } diff --git a/config/configuration.go b/config/configuration.go index 9960081..8c5db56 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -1,6 +1,7 @@ package config type Configuration struct { + KUBECONFIG string `env:"KUBECONFIG"` JIRA_USERNAME string `env:"JIRA_USERNAME"` JIRA_PASSWORD string `env:"JIRA_PASSWORD"` JIRA_URL string `env:"JIRA_URL"` diff --git a/e2e/metrics/metrics_utils.go b/e2e/metrics/metrics_utils.go index 85ed703..ea288cd 100644 --- a/e2e/metrics/metrics_utils.go +++ b/e2e/metrics/metrics_utils.go @@ -1,6 +1,7 @@ package metrics import ( + "bytes" "fmt" "os" "os/exec" @@ -8,6 +9,9 @@ import ( "strings" "time" + . "github.com/konveyor/go-konveyor-tests/config" + . "github.com/onsi/gomega" + "github.com/konveyor/go-konveyor-tests/utils" ) @@ -16,10 +20,6 @@ var ( hub_pod_name string ) -func init() { - hub_pod_name = getHubFullName() -} - func getHubFullName() string { operator_namespace = "konveyor-tackle" pod := "tackle-hub" @@ -30,25 +30,40 @@ func getHubFullName() string { pod = "mta-hub" } cmd := fmt.Sprintf("oc get pod -n %s | grep %s | awk '{print $1}'", operator_namespace, pod) - return runCmd(cmd) + return runOpenshiftCmd(cmd) } func GetMetricValue(metricName string) int { + hub_pod_name = getHubFullName() utils.Log.Info("Waiting for 30 seconds...") time.Sleep(30 * time.Second) cmd := fmt.Sprintf("oc exec -n %s %s -- curl -s http://localhost:2112/metrics | grep %s", operator_namespace, hub_pod_name, metricName) - var outStr []string = strings.Split(runCmd(cmd), "\n") + var outStr []string = strings.Split(runOpenshiftCmd(cmd), "\n") metricValue := outStr[len(outStr)-1] metricValue = utils.LastString(strings.Split(metricValue, " ")) outInt, _ := strconv.Atoi(metricValue) return outInt } -func runCmd(cmd string) string { - out, err := exec.Command("bash", "-c", cmd).Output() - if err != nil { - return fmt.Sprintf("Failed to execute command: %s", cmd) - } - out = out[:len(out)-1] - return string(out) +// runOpenshiftCmd runs an OpenShift command and returns its output as a string. +func runOpenshiftCmd(cmd string) string { + os.Setenv("KUBECONFIG", Config.KUBECONFIG) + + // Create a new command to execute in a Bash environment. + command := exec.Command("bash", "-c", cmd) + + // Create a buffer to capture the standard output of the executed command. + var out bytes.Buffer + command.Stdout = &out + + // Execute the command and check for any errors. + err := command.Run() + Expect(err).ShouldNot(HaveOccurred()) + + // Assert that the captured output is not empty. + Expect(out.Len()).ShouldNot(BeZero()) + + // Removing the trailing newline character ("\n") + outStr := out.String() + return outStr[:len(outStr)-1] } From 6e5e17e5d1752f86fb983eaacc339fb5c8f05a3b Mon Sep 17 00:00:00 2001 From: Maayan Hadasi Date: Thu, 21 Sep 2023 14:34:32 +0300 Subject: [PATCH 2/2] Update README.md Signed-off-by: Maayan Hadasi --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b04e9f8..dac0d39 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,16 @@ git clone https://github.com/aufi/go-konveyor-tests && cd go-konveyor-tests $ make setup # start minikube&tackle using David's scripts - local env only ``` +### OpenShift cluster + +These tests can be executed against OpenShift cluster with Konveyor installed by setting `KUBECONFIG` variable: + +``` +KUBECONFIG= +``` + +> **_NOTE:_** You might be required to download and import the certificate chain. Please see [Hub API test README](https://github.com/konveyor/tackle2-hub/tree/main/test#https) for more information. + ### Run test suite Set ```$HUB_BASE_URL``` environment variable to point to Konveyor installation before running tests. More options could be found in [Hub API test README](https://github.com/konveyor/tackle2-hub/tree/main/test#rest-api).