dnet client update for -force unpublish and Integration Tests

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2016-01-12 02:53:27 +00:00
parent ec622bf158
commit 02d6721763
3 changed files with 49 additions and 1 deletions

View file

@ -191,6 +191,7 @@ func (cli *NetworkCli) CmdServicePublish(chain string, args ...string) error {
// CmdServiceUnpublish handles service delete UI
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
@ -203,7 +204,8 @@ func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
return err
}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, nil, nil))
sd := serviceDelete{Name: sn, Force: *force}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
return err
}

View file

@ -49,6 +49,12 @@ type serviceCreate struct {
PortMapping []types.PortBinding `json:"port_mapping"`
}
// serviceDelete represents the body of the "unpublish service" http request message
type serviceDelete struct {
Name string `json:"name"`
Force bool `json:"force"`
}
// serviceAttach represents the expected body of the "attach/detach sandbox to/from service" http request messages
type serviceAttach struct {
SandboxID string `json:"sandbox_id"`

View file

@ -25,6 +25,46 @@ load helpers
test_overlay consul skip_add
}
@test "Test overlay network with dnet ungraceful shutdown" {
skip_for_circleci
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
start=1
end=3
for i in `seq ${start} ${end}`;
do
dnet_cmd $(inst_id2port $i) container create container_${i}
net_connect ${i} container_${i} multihost
done
hrun runc $(dnet_container_name 1 consul) $(get_sbox_id 1 container_1) "ifconfig eth0"
container_1_ip=$(echo ${output} | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
# forcefully unpublish the service from dnet2 when dnet1 is alive.
# operation must fail
set +e
dnet_cmd $(inst_id2port 2) service unpublish -f container_1.multihost
status="$?"
set -e
[ "${status}" -ne 0 ]
# ungracefully kill dnet-1-consul container
docker rm -f dnet-1-consul
# sleep for 60 seconds to make sure the discovery catches up
sleep 60
# forcefully unpublish the service from dnet2 when dnet1 is dead.
dnet_cmd $(inst_id2port 2) service unpublish -f container_1.multihost
dnet_cmd $(inst_id2port 2) container create container_1
net_connect 2 container_1 multihost
hrun runc $(dnet_container_name 2 consul) $(get_sbox_id 2 container_1) "ifconfig eth0"
container_1_new_ip=$(echo ${output} | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
if [ "$container_1_ip" != "$container_1_new_ip" ]; then
exit 1
fi
}
@test "Test overlay network internal network with consul" {
skip_for_circleci
test_overlay consul internal