2016-06-17 19:24:07 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
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-12-09 04:17:53 -05:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2016-06-17 19:24:07 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setPortConfig(portConfig []swarm.PortConfig) daemon.ServiceConstructor {
|
2016-06-17 19:24:07 -04:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
if s.Spec.EndpointSpec == nil {
|
|
|
|
s.Spec.EndpointSpec = &swarm.EndpointSpec{}
|
|
|
|
}
|
|
|
|
s.Spec.EndpointSpec.Ports = portConfig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *check.C) {
|
2016-06-17 19:24:07 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
// Create a service with a port mapping of 8080:8081.
|
|
|
|
portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}}
|
2016-12-09 04:17:53 -05:00
|
|
|
serviceID := d.CreateService(c, simpleTestService, setInstances(1), setPortConfig(portConfig))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-17 19:24:07 -04:00
|
|
|
|
|
|
|
// Update the service: changed the port mapping from 8080:8081 to 8082:8083.
|
|
|
|
updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}}
|
2016-12-09 04:17:53 -05:00
|
|
|
remoteService := d.GetService(c, serviceID)
|
|
|
|
d.UpdateService(c, remoteService, setPortConfig(updatedPortConfig))
|
2016-06-17 19:24:07 -04:00
|
|
|
|
|
|
|
// Inspect the service and verify port mapping.
|
2016-12-09 04:17:53 -05:00
|
|
|
updatedService := d.GetService(c, serviceID)
|
2016-06-17 19:24:07 -04:00
|
|
|
c.Assert(updatedService.Spec.EndpointSpec, check.NotNil)
|
|
|
|
c.Assert(len(updatedService.Spec.EndpointSpec.Ports), check.Equals, 1)
|
|
|
|
c.Assert(updatedService.Spec.EndpointSpec.Ports[0].TargetPort, check.Equals, uint32(8083))
|
|
|
|
c.Assert(updatedService.Spec.EndpointSpec.Ports[0].PublishedPort, check.Equals, uint32(8082))
|
|
|
|
}
|