Skip to content

Commit

Permalink
CI: Make sure oc command is available before any oc operations
Browse files Browse the repository at this point in the history
As part of crc-org#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: crc-org#3792
  • Loading branch information
praveenkumar committed Aug 22, 2023
1 parent 97705a0 commit dc2f2fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions test/e2e/features/story_microshift.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/e2e/features/story_openshift.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions test/e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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$`,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dc2f2fa

Please sign in to comment.