Skip to content

Commit bdec585

Browse files
author
Maxime Belanger
committed
Add join_swarm default listen address
Since the docker CLI adds a default listen address (0.0.0.0:2377) when joining a node to the swarm, the docker-py api will support the same behavior. Signed-off-by: Maxime Belanger <maxime.b.belanger@gmail.com>
1 parent 8919514 commit bdec585

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

docker/api/swarm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def inspect_node(self, node_id):
137137
return self._result(self._get(url), True)
138138

139139
@utils.minimum_version('1.24')
140-
def join_swarm(self, remote_addrs, join_token, listen_addr=None,
140+
def join_swarm(self, remote_addrs, join_token, listen_addr='0.0.0.0:2377',
141141
advertise_addr=None):
142142
"""
143143
Make this Engine join a swarm that has already been created.

tests/unit/fake_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ def post_fake_update_node():
435435
return 200, None
436436

437437

438+
def post_fake_join_swarm():
439+
return 200, None
440+
441+
438442
def get_fake_network_list():
439443
return 200, [{
440444
"Name": "bridge",
@@ -599,6 +603,8 @@ def post_fake_network_disconnect():
599603
CURRENT_VERSION, prefix, FAKE_NODE_ID
600604
), 'POST'):
601605
post_fake_update_node,
606+
('{1}/{0}/swarm/join'.format(CURRENT_VERSION, prefix), 'POST'):
607+
post_fake_join_swarm,
602608
('{1}/{0}/networks'.format(CURRENT_VERSION, prefix), 'GET'):
603609
get_fake_network_list,
604610
('{1}/{0}/networks/create'.format(CURRENT_VERSION, prefix), 'POST'):

tests/unit/swarm_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,42 @@ def test_node_update(self):
3030
self.assertEqual(
3131
args[1]['headers']['Content-Type'], 'application/json'
3232
)
33+
34+
@requires_api_version('1.24')
35+
def test_join_swarm(self):
36+
remote_addr = ['1.2.3.4:2377']
37+
listen_addr = '2.3.4.5:2377'
38+
join_token = 'A_BEAUTIFUL_JOIN_TOKEN'
39+
40+
data = {
41+
'RemoteAddrs': remote_addr,
42+
'ListenAddr': listen_addr,
43+
'JoinToken': join_token
44+
}
45+
46+
self.client.join_swarm(remote_addrs=remote_addr, listen_addr=listen_addr, join_token=join_token)
47+
48+
args = fake_request.call_args
49+
50+
assert (args[0][1] == url_prefix + 'swarm/join')
51+
assert (json.loads(args[1]['data']) == data)
52+
assert (args[1]['headers']['Content-Type'] == 'application/json')
53+
54+
@requires_api_version('1.24')
55+
def test_join_swarm_no_listen_address_takes_default(self):
56+
remote_addr = ['1.2.3.4:2377']
57+
join_token = 'A_BEAUTIFUL_JOIN_TOKEN'
58+
59+
data = {
60+
'RemoteAddrs': remote_addr,
61+
'ListenAddr': '0.0.0.0:2377',
62+
'JoinToken': join_token
63+
}
64+
65+
self.client.join_swarm(remote_addrs=remote_addr, join_token=join_token)
66+
67+
args = fake_request.call_args
68+
69+
assert (args[0][1] == url_prefix + 'swarm/join')
70+
assert (json.loads(args[1]['data']) == data)
71+
assert (args[1]['headers']['Content-Type'] == 'application/json')

0 commit comments

Comments
 (0)