From da7e5a9cf068bbe1d648f5e8af950d19af4a5d2f Mon Sep 17 00:00:00 2001 From: Adrian Riobo Lorenzo Date: Tue, 3 Oct 2023 21:23:54 +0200 Subject: [PATCH] [e2e] story_microshift ensures operational status for cluster before deploy the sample service previously the test service was deployed right after the crc start finished successfully, now we add some checks before deploy the service to ensure the cluster is operational: crc status + dns pods running + ovn pods running --- test/e2e/features/story_microshift.feature | 7 ++-- test/e2e/testsuite/testsuite.go | 40 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/test/e2e/features/story_microshift.feature b/test/e2e/features/story_microshift.feature index 1270706122..54a6b45aaa 100644 --- a/test/e2e/features/story_microshift.feature +++ b/test/e2e/features/story_microshift.feature @@ -3,14 +3,15 @@ Feature: Microshift test stories Background: Given setting config property "preset" to value "microshift" succeeds - And setting config property "network-mode" to value "user" succeeds + And ensuring network mode user And executing single crc setup command succeeds And starting CRC with default bundle succeeds And ensuring oc command is available - + And ensuring microshift cluster is fully operational + # End-to-end health check - @microshift @testdata @linux @windows @darwin + @microshift @testdata @linux @windows @darwin @cleanup Scenario: Start and expose a basic HTTP service and check after restart Given executing "oc create namespace testproj" succeeds And executing "oc config set-context --current --namespace=testproj" succeeds diff --git a/test/e2e/testsuite/testsuite.go b/test/e2e/testsuite/testsuite.go index c27e70052a..a155ed0812 100644 --- a/test/e2e/testsuite/testsuite.go +++ b/test/e2e/testsuite/testsuite.go @@ -514,6 +514,10 @@ func InitializeScenario(s *godog.ScenarioContext) { DeleteFileFromCRCHome) s.Step(`^decode base64 file "(.*)" to "(.*)"$`, DecodeBase64File) + s.Step(`^ensuring network mode user$`, + EnsureUserNetworkmode) + s.Step(`^ensuring microshift cluster is fully operational$`, + EnsureMicroshiftClusterIsOperational) s.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) { @@ -978,3 +982,39 @@ func DecodeBase64File(inputFile, outputFile string) error { } return util.ExecuteCommandSucceedsOrFails(cmd, "succeeds") } + +func EnsureUserNetworkmode() error { + if runtime.GOOS == "linux" { + return crcCmd.SetConfigPropertyToValueSucceedsOrFails( + "network-mode", "user", "succeeds") + } + return nil +} + +// This function will wait until the microshift cluster got operational +func EnsureMicroshiftClusterIsOperational() error { + // First wait until crc report the cluster as running + err := crcCmd.WaitForClusterInState("running") + if err != nil { + return err + } + // Define the services to declare the cluster operational + services := map[string]string{ + ".*dns-default.*2/2.*Running.*": "oc get pods -n openshift-dns", + ".*ovnkube-master.*4/4.*Running.*": "oc get pods -n openshift-ovn-kubernetes", + ".*ovnkube-node.*1/1.*Running.*": "oc get pods -n openshift-ovn-kubernetes"} + + for operationalState, getPodCommand := range services { + var operational = false + for !operational { + if err := util.ExecuteCommandSucceedsOrFails(getPodCommand, "succeeds"); err != nil { + return err + } + operational = (nil == util.CommandReturnShouldMatch( + "stdout", + operationalState)) + } + } + + return nil +}