Skip to content

Commit

Permalink
Issue crc-org#673 Integration tests run with embedded bundle binary
Browse files Browse the repository at this point in the history
  • Loading branch information
jsliacan committed Oct 8, 2019
1 parent bece74c commit 91bc3de
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 25 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ clean: clean_docs
.PHONY: integration ## Run integration tests
integration: GODOG_OPTS = --godog.tags=$(GOOS)
integration:
@$(call check_defined, BUNDLE_LOCATION, "'make integration' requires BUNDLE_LOCATION to contain the full path to a bundle file")
@$(call check_defined, PULL_SECRET_FILE, "'make integration' requires PULL_SECRET_FILE to point to a file with the pull secret to use")
@go test --timeout=90m $(REPOPATH)/test/integration -v --tags=integration $(GODOG_OPTS) $(BUNDLE_LOCATION) $(PULL_SECRET_FILE)
@go test --timeout=90m $(REPOPATH)/test/integration -v --tags=integration $(GODOG_OPTS) $(PULL_SECRET_FILE) $(BUNDLE_VERSION) $(BUNDLE_LOCATION)

.PHONY: fmt
fmt:
Expand Down
2 changes: 1 addition & 1 deletion centos_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function run_tests() {
set +e
# In Jenkins slave we have pull secret file in the $HOME/payload/crc_pull_secret
# this is copied over using https://github.com/minishift/minishift-ci-jobs/blob/master/minishift-ci-index.yaml#L99
make integration BUNDLE_LOCATION=$HOME/Downloads/$BUNDLE PULL_SECRET_FILE=$HOME/payload/crc_pull_secret
make integration PULL_SECRET_FILE=$HOME/payload/crc_pull_secret BUNDLE_LOCATION=$HOME/Downloads/$BUNDLE
if [[ $? -ne 0 ]]; then
upload_logs $1
exit 1
Expand Down
5 changes: 2 additions & 3 deletions developing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ Clicumber allows running commands in a persistent shell instance (`bash`, `tcsh`
To start integration tests, run:

```bash
$ make integration BUNDLE_LOCATION=<bundle location> PULL_SECRET_FILE=<pull secret path>
$ make integration PULL_SECRET_FILE=<pull secret path> BUNDLE_LOCATION=<bundle location>
```
where `<bundle location>` is either the bundle's URL or its path in the filesystem,
and `<pull secret path>` is the path to a file containing your OpenShift pull secret.
where `<bundle location>` is the bundle's URL or its path in the filesystem if the bundle is not embedded. If bundle is embedded in the binary, `BUNDLE_LOCATION` is not passed to `make integration`. The `<pull secret path>` is the path to a file containing your OpenShift pull secret.
The paths must be absolute paths.

===== How to run only a subset of all integration tests
Expand Down
92 changes: 77 additions & 15 deletions test/integration/crcsuite/crcsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ import (
"time"

clicumber "github.com/code-ready/clicumber/testsuite"
"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/oc"
)

var (
CRCHome string
bundleEmbedded bool
bundleURL string
bundleName string
bundleVersion string
pullSecretFile string
)

Expand Down Expand Up @@ -91,21 +92,24 @@ func FeatureContext(s *godog.Suite) {

s.BeforeFeature(func(this *gherkin.Feature) {

if _, err := os.Stat(bundleName); os.IsNotExist(err) {
// Obtain the bundle to current dir
fmt.Println("Obtaining bundle...")
bundle, err := DownloadBundle(bundleURL, ".")
if err != nil {
fmt.Printf("Failed to obtain CRC bundle, %v\n", err)
if !bundleEmbedded {
if _, err := os.Stat(bundleName); os.IsNotExist(err) {
// Obtain the bundle to current dir
fmt.Println("Obtaining bundle...")
bundle, err := DownloadBundle(bundleURL, ".")
if err != nil {
fmt.Printf("Failed to obtain CRC bundle, %v\n", err)
os.Exit(1)
}
fmt.Println("Using bundle:", bundle)
} else if err != nil {
fmt.Printf("Unknown error obtaining the bundle %v.\n", bundleName)
os.Exit(1)
} else {
fmt.Println("Using existing bundle:", bundleName)
}
fmt.Println("Using bundle:", bundle)
} else if err != nil {
fmt.Printf("Unknown error obtaining the bundle %v.\n", bundleName)
os.Exit(1)
} else {
fmt.Println("Using existing bundle:", bundleName)
}
fmt.Println("Expecting bundle to be embedded in the CRC binary.")

})
}
Expand Down Expand Up @@ -188,6 +192,13 @@ func FileExistsInCRCHome(fileName string) error {

func ConfigFileInCRCHomeContainsKeyMatchingValue(format string, configFile string, condition string, keyPath string, expectedValue string) error {

if bundleName == "" {
err := SetBundleName()
if err != nil {
fmt.Println("Could not set bundleName: %s", err)
}
}

if expectedValue == "current bundle" {
expectedValue = bundleName
}
Expand Down Expand Up @@ -240,6 +251,13 @@ func ConfigFileInCRCHomeContainsKey(format string, configFile string, condition

func LoginToOcClusterSucceedsOrFails(expected string) error {

if bundleName == "" {
err := SetBundleName()
if err != nil {
fmt.Println("Could not set bundleName: %s", err)
}
}

bundle := strings.Split(bundleName, ".crcbundle")[0]
pswdLocation := filepath.Join(CRCHome, "cache", bundle, "kubeadmin-password")

Expand All @@ -260,7 +278,14 @@ func StartCRCWithDefaultBundleAndDefaultHypervisorSucceedsOrFails(expected strin
var cmd string
var extraBundleArgs string

if !constants.BundleEmbedded() {
if bundleName == "" {
err := SetBundleName()
if err != nil {
fmt.Println("Could not set bundleName: %s", err)
}
}

if !bundleEmbedded {
extraBundleArgs = fmt.Sprintf("-b %s", bundleName)
}
cmd = fmt.Sprintf("crc start -p '%s' %s --log-level debug", pullSecretFile, extraBundleArgs)
Expand All @@ -274,7 +299,14 @@ func StartCRCWithDefaultBundleAndHypervisorSucceedsOrFails(hypervisor string, ex
var cmd string
var extraBundleArgs string

if !constants.BundleEmbedded() {
if bundleName == "" {
err := SetBundleName()
if err != nil {
fmt.Println("Could not set bundleName: %s", err)
}
}

if !bundleEmbedded {
extraBundleArgs = fmt.Sprintf("-b %s", bundleName)
}
cmd = fmt.Sprintf("crc start -d %s -p '%s' %s --log-level debug", hypervisor, pullSecretFile, extraBundleArgs)
Expand All @@ -286,11 +318,41 @@ func StartCRCWithDefaultBundleAndHypervisorSucceedsOrFails(hypervisor string, ex
func SetConfigPropertyToValueSucceedsOrFails(property string, value string, expected string) error {

if value == "current bundle" {

value = bundleName

if bundleName == "" {
err := SetBundleName()
if err != nil {
fmt.Println("Could not set bundleName: %s", err)
}

value = filepath.Join(CRCHome, bundleName)
}
}

cmd := "crc config set " + property + " " + value
err := clicumber.ExecuteCommandSucceedsOrFails(cmd, expected)

return err
}

func SetBundleName() error {

files, err := ioutil.ReadDir(CRCHome)
if err != nil {
fmt.Println("Cannot list files in %s: %s.\n", CRCHome, err)
return err
}

for _, f := range files {
// not great!
// If there are multiple bundles in ~/.crc, the first one is taken
if strings.Contains(f.Name(), ".crcbundle") {
bundleName = f.Name()
break
}
}
return nil

}
38 changes: 34 additions & 4 deletions test/integration/crcsuite/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/user"
"path/filepath"
"runtime"

"github.com/code-ready/crc/pkg/download"
)
Expand Down Expand Up @@ -62,12 +63,41 @@ func ParseFlags() {

flag.Parse()
if flag.NArg() < 2 {
fmt.Printf("Invalid number of arguments, the paths to the bundle file and to the pull secret file are required\n")
fmt.Printf("Invalid number of arguments, the path to the pull secret file and the bundle version are required\n")
os.Exit(1)
}
bundleURL = flag.Args()[0]
_, bundleName = filepath.Split(bundleURL)
pullSecretFile = flag.Args()[1]

pullSecretFile = flag.Args()[0]

// embedded bundle
if flag.NArg() == 2 {
bundleEmbedded = true
bundleVersion = flag.Args()[1]
// assume default hypervisor
var hypervisor string
switch os := runtime.GOOS; os {
case "darwin":
hypervisor = "hyperkit"
case "linux":
hypervisor = "libvirt"
case "windows":
hypervisor = "hyperv"
default:
fmt.Printf("Unsupported OS: %s", os)
}

bundleName = fmt.Sprintf("crc_%s_%s.crcbundle", hypervisor, bundleVersion)
fmt.Printf("Bundle name: %s\n", bundleName)

}

// separate bundle
if flag.NArg() == 3 {
bundleEmbedded = false
bundleURL = flag.Args()[1]
_, bundleName = filepath.Split(bundleURL)
}

}

// Set CRCHome var to ~/.crc
Expand Down

0 comments on commit 91bc3de

Please sign in to comment.