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 Nov 4, 2019
1 parent 4347c0e commit 5a5bd5f
Show file tree
Hide file tree
Showing 5 changed files with 60 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_LOCATION) $(BUNDLE_VERSION)

.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 @@ -130,7 +130,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
35 changes: 20 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 @@ -95,21 +96,25 @@ 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...")
fmt.Printf("bundleURL = %s\n", bundleURL)
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 @@ -287,7 +292,7 @@ func StartCRCWithDefaultBundleAndDefaultHypervisorSucceedsOrFails(expected strin
var cmd string
var extraBundleArgs string

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

if !constants.BundleEmbedded() {
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 Down
40 changes: 36 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,43 @@ 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
// this will never occur on Centos CI
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)

}

// separate bundle
// 3: on laptop
// 4: on Centos CI
if flag.NArg() > 2 {
bundleEmbedded = false
bundleURL = flag.Args()[1]
_, bundleName = filepath.Split(bundleURL)
}

}

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

0 comments on commit 5a5bd5f

Please sign in to comment.