From dc2f2fad476464f73523e154155f4ad9713f4296 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Mon, 21 Aug 2023 12:26:58 +0530 Subject: [PATCH] CI: Make sure oc command is available before any oc operations As part of https://github.com/crc-org/crc/pull/3782 debugging steps are added to figure out why the `oc login` require insecure sometimes but this logic fails in case the `oc` binary is not part of system path. This PR make sure that the oc command available before those debugging steps. fixes: #3792 --- test/e2e/features/story_microshift.feature | 1 + test/e2e/features/story_openshift.feature | 1 + test/e2e/testsuite/testsuite.go | 22 +++++++++++++--------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/e2e/features/story_microshift.feature b/test/e2e/features/story_microshift.feature index bfc937e500..1270706122 100644 --- a/test/e2e/features/story_microshift.feature +++ b/test/e2e/features/story_microshift.feature @@ -6,6 +6,7 @@ Feature: Microshift test stories And setting config property "network-mode" to value "user" succeeds And executing single crc setup command succeeds And starting CRC with default bundle succeeds + And ensuring oc command is available # End-to-end health check diff --git a/test/e2e/features/story_openshift.feature b/test/e2e/features/story_openshift.feature index 36bfcc9be6..d28d8b12c6 100644 --- a/test/e2e/features/story_openshift.feature +++ b/test/e2e/features/story_openshift.feature @@ -3,6 +3,7 @@ Feature: 4 Openshift stories Background: Given ensuring CRC cluster is running + And ensuring oc command is available And executing "oc config view --raw -o jsonpath="{.clusters[?(@.name=='api-crc-testing:6443')].cluster.certificate-authority-data}"| base64 -d - > ca.crt" succeeds And executing "echo | openssl s_client -connect api.crc.testing:6443 | openssl x509 -out server.crt" succeeds And executing "openssl verify -CAfile ca.crt server.crt" succeeds diff --git a/test/e2e/testsuite/testsuite.go b/test/e2e/testsuite/testsuite.go index 22287101de..9cd314c454 100644 --- a/test/e2e/testsuite/testsuite.go +++ b/test/e2e/testsuite/testsuite.go @@ -492,6 +492,8 @@ func InitializeScenario(s *godog.ScenarioContext) { ExecutingPodmanCommandSucceedsFails) s.Step(`^ensuring CRC cluster is running$`, EnsureCRCIsRunning) + s.Step(`^ensuring oc command is available$`, + EnsureOCCommandIsAvailable) s.Step(`^ensuring user is logged in (succeeds|fails)`, EnsureUserIsLoggedIntoClusterSucceedsOrFails) s.Step(`^podman command is available$`, @@ -845,19 +847,21 @@ func EnsureCRCIsRunning() error { } func EnsureUserIsLoggedIntoClusterSucceedsOrFails(expected string) error { + if err := setOcEnv(); err != nil { + return err + } + return LoginToOcClusterSucceedsOrFails(expected) +} - var err error +func EnsureOCCommandIsAvailable() error { + return setOcEnv() +} +func setOcEnv() error { if runtime.GOOS == "windows" { - err = util.ExecuteCommandSucceedsOrFails("crc oc-env | Invoke-Expression", expected) - } else { - err = util.ExecuteCommandSucceedsOrFails("eval $(crc oc-env)", expected) - } - if err != nil { - return err + return util.ExecuteCommandSucceedsOrFails("crc oc-env | Invoke-Expression", "succeeds") } - - return LoginToOcClusterSucceedsOrFails(expected) + return util.ExecuteCommandSucceedsOrFails("eval $(crc oc-env)", "succeeds") } func SetConfigPropertyToValueSucceedsOrFails(property string, value string, expected string) error {