From 61473ff564bcc8c60b6b7ee4c37ee2982629f00f Mon Sep 17 00:00:00 2001 From: Jakub Sliacan Date: Wed, 16 Nov 2022 10:25:47 +0100 Subject: [PATCH] e2e: fetch podman bundle behind proxy under podman preset --- test/e2e/features/proxy.feature | 24 ++++++++++-- test/e2e/testsuite/testsuite.go | 67 +++++++++++++++++++++++++++++++++ test/extended/util/util.go | 14 +++++++ 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/test/e2e/features/proxy.feature b/test/e2e/features/proxy.feature index 2ac2368728..d129557065 100644 --- a/test/e2e/features/proxy.feature +++ b/test/e2e/features/proxy.feature @@ -1,14 +1,13 @@ @proxy @linux Feature: Behind proxy test - User starts CRC behind a proxy. They expect a successful start - and to be able to deploy an app and check its accessibility. + Check CRC use behind proxy Background: Setup the proxy container using podman * executing "podman run --name squid -d -p 3128:3128 quay.io/crcont/squid" succeeds @cleanup - Scenario: Start CRC behind proxy + Scenario: Start CRC behind proxy under openshift preset Given executing single crc setup command succeeds And executing "crc config set http-proxy http://192.168.130.1:3128" succeeds Then executing "crc config set https-proxy http://192.168.130.1:3128" succeeds @@ -29,3 +28,22 @@ Feature: Behind proxy test And executing crc cleanup command succeeds + Scenario: Cache podman bundle behind proxy under podman preset + * executing "crc config set http-proxy http://192.168.130.1:3128" succeeds + * executing "crc config set https-proxy http://192.168.130.1:3128" succeeds + * removing podman bundle from cache succeeds +<<<<<<< HEAD + Given executing "crc config set preset podman" succeeds + Then executing single crc setup command succeeds + And podman bundle is cached + # cleanup proxy and preset settings from config + * executing "crc config unset http-proxy" succeeds + * executing "crc config unset https-proxy" succeeds + * executing "crc config unset preset" succeeds + * executing "podman stop squid" succeeds + * executing "podman rm squid" succeeds +======= + * executing "crc config set preset podman" succeeds + When executing single crc setup command succeeds + Then executing "crc start" succeeds +>>>>>>> 5c6d0b94 (Trying a pure start for podman preset) diff --git a/test/e2e/testsuite/testsuite.go b/test/e2e/testsuite/testsuite.go index 89af95ba65..bcbd42110d 100644 --- a/test/e2e/testsuite/testsuite.go +++ b/test/e2e/testsuite/testsuite.go @@ -180,6 +180,12 @@ func InitializeScenario(s *godog.ScenarioContext) { } for _, tag := range sc.Tags { + + // if podman preset is activated, bundle will not be provided by the user + if tag.Name == "@podman-preset" { + userProvidedBundle = false + } + // copy data/config files to test dir if tag.Name == "@testdata" { err := util.CopyFilesToTestDir() @@ -332,6 +338,10 @@ func InitializeScenario(s *godog.ScenarioContext) { util.DownloadFileIntoLocation) s.Step(`^writing text "([^"]*)" to file "([^"]*)" succeeds$`, util.WriteToFile) + s.Step(`^removing (podman|openshift) bundle from cache succeeds$`, + RemoveBundleFromCache) + s.Step(`^(podman|openshift) bundle (is|is not) cached$`, + BundleIsCachedOrNot) // File content checks s.Step(`^content of file "([^"]*)" should contain "([^"]*)"$`, @@ -539,6 +549,63 @@ func FileExistsInCRCHome(fileName string) error { return err } +func BundleIsCachedOrNot(presetName string, isOrNot string) error { + + bundle := "" + if presetName == "podman" { + bundle = constants.GetDefaultBundle(preset.Podman) + } else { + bundle = constants.GetDefaultBundle(preset.OpenShift) + } + + theFile := filepath.Join(CRCHome, "cache", bundle) + + _, err := os.Stat(theFile) + + if os.IsNotExist(err) && isOrNot == "is" { + return fmt.Errorf("file %s does not exists, error: %v ", theFile, err) + } + + if err == nil && isOrNot == "is not" { + return fmt.Errorf("file %s exists when it should not exist", theFile) + } + + return nil +} + +func RemoveBundleFromCache(presetName string) error { + +<<<<<<< HEAD + var theFolder, theBundle string // locations to be removed +======= +>>>>>>> f339a7c5 (Refactoring podman proxy feature addition) + var p preset.Preset + + if presetName == "podman" { + p = preset.Podman + } else { + p = preset.OpenShift + } + + theBundle := util.GetBundlePath(p) + theFolder := strings.TrimSuffix(theBundle, ".crcbundle") + + // remove the unpacked folder (if present) + err := os.RemoveAll(theFolder) + if err != nil { + return err + } + + // remove the bundle file (if present) + err = os.RemoveAll(theBundle) + + if err != nil { + return err + } + + return nil +} + func ConfigFileInCRCHomeContainsKeyMatchingValue(format string, configFile string, condition string, keyPath string, expectedValue string) error { if expectedValue == "current bundle" { diff --git a/test/extended/util/util.go b/test/extended/util/util.go index de4efb2d0c..6cf218ab47 100644 --- a/test/extended/util/util.go +++ b/test/extended/util/util.go @@ -4,11 +4,14 @@ import ( "fmt" "io" "os" + "os/user" "path/filepath" "runtime" "strings" "time" + "github.com/crc-org/crc/pkg/crc/constants" + "github.com/crc-org/crc/pkg/crc/preset" "github.com/crc-org/crc/pkg/download" ) @@ -174,3 +177,14 @@ func MatchRepetitionsWithRetry(expression string, match func(string) error, matc } } } + +// GetBundlePath returns a path to the cached bundle, depending on the preset +func GetBundlePath(preset preset.Preset) string { + + usr, _ := user.Current() + crcHome := filepath.Join(usr.HomeDir, ".crc") + + bundle := constants.GetDefaultBundle(preset) + return filepath.Join(crcHome, "cache", bundle) + +}