Skip to content

Commit 710b9d9

Browse files
committed
dnet client update for -force unpublish and Integration Tests
Signed-off-by: Madhu Venugopal <madhu@docker.com>
1 parent 3edcfd3 commit 710b9d9

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

client/service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func (cli *NetworkCli) CmdServicePublish(chain string, args ...string) error {
191191
// CmdServiceUnpublish handles service delete UI
192192
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
193193
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
194+
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
194195
cmd.Require(flag.Exact, 1)
195196
err := cmd.ParseFlags(args, true)
196197
if err != nil {
@@ -203,7 +204,8 @@ func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
203204
return err
204205
}
205206

206-
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, nil, nil))
207+
sd := serviceDelete{Name: sn, Force: *force}
208+
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
207209

208210
return err
209211
}

client/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ type serviceCreate struct {
4949
PortMapping []types.PortBinding `json:"port_mapping"`
5050
}
5151

52+
// serviceDelete represents the body of the "unpublish service" http request message
53+
type serviceDelete struct {
54+
Name string `json:"name"`
55+
Force bool `json:"force"`
56+
}
57+
5258
// serviceAttach represents the expected body of the "attach/detach sandbox to/from service" http request messages
5359
type serviceAttach struct {
5460
SandboxID string `json:"sandbox_id"`

test/integration/dnet/overlay-consul.bats

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,46 @@ load helpers
2525
test_overlay consul skip_add
2626
}
2727

28+
@test "Test overlay network with dnet ungraceful shutdown" {
29+
skip_for_circleci
30+
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
31+
start=1
32+
end=3
33+
for i in `seq ${start} ${end}`;
34+
do
35+
dnet_cmd $(inst_id2port $i) container create container_${i}
36+
net_connect ${i} container_${i} multihost
37+
done
38+
39+
hrun runc $(dnet_container_name 1 consul) $(get_sbox_id 1 container_1) "ifconfig eth0"
40+
container_1_ip=$(echo ${output} | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
41+
42+
# forcefully unpublish the service from dnet2 when dnet1 is alive.
43+
# operation must fail
44+
set +e
45+
dnet_cmd $(inst_id2port 2) service unpublish -f container_1.multihost
46+
status="$?"
47+
set -e
48+
[ "${status}" -ne 0 ]
49+
50+
# ungracefully kill dnet-1-consul container
51+
docker rm -f dnet-1-consul
52+
# sleep for 60 seconds to make sure the discovery catches up
53+
sleep 60
54+
55+
# forcefully unpublish the service from dnet2 when dnet1 is dead.
56+
dnet_cmd $(inst_id2port 2) service unpublish -f container_1.multihost
57+
dnet_cmd $(inst_id2port 2) container create container_1
58+
net_connect 2 container_1 multihost
59+
60+
hrun runc $(dnet_container_name 2 consul) $(get_sbox_id 2 container_1) "ifconfig eth0"
61+
container_1_new_ip=$(echo ${output} | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
62+
63+
if [ "$container_1_ip" != "$container_1_new_ip" ]; then
64+
exit 1
65+
fi
66+
}
67+
2868
@test "Test overlay network internal network with consul" {
2969
skip_for_circleci
3070
test_overlay consul internal

0 commit comments

Comments
 (0)