Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #425 from stealthybox/improve_e2e
Browse files Browse the repository at this point in the history
Store e2e command output /w errors + remove variable sleep
  • Loading branch information
chanwit committed Sep 14, 2019
2 parents 2bde2cb + 6803d8f commit e8a2996
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 51 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ BASEIMAGE=arm64v8/alpine:3.9
ARCH_SUFFIX=-aarch64
endif

E2E_REGEX := Test
E2E_COUNT := 1

all: ignite
install: ignite
sudo cp bin/$(GOARCH)/ignite /usr/local/bin
Expand Down Expand Up @@ -253,5 +256,11 @@ serve-docs: build-docs
@echo Stating docs website on http://localhost:${DOCS_PORT}/_build/html/index.html
@$(DOCKER) run -i --rm -p ${DOCS_PORT}:8000 -e USER_ID=$$UID ignite-docs

e2e: build-all
sudo IGNITE_E2E_HOME=$(shell pwd) $(shell which go) test ./e2e/. -count 1
e2e: build-all e2e-nobuild

e2e-nobuild:
sudo IGNITE_E2E_HOME=$(shell pwd) \
$(shell which go) test \
./e2e/. -v \
-count $(E2E_COUNT) \
-run $(E2E_REGEX)
67 changes: 18 additions & 49 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// we have to wait until the CI setup to allow Ignite to run with sudo and in a KVM environment.
//
// How to run tests:
// sudo IGNITE_E2E_HOME=$PWD $(which go) test ./e2e/. -count 1
// sudo IGNITE_E2E_HOME=$PWD $(which go) test ./e2e/. -v -count 1 -run Test
//

package e2e
Expand All @@ -25,40 +25,32 @@ var (
igniteBin = path.Join(e2eHome, "bin/ignite")
)

// stdCmd builds an *exec.Cmd hooked up to Stdout/Stderr by default
func stdCmd(name string, arg ...string) *exec.Cmd {
cmd := exec.Command(name, arg...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}

// runWithRuntimeAndNetworkPlugin is a helper for running a vm then forcing removal
// vmName should be unique for each test
func runWithRuntimeAndNetworkPlugin(t *testing.T, vmName, runtime, networkPlugin string) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")

runCmd := stdCmd(
runCmd := exec.Command(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"run", "--name="+vmName,
"weaveworks/ignite-ubuntu",
)
runErr := runCmd.Run()
runOut, runErr := runCmd.CombinedOutput()

defer func() {
rmvCmd := stdCmd(
rmvCmd := exec.Command(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"rm", "-f", vmName,
)
rmvErr := rmvCmd.Run()
assert.Check(t, rmvErr, fmt.Sprintf("vm removal should not fail: %q", rmvCmd.Args))
rmvOut, rmvErr := rmvCmd.CombinedOutput()
assert.Check(t, rmvErr, fmt.Sprintf("vm removal: \n%q\n%s", rmvCmd.Args, rmvOut))
}()

assert.Check(t, runErr, fmt.Sprintf("%q should not fail to run", runCmd.Args))
assert.Check(t, runErr, fmt.Sprintf("vm run: \n%q\n%s", runCmd.Args, runOut))
}

func TestIgniteRunWithDockerAndDockerBridge(t *testing.T) {
Expand Down Expand Up @@ -90,45 +82,45 @@ func TestIgniteRunWithContainerdAndCNI(t *testing.T) {

// runCurl is a helper for testing network connectivity
// vmName should be unique for each test
func runCurl(t *testing.T, vmName, runtime, networkPlugin string, sleepDuration time.Duration) {
func runCurl(t *testing.T, vmName, runtime, networkPlugin string) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")

runCmd := stdCmd(
runCmd := exec.Command(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"run", "--name="+vmName,
"weaveworks/ignite-ubuntu",
"--ssh",
)
runErr := runCmd.Run()
runOut, runErr := runCmd.CombinedOutput()

defer func() {
rmvCmd := stdCmd(
rmvCmd := exec.Command(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"rm", "-f", vmName,
)
rmvErr := rmvCmd.Run()
assert.Check(t, rmvErr, fmt.Sprintf("vm removal should not fail: %q", rmvCmd.Args))
rmvOut, rmvErr := rmvCmd.CombinedOutput()
assert.Check(t, rmvErr, fmt.Sprintf("vm removal: \n%q\n%s", rmvCmd.Args, rmvOut))
}()

assert.Check(t, runErr, fmt.Sprintf("%q should not fail to run", runCmd.Args))
assert.Check(t, runErr, fmt.Sprintf("vm run: \n%q\n%s", runCmd.Args, runOut))
if runErr != nil {
return
}

time.Sleep(sleepDuration)
curlCmd := stdCmd(
time.Sleep(2 * time.Second) // TODO(https://github.com/weaveworks/ignite/issues/423): why is this necessary? Can we work to eliminate this?
curlCmd := exec.Command(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"exec", vmName,
"curl", "google.com",
)
curlErr := curlCmd.Run()
assert.Check(t, curlErr, fmt.Sprintf("curl should not fail: %q", curlCmd.Args))
curlOut, curlErr := curlCmd.CombinedOutput()
assert.Check(t, curlErr, fmt.Sprintf("curl: \n%q\n%s", curlCmd.Args, curlOut))
}

func TestCurlWithDockerAndDockerBridge(t *testing.T) {
Expand All @@ -137,7 +129,6 @@ func TestCurlWithDockerAndDockerBridge(t *testing.T) {
"e2e_test_curl_docker_and_docker_bridge",
"docker",
"docker-bridge",
0,
)
}

Expand All @@ -147,7 +138,6 @@ func TestCurlWithDockerAndCNI(t *testing.T) {
"e2e_test_curl_docker_and_cni",
"docker",
"cni",
0,
)
}

Expand All @@ -157,26 +147,5 @@ func TestCurlWithContainerdAndCNI(t *testing.T) {
"e2e_test_curl_containerd_and_cni",
"containerd",
"cni",
0,
)
}

func TestCurlWithDockerAndCNISleep2(t *testing.T) {
runCurl(
t,
"e2e_test_curl_docker_and_cni_sleep2",
"docker",
"cni",
2 * time.Second, // TODO: why is this necessary? Can we work to eliminate this?
)
}

func TestCurlWithContainerdAndCNISleep2(t *testing.T) {
runCurl(
t,
"e2e_test_curl_containerd_and_cni_sleep2",
"containerd",
"cni",
2 * time.Second,
)
}

0 comments on commit e8a2996

Please sign in to comment.