From 02d67217637b30917842611c67dfb914abe837f3 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Tue, 12 Jan 2016 02:53:27 +0000 Subject: [PATCH] dnet client update for -force unpublish and Integration Tests Signed-off-by: Madhu Venugopal --- libnetwork/client/service.go | 4 +- libnetwork/client/types.go | 6 +++ .../test/integration/dnet/overlay-consul.bats | 40 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/libnetwork/client/service.go b/libnetwork/client/service.go index fb70228485..77b0e63609 100644 --- a/libnetwork/client/service.go +++ b/libnetwork/client/service.go @@ -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 } diff --git a/libnetwork/client/types.go b/libnetwork/client/types.go index 1337d60efc..64e52a7e1a 100644 --- a/libnetwork/client/types.go +++ b/libnetwork/client/types.go @@ -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"` diff --git a/libnetwork/test/integration/dnet/overlay-consul.bats b/libnetwork/test/integration/dnet/overlay-consul.bats index f8c2cdd3bd..df0473b115 100644 --- a/libnetwork/test/integration/dnet/overlay-consul.bats +++ b/libnetwork/test/integration/dnet/overlay-consul.bats @@ -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