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 #422 from stealthybox/improve_e2e
Browse files Browse the repository at this point in the history
e2e docker+cni and curl google.com
  • Loading branch information
chanwit authored Sep 12, 2019
2 parents 6b3b9d4 + 6893995 commit 67ae546
Showing 1 changed file with 142 additions and 34 deletions.
176 changes: 142 additions & 34 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,168 @@ import (
"os/exec"
"path"
"testing"
"time"

"gotest.tools/assert"
)

var e2eHome = os.Getenv("IGNITE_E2E_HOME")
var (
e2eHome = os.Getenv("IGNITE_E2E_HOME")
igniteBin = path.Join(e2eHome, "bin/ignite")
)

func TestIgniteRunWithDockerAndDockerBridge(t *testing.T) {
// vmName should be unique for each test
const vmName = "e2e_test_ignite_run_docker_and_docker_bridge"
// 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")

binary := path.Join(e2eHome, "bin/ignite")
cmd := exec.Command(binary,
"--runtime=docker",
"--network-plugin=docker-bridge",
runCmd := stdCmd(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"run", "--name="+vmName,
"weaveworks/ignite-ubuntu")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
"weaveworks/ignite-ubuntu",
)
runErr := runCmd.Run()

defer func() {
cmd := exec.Command(binary,
"--runtime=docker",
"--network-plugin=docker-bridge",
"rm", "-f", vmName)
assert.Check(t, cmd.Run(), "vm removal should not fail")
rmvCmd := stdCmd(
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))
}()

assert.Check(t, err, fmt.Sprintf("%q should not fail to run", cmd.Args))
assert.Check(t, runErr, fmt.Sprintf("%q should not fail to run", runCmd.Args))
}

func TestIgniteRunWithDockerAndDockerBridge(t *testing.T) {
runWithRuntimeAndNetworkPlugin(
t,
"e2e_test_ignite_run_docker_and_docker_bridge",
"docker",
"docker-bridge",
)
}

func TestIgniteRunWithDockerAndCNI(t *testing.T) {
runWithRuntimeAndNetworkPlugin(
t,
"e2e_test_ignite_run_docker_and_cni",
"docker",
"cni",
)
}

func TestIgniteRunWithContainerdAndCNI(t *testing.T) {
// vmName should be unique for each test
const vmName = "e2e_test_ignite_run_containerd_and_cni"
runWithRuntimeAndNetworkPlugin(
t,
"e2e_test_ignite_run_containerd_and_cni",
"containerd",
"cni",
)
}

// 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) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")

binary := path.Join(e2eHome, "bin/ignite")
cmd := exec.Command(binary,
"--runtime=containerd",
"--network-plugin=cni",
runCmd := stdCmd(
igniteBin,
"--runtime="+runtime,
"--network-plugin="+networkPlugin,
"run", "--name="+vmName,
"weaveworks/ignite-ubuntu")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
"weaveworks/ignite-ubuntu",
"--ssh",
)
runErr := runCmd.Run()

defer func() {
cmd := exec.Command(binary,
"--runtime=containerd",
"--network-plugin=cni",
"rm", "-f", vmName)
assert.Check(t, cmd.Run(), "vm removal should not fail")
rmvCmd := stdCmd(
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))
}()

assert.Check(t, err, fmt.Sprintf("%q should not fail to run", cmd.Args))
assert.Check(t, runErr, fmt.Sprintf("%q should not fail to run", runCmd.Args))
if runErr != nil {
return
}

time.Sleep(sleepDuration)
curlCmd := stdCmd(
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))
}

func TestCurlWithDockerAndDockerBridge(t *testing.T) {
runCurl(
t,
"e2e_test_curl_docker_and_docker_bridge",
"docker",
"docker-bridge",
0,
)
}

func TestCurlWithDockerAndCNI(t *testing.T) {
runCurl(
t,
"e2e_test_curl_docker_and_cni",
"docker",
"cni",
0,
)
}

func TestCurlWithContainerdAndCNI(t *testing.T) {
runCurl(
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 67ae546

Please sign in to comment.