mirror of https://github.com/docker/docker-py.git
Add unlock methods to Swarm model
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
aa3c4f026d
commit
3bd053a4b7
|
@ -29,6 +29,10 @@ class Swarm(Model):
|
|||
"""
|
||||
return self.attrs.get('Version').get('Index')
|
||||
|
||||
def get_unlock_key(self):
|
||||
return self.client.api.get_unlock_key()
|
||||
get_unlock_key.__doc__ = APIClient.get_unlock_key.__doc__
|
||||
|
||||
def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
|
||||
force_new_cluster=False, **kwargs):
|
||||
"""
|
||||
|
@ -128,6 +132,10 @@ class Swarm(Model):
|
|||
"""
|
||||
self.attrs = self.client.api.inspect_swarm()
|
||||
|
||||
def unlock(self, key):
|
||||
return self.client.api.unlock_swarm(key)
|
||||
unlock.__doc__ = APIClient.unlock_swarm.__doc__
|
||||
|
||||
def update(self, rotate_worker_token=False, rotate_manager_token=False,
|
||||
**kwargs):
|
||||
"""
|
||||
|
|
|
@ -12,9 +12,11 @@ These methods are available on ``client.swarm``:
|
|||
.. rst-class:: hide-signature
|
||||
.. py:class:: Swarm
|
||||
|
||||
.. automethod:: get_unlock_key()
|
||||
.. automethod:: init()
|
||||
.. automethod:: join()
|
||||
.. automethod:: leave()
|
||||
.. automethod:: unlock()
|
||||
.. automethod:: update()
|
||||
.. automethod:: reload()
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@ class SwarmTest(BaseAPIIntegrationTest):
|
|||
def setUp(self):
|
||||
super(SwarmTest, self).setUp()
|
||||
force_leave_swarm(self.client)
|
||||
self._unlock_key = None
|
||||
|
||||
def tearDown(self):
|
||||
super(SwarmTest, self).tearDown()
|
||||
try:
|
||||
unlock_key = self.client.get_unlock_key()
|
||||
if unlock_key.get('UnlockKey'):
|
||||
self.unlock_swarm(unlock_key)
|
||||
if self._unlock_key:
|
||||
self.client.unlock_swarm(self._unlock_key)
|
||||
except docker.errors.APIError:
|
||||
pass
|
||||
|
||||
|
@ -71,14 +71,15 @@ class SwarmTest(BaseAPIIntegrationTest):
|
|||
def test_init_swarm_with_autolock_managers(self):
|
||||
spec = self.client.create_swarm_spec(autolock_managers=True)
|
||||
assert self.init_swarm(swarm_spec=spec)
|
||||
# save unlock key for tearDown
|
||||
self._unlock_key = self.client.get_unlock_key()
|
||||
swarm_info = self.client.inspect_swarm()
|
||||
|
||||
assert (
|
||||
swarm_info['Spec']['EncryptionConfig']['AutoLockManagers'] is True
|
||||
)
|
||||
|
||||
unlock_key = self.get_unlock_key()
|
||||
assert unlock_key.get('UnlockKey')
|
||||
assert self._unlock_key.get('UnlockKey')
|
||||
|
||||
@requires_api_version('1.25')
|
||||
@pytest.mark.xfail(
|
||||
|
|
Loading…
Reference in New Issue