Skip to content

Commit

Permalink
e2e: fetch podman bundle behind proxy under podman preset
Browse files Browse the repository at this point in the history
  • Loading branch information
jsliacan authored and anjannath committed Mar 1, 2023
1 parent b0b2dfb commit 61473ff
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/e2e/features/proxy.feature
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
67 changes: 67 additions & 0 deletions test/e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 "([^"]*)"$`,
Expand Down Expand Up @@ -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" {
Expand Down
14 changes: 14 additions & 0 deletions test/extended/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)

}

0 comments on commit 61473ff

Please sign in to comment.