Merge pull request #2296 from hannseman/swarm-init-response

Return node id on swarm init
This commit is contained in:
Joffrey F 2019-05-01 02:29:30 -07:00 committed by GitHub
commit 4d62dd0a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -120,7 +120,7 @@ class SwarmApiMixin(object):
traffic. For example, 192.168.1.1, or an interface, like eth0. traffic. For example, 192.168.1.1, or an interface, like eth0.
Returns: Returns:
``True`` if successful. (str): The ID of the created node.
Raises: Raises:
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
@ -167,8 +167,7 @@ class SwarmApiMixin(object):
data['DataPathAddr'] = data_path_addr data['DataPathAddr'] = data_path_addr
response = self._post_json(url, data=data) response = self._post_json(url, data=data)
self._raise_for_status(response) return self._result(response, json=True)
return True
@utils.minimum_version('1.24') @utils.minimum_version('1.24')
def inspect_swarm(self): def inspect_swarm(self):

View File

@ -98,7 +98,7 @@ class Swarm(Model):
created in the orchestrator. created in the orchestrator.
Returns: Returns:
``True`` if the request went through. (str): The ID of the created node.
Raises: Raises:
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
@ -123,9 +123,9 @@ class Swarm(Model):
'data_path_addr': data_path_addr, 'data_path_addr': data_path_addr,
} }
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs) 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() self.reload()
return True return node_id
def join(self, *args, **kwargs): def join(self, *args, **kwargs):
return self.client.api.join_swarm(*args, **kwargs) return self.client.api.join_swarm(*args, **kwargs)

View File

@ -186,12 +186,14 @@ class SwarmTest(BaseAPIIntegrationTest):
@requires_api_version('1.24') @requires_api_version('1.24')
def test_inspect_node(self): def test_inspect_node(self):
assert self.init_swarm() node_id = self.init_swarm()
assert node_id
nodes_list = self.client.nodes() nodes_list = self.client.nodes()
assert len(nodes_list) == 1 assert len(nodes_list) == 1
node = nodes_list[0] node = nodes_list[0]
node_data = self.client.inspect_node(node['ID']) node_data = self.client.inspect_node(node['ID'])
assert node['ID'] == node_data['ID'] assert node['ID'] == node_data['ID']
assert node_id == node['ID']
assert node['Version'] == node_data['Version'] assert node['Version'] == node_data['Version']
@requires_api_version('1.24') @requires_api_version('1.24')