1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #36468 from vdemeester/e2e-container-run

Fixes some integration/container tests to run on remote daemon
This commit is contained in:
Yong Tang 2018-03-05 12:23:24 -08:00 committed by GitHub
commit 4b2fb7e394
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 22 deletions

View file

@ -85,7 +85,7 @@ type DockerSuite struct {
} }
func (s *DockerSuite) OnTimeout(c *check.C) { func (s *DockerSuite) OnTimeout(c *check.C) {
if !testEnv.IsLocalDaemon() { if testEnv.IsRemoteDaemon() {
return return
} }
path := filepath.Join(os.Getenv("DEST"), "docker.pid") path := filepath.Join(os.Getenv("DEST"), "docker.pid")

View file

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/container"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -26,6 +27,7 @@ import (
// the container process, then start dockerd back up and attempt to start the // the container process, then start dockerd back up and attempt to start the
// container again. // container again.
func TestContainerStartOnDaemonRestart(t *testing.T) { func TestContainerStartOnDaemonRestart(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon(), "cannot start daemon on remote test run")
t.Parallel() t.Parallel()
d := daemon.New(t, "", "dockerd", daemon.Config{}) d := daemon.New(t, "", "dockerd", daemon.Config{})

View file

@ -20,7 +20,7 @@ import (
) )
func TestLinksEtcHostsContentMatch(t *testing.T) { func TestLinksEtcHostsContentMatch(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
hosts, err := ioutil.ReadFile("/etc/hosts") hosts, err := ioutil.ReadFile("/etc/hosts")
skip.If(t, os.IsNotExist(err)) skip.If(t, os.IsNotExist(err))

View file

@ -23,6 +23,7 @@ import (
) )
func TestContainerShmNoLeak(t *testing.T) { func TestContainerShmNoLeak(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon(), "cannot start daemon on remote test run")
t.Parallel() t.Parallel()
d := daemon.New(t, "docker", "dockerd", daemon.Config{}) d := daemon.New(t, "docker", "dockerd", daemon.Config{})
client, err := d.NewClient() client, err := d.NewClient()
@ -94,7 +95,7 @@ func TestContainerShmNoLeak(t *testing.T) {
func TestContainerNetworkMountsNoChown(t *testing.T) { func TestContainerNetworkMountsNoChown(t *testing.T) {
// chown only applies to Linux bind mounted volumes; must be same host to verify // chown only applies to Linux bind mounted volumes; must be same host to verify
skip.If(t, testEnv.DaemonInfo.OSType != "linux" || !testEnv.IsLocalDaemon()) skip.If(t, testEnv.DaemonInfo.OSType != "linux" || testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()

View file

@ -22,7 +22,7 @@ import (
) )
func TestNetworkNat(t *testing.T) { func TestNetworkNat(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()
@ -40,7 +40,7 @@ func TestNetworkNat(t *testing.T) {
} }
func TestNetworkLocalhostTCPNat(t *testing.T) { func TestNetworkLocalhostTCPNat(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()
@ -57,7 +57,7 @@ func TestNetworkLocalhostTCPNat(t *testing.T) {
} }
func TestNetworkLoopbackNat(t *testing.T) { func TestNetworkLoopbackNat(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
msg := "it works" msg := "it works"
startServerContainer(t, msg, 8080) startServerContainer(t, msg, 8080)

View file

@ -25,20 +25,19 @@ func TestPause(t *testing.T) {
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
ctx := context.Background() ctx := context.Background()
name := "testeventpause" cID := container.Run(t, ctx, client)
cID := container.Run(t, ctx, client, container.WithName(name))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
since := request.DaemonUnixTime(ctx, t, client, testEnv) since := request.DaemonUnixTime(ctx, t, client, testEnv)
err := client.ContainerPause(ctx, name) err := client.ContainerPause(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
inspect, err := client.ContainerInspect(ctx, cID) inspect, err := client.ContainerInspect(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.State.Paused, true) assert.Equal(t, inspect.State.Paused, true)
err = client.ContainerUnpause(ctx, name) err = client.ContainerUnpause(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
until := request.DaemonUnixTime(ctx, t, client, testEnv) until := request.DaemonUnixTime(ctx, t, client, testEnv)
@ -46,7 +45,7 @@ func TestPause(t *testing.T) {
messages, errs := client.Events(ctx, types.EventsOptions{ messages, errs := client.Events(ctx, types.EventsOptions{
Since: since, Since: since,
Until: until, Until: until,
Filters: filters.NewArgs(filters.Arg("container", name)), Filters: filters.NewArgs(filters.Arg("container", cID)),
}) })
assert.Equal(t, getEventActions(t, messages, errs), []string{"pause", "unpause"}) assert.Equal(t, getEventActions(t, messages, errs), []string{"pause", "unpause"})
} }

View file

@ -27,7 +27,7 @@ func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
// Test case for #5244: `docker rm` fails if bind dir doesn't exist anymore // Test case for #5244: `docker rm` fails if bind dir doesn't exist anymore
func TestRemoveContainerWithRemovedVolume(t *testing.T) { func TestRemoveContainerWithRemovedVolume(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()
ctx := context.Background() ctx := context.Background()

View file

@ -55,7 +55,7 @@ func TestRenameStoppedContainer(t *testing.T) {
inspect, err := client.ContainerInspect(ctx, cID) inspect, err := client.ContainerInspect(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.Name, "/"+oldName) assert.Equal(t, "/"+oldName, inspect.Name)
newName := "new_name" + stringid.GenerateNonCryptoID() newName := "new_name" + stringid.GenerateNonCryptoID()
err = client.ContainerRename(ctx, oldName, newName) err = client.ContainerRename(ctx, oldName, newName)
@ -63,7 +63,7 @@ func TestRenameStoppedContainer(t *testing.T) {
inspect, err = client.ContainerInspect(ctx, cID) inspect, err = client.ContainerInspect(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.Name, "/"+newName) assert.Equal(t, "/"+newName, inspect.Name)
} }
func TestRenameRunningContainerAndReuse(t *testing.T) { func TestRenameRunningContainerAndReuse(t *testing.T) {
@ -81,7 +81,7 @@ func TestRenameRunningContainerAndReuse(t *testing.T) {
inspect, err := client.ContainerInspect(ctx, cID) inspect, err := client.ContainerInspect(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.Name, "/"+newName) assert.Equal(t, "/"+newName, inspect.Name)
_, err = client.ContainerInspect(ctx, oldName) _, err = client.ContainerInspect(ctx, oldName)
testutil.ErrorContains(t, err, "No such container: "+oldName) testutil.ErrorContains(t, err, "No such container: "+oldName)
@ -91,7 +91,7 @@ func TestRenameRunningContainerAndReuse(t *testing.T) {
inspect, err = client.ContainerInspect(ctx, cID) inspect, err = client.ContainerInspect(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.Name, "/"+oldName) assert.Equal(t, "/"+oldName, inspect.Name)
} }
func TestRenameInvalidName(t *testing.T) { func TestRenameInvalidName(t *testing.T) {
@ -108,7 +108,7 @@ func TestRenameInvalidName(t *testing.T) {
inspect, err := client.ContainerInspect(ctx, oldName) inspect, err := client.ContainerInspect(ctx, oldName)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.ID, cID) assert.Equal(t, cID, inspect.ID)
} }
// Test case for GitHub issue 22466 // Test case for GitHub issue 22466
@ -133,6 +133,10 @@ func TestRenameAnonymousContainer(t *testing.T) {
}) })
err = client.ContainerRename(ctx, cID, "container1") err = client.ContainerRename(ctx, cID, "container1")
require.NoError(t, err) require.NoError(t, err)
// Stop/Start the container to get registered
// FIXME(vdemeester) this is a really weird behavior as it fails otherwise
err = client.ContainerStop(ctx, "container1", nil)
require.NoError(t, err)
err = client.ContainerStart(ctx, "container1", types.ContainerStartOptions{}) err = client.ContainerStart(ctx, "container1", types.ContainerStartOptions{})
require.NoError(t, err) require.NoError(t, err)
@ -152,7 +156,7 @@ func TestRenameAnonymousContainer(t *testing.T) {
inspect, err := client.ContainerInspect(ctx, cID) inspect, err := client.ContainerInspect(ctx, cID)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.State.ExitCode, 0) assert.Equal(t, 0, inspect.State.ExitCode, "container %s exited with the wrong exitcode: %+v", cID, inspect)
} }
// TODO: should be a unit test // TODO: should be a unit test
@ -175,7 +179,7 @@ func TestRenameContainerWithSameName(t *testing.T) {
// of the linked container should be updated so that the other // of the linked container should be updated so that the other
// container could still reference to the container that is renamed. // container could still reference to the container that is renamed.
func TestRenameContainerWithLinkedContainer(t *testing.T) { func TestRenameContainerWithLinkedContainer(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()
ctx := context.Background() ctx := context.Background()
@ -192,5 +196,5 @@ func TestRenameContainerWithLinkedContainer(t *testing.T) {
inspect, err := client.ContainerInspect(ctx, "app2/mysql") inspect, err := client.ContainerInspect(ctx, "app2/mysql")
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, inspect.ID, db1ID) assert.Equal(t, db1ID, inspect.ID)
} }

View file

@ -9,9 +9,11 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
"github.com/gotestyourself/gotestyourself/skip"
) )
func TestDaemonRestartKillContainers(t *testing.T) { func TestDaemonRestartKillContainers(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon(), "cannot start daemon on remote test run")
type testCase struct { type testCase struct {
desc string desc string
config *container.Config config *container.Config

View file

@ -18,7 +18,7 @@ import (
) )
func TestInspect(t *testing.T) { func TestInspect(t *testing.T) {
skip.IfCondition(t, !testEnv.IsLocalDaemon()) skip.IfCondition(t, testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()
d := swarm.NewSwarm(t, testEnv) d := swarm.NewSwarm(t, testEnv)
defer d.Stop(t) defer d.Stop(t)

View file

@ -96,7 +96,7 @@ func toSlash(path string) string {
} }
// IsLocalDaemon is true if the daemon under test is on the same // IsLocalDaemon is true if the daemon under test is on the same
// host as the CLI. // host as the test process.
// //
// Deterministically working out the environment in which CI is running // Deterministically working out the environment in which CI is running
// to evaluate whether the daemon is local or remote is not possible through // to evaluate whether the daemon is local or remote is not possible through
@ -115,6 +115,12 @@ func (e *Execution) IsLocalDaemon() bool {
return os.Getenv("DOCKER_REMOTE_DAEMON") == "" return os.Getenv("DOCKER_REMOTE_DAEMON") == ""
} }
// IsRemoteDaemon is true if the daemon under test is on different host
// as the test process.
func (e *Execution) IsRemoteDaemon() bool {
return !e.IsLocalDaemon()
}
// Print the execution details to stdout // Print the execution details to stdout
// TODO: print everything // TODO: print everything
func (e *Execution) Print() { func (e *Execution) Print() {