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-06-17 19:24:07 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceUpdatePort(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
serviceName := "TestServiceUpdatePort"
|
2016-08-17 18:46:28 -04:00
|
|
|
serviceArgs := append([]string{"service", "create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, sleepCommandForDaemonPlatform()...)
|
2016-06-17 19:24:07 -04:00
|
|
|
|
|
|
|
// Create a service with a port mapping of 8080:8081.
|
2016-07-22 12:14:05 -04:00
|
|
|
out, err := d.Cmd(serviceArgs...)
|
2016-06-17 19:24:07 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
|
|
|
|
|
|
|
|
// Update the service: changed the port mapping from 8080:8081 to 8082:8083.
|
2016-06-29 12:28:33 -04:00
|
|
|
_, err = d.Cmd("service", "update", "--publish-add", "8082:8083", "--publish-rm", "8081", serviceName)
|
2016-06-17 19:24:07 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// Inspect the service and verify port mapping
|
|
|
|
expected := []swarm.PortConfig{
|
|
|
|
{
|
|
|
|
Protocol: "tcp",
|
|
|
|
PublishedPort: 8082,
|
|
|
|
TargetPort: 8083,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.EndpointSpec.Ports }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var portConfig []swarm.PortConfig
|
|
|
|
if err := json.Unmarshal([]byte(out), &portConfig); err != nil {
|
|
|
|
c.Fatalf("invalid JSON in inspect result: %v (%s)", err, out)
|
|
|
|
}
|
|
|
|
c.Assert(portConfig, checker.DeepEquals, expected)
|
|
|
|
}
|
2016-07-25 15:54:38 -04:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceUpdateLabel(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
out, err := d.Cmd("service", "create", "--name=test", "busybox", "top")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
service := d.getService(c, "test")
|
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 0)
|
|
|
|
|
|
|
|
// add label to empty set
|
|
|
|
out, err = d.Cmd("service", "update", "test", "--label-add", "foo=bar")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
service = d.getService(c, "test")
|
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
|
|
|
c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar")
|
|
|
|
|
|
|
|
// add label to non-empty set
|
|
|
|
out, err = d.Cmd("service", "update", "test", "--label-add", "foo2=bar")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
service = d.getService(c, "test")
|
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 2)
|
|
|
|
c.Assert(service.Spec.Labels["foo2"], checker.Equals, "bar")
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "update", "test", "--label-rm", "foo2")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
service = d.getService(c, "test")
|
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
|
|
|
c.Assert(service.Spec.Labels["foo2"], checker.Equals, "")
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "update", "test", "--label-rm", "foo")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
service = d.getService(c, "test")
|
|
|
|
c.Assert(service.Spec.Labels, checker.HasLen, 0)
|
|
|
|
c.Assert(service.Spec.Labels["foo"], checker.Equals, "")
|
|
|
|
|
|
|
|
// now make sure we can add again
|
|
|
|
out, err = d.Cmd("service", "update", "test", "--label-add", "foo=bar")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
service = d.getService(c, "test")
|
|
|
|
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"
|
|
|
|
id := d.createSecret(c, swarm.SecretSpec{
|
|
|
|
swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
[]byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
testTarget := "testing"
|
|
|
|
serviceName := "test"
|
|
|
|
|
|
|
|
out, err := d.Cmd("service", "create", "--name", serviceName, "busybox", "top")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
// add secret
|
2016-11-01 22:28:32 -04:00
|
|
|
out, err = d.Cmd("service", "update", "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-01 18:59:16 -04:00
|
|
|
c.Assert(refs[0].Target, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(refs[0].Target.Name, checker.Equals, testTarget)
|
2016-10-31 15:38:00 -04:00
|
|
|
|
|
|
|
// remove
|
|
|
|
out, err = d.Cmd("service", "update", "test", "--secret-rm", testName)
|
|
|
|
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)
|
|
|
|
}
|