2016-06-17 19:24:07 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-10-31 15:38:00 -04:00
|
|
|
"fmt"
|
2016-06-17 19:24:07 -04:00
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-06-17 19:24:07 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2016-07-25 15:54:38 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceUpdateLabel(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name=test", "busybox", "top")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-12-09 04:17:53 -05:00
|
|
|
service := d.GetService(c, "test")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 0)
|
|
|
|
|
|
|
|
// add label to empty set
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "test", "--label-add", "foo=bar")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-12-09 04:17:53 -05:00
|
|
|
service = d.GetService(c, "test")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
|
|
|
c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar")
|
|
|
|
|
|
|
|
// add label to non-empty set
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "test", "--label-add", "foo2=bar")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-12-09 04:17:53 -05:00
|
|
|
service = d.GetService(c, "test")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 2)
|
|
|
|
c.Assert(service.Spec.Labels["foo2"], checker.Equals, "bar")
|
|
|
|
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "test", "--label-rm", "foo2")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-12-09 04:17:53 -05:00
|
|
|
service = d.GetService(c, "test")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
|
|
|
c.Assert(service.Spec.Labels["foo2"], checker.Equals, "")
|
|
|
|
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "test", "--label-rm", "foo")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-12-09 04:17:53 -05:00
|
|
|
service = d.GetService(c, "test")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 0)
|
|
|
|
c.Assert(service.Spec.Labels["foo"], checker.Equals, "")
|
|
|
|
|
|
|
|
// now make sure we can add again
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "test", "--label-add", "foo=bar")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-12-09 04:17:53 -05:00
|
|
|
service = d.GetService(c, "test")
|
2016-07-25 15:54:38 -04:00
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
|
|
|
c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar")
|
|
|
|
}
|
2016-10-31 15:38:00 -04:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceUpdateSecrets(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
testName := "test_secret"
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
2017-03-20 04:27:51 -04:00
|
|
|
Annotations: swarm.Annotations{
|
2016-10-31 15:38:00 -04:00
|
|
|
Name: testName,
|
|
|
|
},
|
2017-03-20 04:27:51 -04:00
|
|
|
Data: []byte("TESTINGDATA"),
|
2016-10-31 15:38:00 -04:00
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
testTarget := "testing"
|
|
|
|
serviceName := "test"
|
|
|
|
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "busybox", "top")
|
2016-10-31 15:38:00 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
// add secret
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "test", "--secret-add", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
2016-10-31 15:38:00 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.SecretReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(refs[0].SecretName, checker.Equals, testName)
|
2016-11-15 10:04:36 -05:00
|
|
|
c.Assert(refs[0].File, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(refs[0].File.Name, checker.Equals, testTarget)
|
2016-10-31 15:38:00 -04:00
|
|
|
|
|
|
|
// remove
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "test", "--secret-rm", testName)
|
2016-10-31 15:38:00 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 0)
|
|
|
|
}
|
2017-04-03 20:59:09 -04:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceUpdateConfigs(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
testName := "test_config"
|
|
|
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
testTarget := "/testing"
|
|
|
|
serviceName := "test"
|
|
|
|
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "busybox", "top")
|
2017-04-03 20:59:09 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
// add config
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "test", "--config-add", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
2017-04-03 20:59:09 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.ConfigReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(refs[0].ConfigName, checker.Equals, testName)
|
|
|
|
c.Assert(refs[0].File, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(refs[0].File.Name, checker.Equals, testTarget)
|
|
|
|
|
|
|
|
// remove
|
2017-09-27 19:17:55 -04:00
|
|
|
out, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "test", "--config-rm", testName)
|
2017-04-03 20:59:09 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 0)
|
|
|
|
}
|