From 2a70ff3e1f5c3e13ee84a1672fdc7c1013b82669 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 10 Aug 2015 16:00:38 -0700 Subject: [PATCH 1/2] display only containers created by swarm in mesos Signed-off-by: Victor Vieux --- cluster/mesos/cluster.go | 6 ++++- cluster/mesos/cluster_test.go | 9 ++------ test/integration/mesos/api/ps.bats | 36 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 test/integration/mesos/api/ps.bats diff --git a/cluster/mesos/cluster.go b/cluster/mesos/cluster.go index 3b84d5da0b..67e18e82d8 100644 --- a/cluster/mesos/cluster.go +++ b/cluster/mesos/cluster.go @@ -243,7 +243,11 @@ func (c *Cluster) Containers() cluster.Containers { out := cluster.Containers{} for _, s := range c.slaves { for _, container := range s.engine.Containers() { - out = append(out, formatContainer(container)) + if container.Config.Labels != nil { + if _, ok := container.Config.Labels[cluster.SwarmLabelNamespace+".mesos.task"]; ok { + out = append(out, formatContainer(container)) + } + } } } diff --git a/cluster/mesos/cluster_test.go b/cluster/mesos/cluster_test.go index ea9d9e5c08..d416442c70 100644 --- a/cluster/mesos/cluster_test.go +++ b/cluster/mesos/cluster_test.go @@ -32,7 +32,7 @@ func TestContainerLookup(t *testing.T) { }, Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{ Labels: map[string]string{ - "com.docker.swarm.id": "swarm1-id", + "com.docker.swarm.mesos.task": "task1-id", }, }), } @@ -44,7 +44,7 @@ func TestContainerLookup(t *testing.T) { }, Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{ Labels: map[string]string{ - "com.docker.swarm.id": "swarm2-id", + "com.docker.swarm.mesos.task": "task2-id", }, }), } @@ -66,11 +66,6 @@ func TestContainerLookup(t *testing.T) { // Container engine/name matching. assert.NotNil(t, c.Container("test-engine/container1-name1")) assert.NotNil(t, c.Container("test-engine/container1-name2")) - // Swarm ID lookup. - assert.NotNil(t, c.Container("swarm1-id")) - // Swarm ID prefix lookup. - assert.NotNil(t, c.Container("swarm1-")) - assert.Nil(t, c.Container("swarm")) // Match name before ID prefix cc := c.Container("con") assert.NotNil(t, cc) diff --git a/test/integration/mesos/api/ps.bats b/test/integration/mesos/api/ps.bats new file mode 100644 index 0000000000..0123313838 --- /dev/null +++ b/test/integration/mesos/api/ps.bats @@ -0,0 +1,36 @@ +#!/usr/bin/env bats + +load ../mesos_helpers + +function teardown() { + swarm_manage_cleanup + stop_mesos + stop_docker +} + +@test "mesos - docker ps" { + start_docker_with_busybox 2 + start_mesos + swarm_manage --cluster-driver mesos-experimental 127.0.0.1:$MESOS_MASTER_PORT + + # make sure no container exist + run docker_swarm ps -qa + [ "${#lines[@]}" -eq 0 ] + + # run + docker_swarm run -m 20m -d --name test_container busybox sleep 100 + + # verify, container is running + run docker_swarm ps -aq + [ "${#lines[@]}" -eq 1 ] + + run docker -H ${HOSTS[0]} run -d --name test_container2 busybox sleep 100 + + # verify, container is running + run docker -H ${HOSTS[0]} ps -q --filter=name=test_container2 --filter=status=running + [ "${#lines[@]}" -eq 1 ] + + # check we only the swarm containers are displayed + run docker_swarm ps -q + [ "${#lines[@]}" -eq 1 ] +} \ No newline at end of file From d5c41a38c179acea9d4d77e79c66e5c3a9126316 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 10 Aug 2015 23:09:52 -0700 Subject: [PATCH 2/2] update tests Signed-off-by: Victor Vieux --- cluster/mesos/cluster_test.go | 15 ++++++++++++++- cluster/swarm/cluster_test.go | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cluster/mesos/cluster_test.go b/cluster/mesos/cluster_test.go index d416442c70..6d3c8131f4 100644 --- a/cluster/mesos/cluster_test.go +++ b/cluster/mesos/cluster_test.go @@ -33,6 +33,7 @@ func TestContainerLookup(t *testing.T) { Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{ Labels: map[string]string{ "com.docker.swarm.mesos.task": "task1-id", + "com.docker.swarm.mesos.name": "container1-name1", }, }), } @@ -45,13 +46,25 @@ func TestContainerLookup(t *testing.T) { Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{ Labels: map[string]string{ "com.docker.swarm.mesos.task": "task2-id", + "com.docker.swarm.mesos.name": "con", }, }), } - s := createSlave(t, "test-engine", container1, container2) + container3 := &cluster.Container{ + Container: dockerclient.Container{ + Id: "container3-id", + Names: []string{"/container3-name"}, + }, + Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{}), + } + + s := createSlave(t, "test-engine", container1, container2, container3) c.slaves[s.id] = s + // Hide container without `com.docker.swarm.mesos.task` + assert.Equal(t, len(c.Containers()), 2) + // Invalid lookup assert.Nil(t, c.Container("invalid-id")) assert.Nil(t, c.Container("")) diff --git a/cluster/swarm/cluster_test.go b/cluster/swarm/cluster_test.go index bd65d97c27..4db853647b 100644 --- a/cluster/swarm/cluster_test.go +++ b/cluster/swarm/cluster_test.go @@ -84,6 +84,8 @@ func TestContainerLookup(t *testing.T) { n := createEngine(t, "test-engine", container1, container2) c.engines[n.ID] = n + assert.Equal(t, len(c.Containers()), 2) + // Invalid lookup assert.Nil(t, c.Container("invalid-id")) assert.Nil(t, c.Container(""))