From 6bbb456138e48c7558cfe5c797c57d136f1a694b Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Mon, 16 Feb 2015 11:32:25 -0800 Subject: [PATCH 1/2] readContainerFileWithExec for links tests Shout out to @estesp for the idea. Some use cases of `readContainerFile` can be replaced with `docker exec $id cat $file`. This helper method can eliminate the requirement that host/cli should be on the same machine. TestRunMutableNetworkFiles and TestRunResolvconfUpdater still need to access the docker host filesystem as they modify the file directly from there assuming cli and daemon are on the same machine. This fixes TestLinksUpdateOnRestart and TestLinksHostsFilesInject for Windows CI. Signed-off-by: Ahmet Alp Balkan --- integration-cli/docker_cli_links_test.go | 8 ++++---- integration-cli/docker_utils.go | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 651e96f8cc..a429902ee4 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -251,12 +251,12 @@ func TestLinksHostsFilesInject(t *testing.T) { time.Sleep(1 * time.Second) - contentOne, err := readContainerFile(idOne, "hosts") + contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts") if err != nil { t.Fatal(err, string(contentOne)) } - contentTwo, err := readContainerFile(idTwo, "hosts") + contentTwo, err := readContainerFileWithExec(idTwo, "/etc/hosts") if err != nil { t.Fatal(err, string(contentTwo)) } @@ -302,7 +302,7 @@ func TestLinksUpdateOnRestart(t *testing.T) { if err != nil { t.Fatal(err) } - content, err := readContainerFile(id, "hosts") + content, err := readContainerFileWithExec(id, "/etc/hosts") if err != nil { t.Fatal(err, string(content)) } @@ -327,7 +327,7 @@ func TestLinksUpdateOnRestart(t *testing.T) { if err != nil { t.Fatal(err) } - content, err = readContainerFile(id, "hosts") + content, err = readContainerFileWithExec(id, "/etc/hosts") if err != nil { t.Fatal(err, string(content)) } diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 56283952ca..2c4518fa14 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -895,6 +895,11 @@ func readContainerFile(containerId, filename string) ([]byte, error) { return content, nil } +func readContainerFileWithExec(containerId, filename string) ([]byte, error) { + out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "exec", containerId, "cat", filename)) + return []byte(out), err +} + func setupRegistry(t *testing.T) func() { reg, err := newTestRegistryV2(t) if err != nil { From 102e0611475c7267dd4d2a87044fcc40b2eddcc0 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Fri, 20 Feb 2015 23:24:30 -0800 Subject: [PATCH 2/2] integration-cli: add test requirement ExecSupport Skip tests based on remote daemon's exec support (to exclude these tests from `make test` ran in LXC case). Makes use of `test_no_exec` build tag passed by build scripts. Signed-off-by: Ahmet Alp Balkan --- integration-cli/docker_cli_links_test.go | 4 ++-- integration-cli/requirements.go | 4 ++++ integration-cli/test_vars_exec.go | 8 ++++++++ integration-cli/test_vars_noexec.go | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 integration-cli/test_vars_exec.go create mode 100644 integration-cli/test_vars_noexec.go diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index a429902ee4..652db3280e 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -231,7 +231,7 @@ func TestLinksNotStartedParentNotFail(t *testing.T) { } func TestLinksHostsFilesInject(t *testing.T) { - testRequires(t, SameHostDaemon) + testRequires(t, SameHostDaemon, ExecSupport) defer deleteAllContainers() @@ -285,7 +285,7 @@ func TestLinksNetworkHostContainer(t *testing.T) { } func TestLinksUpdateOnRestart(t *testing.T) { - testRequires(t, SameHostDaemon) + testRequires(t, SameHostDaemon, ExecSupport) defer deleteAllContainers() diff --git a/integration-cli/requirements.go b/integration-cli/requirements.go index 783e982067..fe7c51ee74 100644 --- a/integration-cli/requirements.go +++ b/integration-cli/requirements.go @@ -21,6 +21,10 @@ var ( func() bool { return isUnixCli }, "Test requires posix utilities or functionality to run.", } + ExecSupport = TestRequirement{ + func() bool { return supportsExec }, + "Test requires 'docker exec' capabilities on the tested daemon.", + } ) // testRequires checks if the environment satisfies the requirements diff --git a/integration-cli/test_vars_exec.go b/integration-cli/test_vars_exec.go new file mode 100644 index 0000000000..7633b346ba --- /dev/null +++ b/integration-cli/test_vars_exec.go @@ -0,0 +1,8 @@ +// +build !test_no_exec + +package main + +const ( + // indicates docker daemon tested supports 'docker exec' + supportsExec = true +) diff --git a/integration-cli/test_vars_noexec.go b/integration-cli/test_vars_noexec.go new file mode 100644 index 0000000000..0845090524 --- /dev/null +++ b/integration-cli/test_vars_noexec.go @@ -0,0 +1,8 @@ +// +build test_no_exec + +package main + +const ( + // indicates docker daemon tested supports 'docker exec' + supportsExec = false +)