2018-02-05 16:05:59 -05:00
|
|
|
package service // import "github.com/docker/docker/integration/service"
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
import (
|
2018-01-28 02:15:44 -05:00
|
|
|
"io/ioutil"
|
2017-08-29 02:49:26 -04:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
2018-02-02 17:36:59 -05:00
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
2017-08-29 02:49:26 -04:00
|
|
|
"github.com/docker/docker/client"
|
2018-02-09 13:13:26 -05:00
|
|
|
"github.com/docker/docker/integration/internal/swarm"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-08-29 02:49:26 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/poll"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2017-11-07 01:12:03 -05:00
|
|
|
func TestCreateServiceMultipleTimes(t *testing.T) {
|
2017-08-29 02:49:26 -04:00
|
|
|
defer setupTest(t)()
|
2018-02-02 17:36:59 -05:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2017-08-29 02:49:26 -04:00
|
|
|
defer d.Stop(t)
|
2018-01-31 18:01:29 -05:00
|
|
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
overlayName := "overlay1"
|
|
|
|
networkCreate := types.NetworkCreate{
|
|
|
|
CheckDuplicate: true,
|
|
|
|
Driver: "overlay",
|
|
|
|
}
|
|
|
|
|
|
|
|
netResp, err := client.NetworkCreate(context.Background(), overlayName, networkCreate)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 02:49:26 -04:00
|
|
|
overlayID := netResp.ID
|
|
|
|
|
2017-11-07 01:12:03 -05:00
|
|
|
var instances uint64 = 4
|
2017-08-29 02:49:26 -04:00
|
|
|
serviceSpec := swarmServiceSpec("TestService", instances)
|
2018-02-02 17:36:59 -05:00
|
|
|
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: overlayName})
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
|
|
|
|
QueryRegistry: false,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
serviceID := serviceResp.ID
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
err = client.ServiceRemove(context.Background(), serviceID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 02:49:26 -04:00
|
|
|
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
2017-11-07 01:12:03 -05:00
|
|
|
|
|
|
|
serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
|
|
|
|
QueryRegistry: false,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-07 01:12:03 -05:00
|
|
|
|
|
|
|
serviceID2 := serviceResp.ID
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll)
|
2017-11-07 01:12:03 -05:00
|
|
|
|
|
|
|
err = client.ServiceRemove(context.Background(), serviceID2)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-07 01:12:03 -05:00
|
|
|
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID2), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
2017-11-07 01:12:03 -05:00
|
|
|
|
2017-08-29 02:49:26 -04:00
|
|
|
err = client.NetworkRemove(context.Background(), overlayID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 02:49:26 -04:00
|
|
|
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
}
|
|
|
|
|
2017-10-31 16:05:24 -04:00
|
|
|
func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 17:36:59 -05:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2017-10-31 16:05:24 -04:00
|
|
|
defer d.Stop(t)
|
2018-01-31 18:01:29 -05:00
|
|
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
name := "foo"
|
|
|
|
networkCreate := types.NetworkCreate{
|
|
|
|
CheckDuplicate: false,
|
|
|
|
Driver: "bridge",
|
|
|
|
}
|
|
|
|
|
|
|
|
n1, err := client.NetworkCreate(context.Background(), name, networkCreate)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
n2, err := client.NetworkCreate(context.Background(), name, networkCreate)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
// Dupliates with name but with different driver
|
|
|
|
networkCreate.Driver = "overlay"
|
|
|
|
n3, err := client.NetworkCreate(context.Background(), name, networkCreate)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
// Create Service with the same name
|
|
|
|
var instances uint64 = 1
|
|
|
|
serviceSpec := swarmServiceSpec("top", instances)
|
|
|
|
|
2018-02-02 17:36:59 -05:00
|
|
|
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: name})
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
service, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, service.ID, instances), swarm.ServicePoll)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
resp, _, err := client.ServiceInspectWithRaw(context.Background(), service.ID, types.ServiceInspectOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(n3.ID, resp.Spec.TaskTemplate.Networks[0].Target))
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
// Remove Service
|
|
|
|
err = client.ServiceRemove(context.Background(), service.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
// Make sure task has been destroyed.
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, service.ID), swarm.ServicePoll)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
// Remove networks
|
|
|
|
err = client.NetworkRemove(context.Background(), n3.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
err = client.NetworkRemove(context.Background(), n2.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
err = client.NetworkRemove(context.Background(), n1.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 16:05:24 -04:00
|
|
|
|
|
|
|
// Make sure networks have been destroyed.
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, n3.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, n2.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, n1.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
}
|
|
|
|
|
2018-01-28 02:15:44 -05:00
|
|
|
func TestCreateServiceSecretFileMode(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 17:36:59 -05:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-01-28 02:15:44 -05:00
|
|
|
defer d.Stop(t)
|
2018-01-31 18:01:29 -05:00
|
|
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
ctx := context.Background()
|
2018-02-02 17:36:59 -05:00
|
|
|
secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-01-28 02:15:44 -05:00
|
|
|
Name: "TestSecret",
|
|
|
|
},
|
|
|
|
Data: []byte("TESTSECRET"),
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
var instances uint64 = 1
|
2018-02-02 17:36:59 -05:00
|
|
|
serviceSpec := swarmtypes.ServiceSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-01-28 02:15:44 -05:00
|
|
|
Name: "TestService",
|
|
|
|
},
|
2018-02-02 17:36:59 -05:00
|
|
|
TaskTemplate: swarmtypes.TaskSpec{
|
|
|
|
ContainerSpec: &swarmtypes.ContainerSpec{
|
2018-01-28 02:15:44 -05:00
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/sh", "-c", "ls -l /etc/secret || /bin/top"},
|
2018-02-02 17:36:59 -05:00
|
|
|
Secrets: []*swarmtypes.SecretReference{
|
2018-01-28 02:15:44 -05:00
|
|
|
{
|
2018-02-02 17:36:59 -05:00
|
|
|
File: &swarmtypes.SecretReferenceFileTarget{
|
2018-01-28 02:15:44 -05:00
|
|
|
Name: "/etc/secret",
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0777,
|
|
|
|
},
|
|
|
|
SecretID: secretResp.ID,
|
|
|
|
SecretName: "TestSecret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-02-02 17:36:59 -05:00
|
|
|
Mode: swarmtypes.ServiceMode{
|
|
|
|
Replicated: &swarmtypes.ReplicatedService{
|
2018-01-28 02:15:44 -05:00
|
|
|
Replicas: &instances,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceResp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{
|
|
|
|
QueryRegistry: false,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances), swarm.ServicePoll)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("service", serviceResp.ID)
|
|
|
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(tasks), 1))
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{
|
|
|
|
ShowStdout: true,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
content, err := ioutil.ReadAll(body)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
err = client.ServiceRemove(ctx, serviceResp.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
2018-03-27 00:06:46 -04:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
err = client.SecretRemove(ctx, "TestSecret")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateServiceConfigFileMode(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 17:36:59 -05:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-01-28 02:15:44 -05:00
|
|
|
defer d.Stop(t)
|
2018-01-31 18:01:29 -05:00
|
|
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
ctx := context.Background()
|
2018-02-02 17:36:59 -05:00
|
|
|
configResp, err := client.ConfigCreate(ctx, swarmtypes.ConfigSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-01-28 02:15:44 -05:00
|
|
|
Name: "TestConfig",
|
|
|
|
},
|
|
|
|
Data: []byte("TESTCONFIG"),
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
var instances uint64 = 1
|
2018-02-02 17:36:59 -05:00
|
|
|
serviceSpec := swarmtypes.ServiceSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-01-28 02:15:44 -05:00
|
|
|
Name: "TestService",
|
|
|
|
},
|
2018-02-02 17:36:59 -05:00
|
|
|
TaskTemplate: swarmtypes.TaskSpec{
|
|
|
|
ContainerSpec: &swarmtypes.ContainerSpec{
|
2018-01-28 02:15:44 -05:00
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/sh", "-c", "ls -l /etc/config || /bin/top"},
|
2018-02-02 17:36:59 -05:00
|
|
|
Configs: []*swarmtypes.ConfigReference{
|
2018-01-28 02:15:44 -05:00
|
|
|
{
|
2018-02-02 17:36:59 -05:00
|
|
|
File: &swarmtypes.ConfigReferenceFileTarget{
|
2018-01-28 02:15:44 -05:00
|
|
|
Name: "/etc/config",
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0777,
|
|
|
|
},
|
|
|
|
ConfigID: configResp.ID,
|
|
|
|
ConfigName: "TestConfig",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-02-02 17:36:59 -05:00
|
|
|
Mode: swarmtypes.ServiceMode{
|
|
|
|
Replicated: &swarmtypes.ReplicatedService{
|
2018-01-28 02:15:44 -05:00
|
|
|
Replicas: &instances,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceResp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{
|
|
|
|
QueryRegistry: false,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances))
|
|
|
|
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("service", serviceResp.ID)
|
|
|
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(tasks), 1))
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{
|
|
|
|
ShowStdout: true,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
content, err := ioutil.ReadAll(body)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
err = client.ServiceRemove(ctx, serviceResp.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
|
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID))
|
|
|
|
poll.WaitOn(t, noTasks(client))
|
|
|
|
|
|
|
|
err = client.ConfigRemove(ctx, "TestConfig")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 02:15:44 -05:00
|
|
|
}
|
|
|
|
|
2018-02-02 17:36:59 -05:00
|
|
|
func swarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec {
|
|
|
|
return swarmtypes.ServiceSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2017-08-29 02:49:26 -04:00
|
|
|
Name: name,
|
|
|
|
},
|
2018-02-02 17:36:59 -05:00
|
|
|
TaskTemplate: swarmtypes.TaskSpec{
|
|
|
|
ContainerSpec: &swarmtypes.ContainerSpec{
|
2017-08-29 02:49:26 -04:00
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/top"},
|
|
|
|
},
|
|
|
|
},
|
2018-02-02 17:36:59 -05:00
|
|
|
Mode: swarmtypes.ServiceMode{
|
|
|
|
Replicated: &swarmtypes.ReplicatedService{
|
2017-08-29 02:49:26 -04:00
|
|
|
Replicas: &replicas,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("service", serviceID)
|
|
|
|
tasks, err := client.TaskList(context.Background(), types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return poll.Error(err)
|
|
|
|
case len(tasks) == int(instances):
|
|
|
|
for _, task := range tasks {
|
2018-02-02 17:36:59 -05:00
|
|
|
if task.Status.State != swarmtypes.TaskStateRunning {
|
2017-08-29 02:49:26 -04:00
|
|
|
return poll.Continue("waiting for tasks to enter run state")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
default:
|
|
|
|
return poll.Continue("task count at %d waiting for %d", len(tasks), instances)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 01:12:03 -05:00
|
|
|
func noTasks(client client.ServiceAPIClient) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
tasks, err := client.TaskList(context.Background(), types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return poll.Error(err)
|
|
|
|
case len(tasks) == 0:
|
|
|
|
return poll.Success()
|
|
|
|
default:
|
|
|
|
return poll.Continue("task count at %d waiting for 0", len(tasks))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 02:49:26 -04:00
|
|
|
func serviceIsRemoved(client client.ServiceAPIClient, serviceID string) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("service", serviceID)
|
|
|
|
_, err := client.TaskList(context.Background(), types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
return poll.Continue("waiting for service %s to be deleted", serviceID)
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func networkIsRemoved(client client.NetworkAPIClient, networkID string) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
_, err := client.NetworkInspect(context.Background(), networkID, types.NetworkInspectOptions{})
|
|
|
|
if err == nil {
|
|
|
|
return poll.Continue("waiting for network %s to be removed", networkID)
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
}
|