Skip to content

Commit 452707f

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

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def setUp(self):
1414
def tearDown(self):
1515
super(SwarmTest, self).tearDown()
1616
try:
17-
unlock_key = self.client.get_unlock_key()
18-
if unlock_key.get('UnlockKey'):
19-
self.unlock_swarm(unlock_key)
17+
if self._unlock_key:
18+
unlock_key = self._unlock_key
19+
self._unlock_key = None
20+
self.client.unlock_swarm(unlock_key)
2021
except docker.errors.APIError:
2122
pass
2223

@@ -71,14 +72,15 @@ def test_init_swarm_with_ca_config(self):
7172
def test_init_swarm_with_autolock_managers(self):
7273
spec = self.client.create_swarm_spec(autolock_managers=True)
7374
assert self.init_swarm(swarm_spec=spec)
75+
# save unlock key for tearDown
76+
self._unlock_key = self.client.get_unlock_key()
7477
swarm_info = self.client.inspect_swarm()
7578

7679
assert (
7780
swarm_info['Spec']['EncryptionConfig']['AutoLockManagers'] is True
7881
)
7982

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

8385
@requires_api_version('1.25')
8486
@pytest.mark.xfail(

0 commit comments

Comments
 (0)