Skip to content

Commit 3bd053a

Browse files
committed
Add unlock methods to Swarm model
Signed-off-by: Joffrey F <[email protected]>
1 parent aa3c4f0 commit 3bd053a

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

docker/models/swarm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def version(self):
2929
"""
3030
return self.attrs.get('Version').get('Index')
3131

32+
def get_unlock_key(self):
33+
return self.client.api.get_unlock_key()
34+
get_unlock_key.__doc__ = APIClient.get_unlock_key.__doc__
35+
3236
def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
3337
force_new_cluster=False, **kwargs):
3438
"""
@@ -128,6 +132,10 @@ def reload(self):
128132
"""
129133
self.attrs = self.client.api.inspect_swarm()
130134

135+
def unlock(self, key):
136+
return self.client.api.unlock_swarm(key)
137+
unlock.__doc__ = APIClient.unlock_swarm.__doc__
138+
131139
def update(self, rotate_worker_token=False, rotate_manager_token=False,
132140
**kwargs):
133141
"""

docs/swarm.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ These methods are available on ``client.swarm``:
1212
.. rst-class:: hide-signature
1313
.. py:class:: Swarm
1414
15+
.. automethod:: get_unlock_key()
1516
.. automethod:: init()
1617
.. automethod:: join()
1718
.. automethod:: leave()
19+
.. automethod:: unlock()
1820
.. automethod:: update()
1921
.. automethod:: reload()
2022

tests/integration/api_swarm_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class SwarmTest(BaseAPIIntegrationTest):
1010
def setUp(self):
1111
super(SwarmTest, self).setUp()
1212
force_leave_swarm(self.client)
13+
self._unlock_key = None
1314

1415
def tearDown(self):
1516
super(SwarmTest, self).tearDown()
1617
try:
17-
unlock_key = self.client.get_unlock_key()
18-
if unlock_key.get('UnlockKey'):
19-
self.unlock_swarm(unlock_key)
18+
if self._unlock_key:
19+
self.client.unlock_swarm(self._unlock_key)
2020
except docker.errors.APIError:
2121
pass
2222

@@ -71,14 +71,15 @@ def test_init_swarm_with_ca_config(self):
7171
def test_init_swarm_with_autolock_managers(self):
7272
spec = self.client.create_swarm_spec(autolock_managers=True)
7373
assert self.init_swarm(swarm_spec=spec)
74+
# save unlock key for tearDown
75+
self._unlock_key = self.client.get_unlock_key()
7476
swarm_info = self.client.inspect_swarm()
7577

7678
assert (
7779
swarm_info['Spec']['EncryptionConfig']['AutoLockManagers'] is True
7880
)
7981

80-
unlock_key = self.get_unlock_key()
81-
assert unlock_key.get('UnlockKey')
82+
assert self._unlock_key.get('UnlockKey')
8283

8384
@requires_api_version('1.25')
8485
@pytest.mark.xfail(

0 commit comments

Comments
 (0)