Skip to content

Commit

Permalink
e2e: execute crc setup as an isolated command
Browse files Browse the repository at this point in the history
        During e2e executions from time to time crc setup got freeze giving false positives. This is due to a wrong behavior on clicumber shell utility within the downloader progress bar to avoid this conflict crc setup will be executed as a single command with os.exec also we remove checks for setup outputs
  • Loading branch information
adrianriobo authored and anjannath committed Sep 12, 2022
1 parent 4873ad6 commit dda5320
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
9 changes: 9 additions & 0 deletions test/e2e/crcsuite/crcsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func FeatureContext(s *godog.Suite) {
ExecuteCommand)
s.Step(`^execut(?:e|ing) crc (.*) command (.*)$`,
ExecuteCommandWithExpectedExitStatus)
s.Step(`^execut(?:e|ing) single crc (.*) command (.*)$`,
ExecuteSingleCommandWithExpectedExitStatus)

// CRC file operations
s.Step(`^file "([^"]*)" exists in CRC home folder$`,
Expand Down Expand Up @@ -429,3 +431,10 @@ func ExecuteCommandWithExpectedExitStatus(command string, expectedExitStatus str
}
return crcCmd.CRC(command).ExecuteWithExpectedExit(expectedExitStatus)
}

func ExecuteSingleCommandWithExpectedExitStatus(command string, expectedExitStatus string) error {
if command == "setup" && userProvidedBundle {
command = fmt.Sprintf("%s -b %s", command, bundleLocation)
}
return crcCmd.CRC(command).ExecuteSingleWithExpectedExit(expectedExitStatus)
}
31 changes: 4 additions & 27 deletions test/e2e/features/basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,7 @@ Feature: Basic test
Scenario: CRC setup on Linux
When executing "crc setup --check-only" fails
Then executing crc start command fails
And executing crc setup command succeeds
And stderr should contain "Checking if CRC bundle is extracted in '$HOME/.crc'"
And stderr should contain "Checking if running as non-root"
And stderr should contain "Checking if Virtualization is enabled"
And stderr should contain "Checking if KVM is enabled"
And stderr should contain "Checking if libvirt is installed"
And stderr should contain "Checking if user is part of libvirt group"
And stderr should contain "Checking if libvirt daemon is running"
And stderr should contain "Checking if a supported libvirt version is installed"
And stderr should contain "Checking if libvirt 'crc' network is available"
And stderr should contain "Checking if libvirt 'crc' network is active"
And stderr should contain "Checking if NetworkManager is installed"
And stderr should contain "Checking if NetworkManager service is running"
And stderr should contain "Using root access: Executing systemctl daemon-reload command"
And stderr should contain "Using root access: Executing systemctl reload NetworkManager"
And stdout should contain "Your system is correctly setup for using CRC. Use 'crc start' to start the instance"
And executing single crc setup command succeeds

@linux
Scenario: Missing CRC setup
Expand All @@ -67,19 +52,11 @@ Feature: Basic test
@darwin
Scenario: CRC setup on Mac
When executing "crc setup --check-only" fails
And executing crc setup command succeeds
And stderr should contain "Checking if running as non-root"
And stderr should contain "Checking if vfkit is installed"
And stderr should contain "Using root access: Changing ownership"

And executing single crc setup command succeeds

@windows
Scenario: CRC setup on Windows
When executing crc setup command succeeds
Then stderr should contain "Extracting bundle from the CRC executable" if bundle is embedded
Then stderr should contain "Checking Windows release"
Then stderr should contain "Checking if Hyper-V is installed"
Then stderr should contain "Checking if user is a member of the Hyper-V Administrators group"
Then stderr should contain "Checking if the Hyper-V virtual switch exist"
When executing single crc setup command succeeds

@darwin @linux @windows
Scenario: Request start with monitoring stack
Expand Down
20 changes: 20 additions & 0 deletions test/extended/crc/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cmd

import (
"fmt"
"os/exec"
"runtime"
"strings"

clicumber "github.com/code-ready/clicumber/testsuite"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/test/extended/util"
)

Expand Down Expand Up @@ -168,3 +170,21 @@ func DeleteCRC() error {
fmt.Printf("Deleted CRC instance (if one existed).\n")
return nil
}

func (c Command) ExecuteSingleWithExpectedExit(expectedExit string) error {
if err := c.validate(); err != nil {
return err
}
if expectedExit == "succeeds" || expectedExit == "fails" {
// Disable G204 lint check as it will force us to use fixed args for the command
cmd := exec.Command("crc", strings.Split(c.command, " ")...) // #nosec G204
err := cmd.Run()
logging.Debugf("Running single command crc %s", c.command)
if err != nil && expectedExit == "fails" ||
err == nil && expectedExit == "succeeds" {
return nil
}
return fmt.Errorf("%s expected %s but it did not", c.ToString(), expectedExit)
}
return fmt.Errorf("%s is a valid expected exit status", expectedExit)
}

0 comments on commit dda5320

Please sign in to comment.