From acd7a8f43056007d8ae5df3d8156c34b837d97b1 Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Thu, 28 Mar 2019 10:48:22 +0100 Subject: [PATCH] Return node id on swarm init Signed-off-by: Hannes Ljungberg --- docker/api/swarm.py | 5 ++--- docker/models/swarm.py | 6 +++--- tests/integration/api_swarm_test.py | 4 +++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docker/api/swarm.py b/docker/api/swarm.py index bab91ee4..ea4c1e71 100644 --- a/docker/api/swarm.py +++ b/docker/api/swarm.py @@ -117,7 +117,7 @@ class SwarmApiMixin(object): networks created from the default subnet pool. Default: None Returns: - ``True`` if successful. + (str): The ID of the created node. Raises: :py:class:`docker.errors.APIError` @@ -155,8 +155,7 @@ class SwarmApiMixin(object): 'Spec': swarm_spec, } response = self._post_json(url, data=data) - self._raise_for_status(response) - return True + return self._result(response, json=True) @utils.minimum_version('1.24') def inspect_swarm(self): diff --git a/docker/models/swarm.py b/docker/models/swarm.py index cb27467d..f78e8e16 100644 --- a/docker/models/swarm.py +++ b/docker/models/swarm.py @@ -96,7 +96,7 @@ class Swarm(Model): created in the orchestrator. Returns: - ``True`` if the request went through. + (str): The ID of the created node. Raises: :py:class:`docker.errors.APIError` @@ -120,9 +120,9 @@ class Swarm(Model): 'subnet_size': subnet_size } init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs) - self.client.api.init_swarm(**init_kwargs) + node_id = self.client.api.init_swarm(**init_kwargs) self.reload() - return True + return node_id def join(self, *args, **kwargs): return self.client.api.join_swarm(*args, **kwargs) diff --git a/tests/integration/api_swarm_test.py b/tests/integration/api_swarm_test.py index 37f5fa79..94ab2a63 100644 --- a/tests/integration/api_swarm_test.py +++ b/tests/integration/api_swarm_test.py @@ -186,12 +186,14 @@ class SwarmTest(BaseAPIIntegrationTest): @requires_api_version('1.24') def test_inspect_node(self): - assert self.init_swarm() + node_id = self.init_swarm() + assert node_id nodes_list = self.client.nodes() assert len(nodes_list) == 1 node = nodes_list[0] node_data = self.client.inspect_node(node['ID']) assert node['ID'] == node_data['ID'] + assert node_id == node['ID'] assert node['Version'] == node_data['Version'] @requires_api_version('1.24')