From 878e5fbc01d90db16742fb58c914a992ff3fe992 Mon Sep 17 00:00:00 2001 From: leigh capili Date: Wed, 11 Sep 2019 06:39:40 -0600 Subject: [PATCH 1/2] Refactor e2e and add docker+cni --- e2e/run_test.go | 92 ++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/e2e/run_test.go b/e2e/run_test.go index 62e676cc1..657d27c49 100644 --- a/e2e/run_test.go +++ b/e2e/run_test.go @@ -19,56 +19,70 @@ import ( "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 TestIgniteRunWithContainerdAndCNI(t *testing.T) { - // vmName should be unique for each test - const vmName = "e2e_test_ignite_run_containerd_and_cni" - - binary := path.Join(e2eHome, "bin/ignite") - cmd := exec.Command(binary, - "--runtime=containerd", - "--network-plugin=cni", - "run", "--name="+vmName, - "weaveworks/ignite-ubuntu") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() +func TestIgniteRunWithDockerAndDockerBridge(t *testing.T) { + runWithRuntimeAndNetworkPlugin( + t, + "e2e_test_ignite_run_docker_and_docker_bridge", + "docker", + "docker-bridge", + ) +} - defer func() { - cmd := exec.Command(binary, - "--runtime=containerd", - "--network-plugin=cni", - "rm", "-f", vmName) - assert.Check(t, cmd.Run(), "vm removal should not fail") - }() +func TestIgniteRunWithDockerAndCNI(t *testing.T) { + runWithRuntimeAndNetworkPlugin( + t, + "e2e_test_ignite_run_docker_and_cni", + "docker", + "cni", + ) +} - assert.Check(t, err, fmt.Sprintf("%q should not fail to run", cmd.Args)) +func TestIgniteRunWithContainerdAndCNI(t *testing.T) { + runWithRuntimeAndNetworkPlugin( + t, + "e2e_test_ignite_run_containerd_and_cni", + "containerd", + "cni", + ) } From 6893995c8a3fc3f1d1892ffb3e474980cceb6a4b Mon Sep 17 00:00:00 2001 From: leigh capili Date: Wed, 11 Sep 2019 06:40:32 -0600 Subject: [PATCH 2/2] Add e2e tests for internet connectivity --- e2e/run_test.go | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/e2e/run_test.go b/e2e/run_test.go index 657d27c49..bfd933048 100644 --- a/e2e/run_test.go +++ b/e2e/run_test.go @@ -15,6 +15,7 @@ import ( "os/exec" "path" "testing" + "time" "gotest.tools/assert" ) @@ -86,3 +87,96 @@ func TestIgniteRunWithContainerdAndCNI(t *testing.T) { "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") + + runCmd := stdCmd( + igniteBin, + "--runtime="+runtime, + "--network-plugin="+networkPlugin, + "run", "--name="+vmName, + "weaveworks/ignite-ubuntu", + "--ssh", + ) + runErr := runCmd.Run() + + defer func() { + 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, 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, + ) +}