Change wait_for_provisioning to return Instance objects
Change-Id: Iea7aece885a5ea4c42000c0d220060a102db03c8
This commit is contained in:
parent
5cfaf5566d
commit
ef7521e294
|
@ -251,13 +251,14 @@ class Provisioner(object):
|
|||
LOG.debug('Waiting for node %(node)s to reach state active '
|
||||
'with timeout %(timeout)s',
|
||||
{'node': _utils.log_node(node), 'timeout': wait})
|
||||
node = self.wait_for_provisioning([node], timeout=wait)[0]
|
||||
instance = self.wait_for_provisioning([node], timeout=wait)[0]
|
||||
LOG.info('Deploy succeeded on node %s', _utils.log_node(node))
|
||||
else:
|
||||
# Update the node to return it's latest state
|
||||
node = self._api.get_node(node, refresh=True)
|
||||
instance = _instance.Instance(self._api, node)
|
||||
|
||||
return _instance.Instance(self._api, node)
|
||||
return instance
|
||||
|
||||
def _get_nics(self, nics):
|
||||
"""Validate and get the NICs."""
|
||||
|
@ -358,12 +359,14 @@ class Provisioner(object):
|
|||
to finish provisioning. If ``None`` (the default), wait forever
|
||||
(more precisely, until the operation times out on server side).
|
||||
:param delay: Delay (in seconds) between two provision state checks.
|
||||
:return: List of updated nodes if all succeeded.
|
||||
:return: List of updated :py:class:`metalsmith.Instance` objects if
|
||||
all succeeded.
|
||||
:raises: :py:class:`metalsmith.exceptions.DeploymentFailure`
|
||||
if the deployment failed or timed out for any nodes.
|
||||
"""
|
||||
return self._wait_for_state(nodes, 'active',
|
||||
timeout=timeout, delay=delay)
|
||||
nodes = self._wait_for_state(nodes, 'active',
|
||||
timeout=timeout, delay=delay)
|
||||
return [_instance.Instance(self._api, node) for node in nodes]
|
||||
|
||||
def _wait_for_state(self, nodes, state, timeout, delay=15):
|
||||
if timeout is not None and timeout <= 0:
|
||||
|
|
|
@ -119,6 +119,7 @@ class TestProvisionNode(Base):
|
|||
fixtures.MockPatchObject(_provisioner.Provisioner,
|
||||
'_wait_for_state', autospec=True))
|
||||
self.wait_mock = self.wait_fixture.mock
|
||||
self.wait_mock.side_effect = lambda self, nodes, *a, **kw: nodes
|
||||
|
||||
def test_ok(self):
|
||||
inst = self.pr.provision_node(self.node, 'image',
|
||||
|
@ -696,7 +697,8 @@ class TestWaitForState(Base):
|
|||
self.api.get_node.side_effect = nodes
|
||||
|
||||
result = self.pr.wait_for_provisioning(['uuid1'])
|
||||
self.assertEqual(nodes[-1:], result)
|
||||
self.assertEqual(nodes[-1:], [inst.node for inst in result])
|
||||
self.assertIsInstance(result[0], _instance.Instance)
|
||||
|
||||
mock_sleep.assert_called_with(15)
|
||||
self.assertEqual(3, mock_sleep.call_count)
|
||||
|
@ -711,7 +713,9 @@ class TestWaitForState(Base):
|
|||
self.api.get_node.side_effect = nodes
|
||||
|
||||
result = self.pr.wait_for_provisioning(['uuid1', 'uuid2'])
|
||||
self.assertEqual(nodes[-2:], result)
|
||||
self.assertEqual(nodes[-2:], [inst.node for inst in result])
|
||||
for inst in result:
|
||||
self.assertIsInstance(inst, _instance.Instance)
|
||||
|
||||
mock_sleep.assert_called_with(15)
|
||||
self.assertEqual(2, mock_sleep.call_count)
|
||||
|
@ -758,7 +762,8 @@ class TestWaitForState(Base):
|
|||
self.api.get_node.side_effect = nodes
|
||||
|
||||
result = self.pr.wait_for_provisioning(['uuid1'], delay=1)
|
||||
self.assertEqual(nodes[-1:], result)
|
||||
self.assertEqual(nodes[-1:], [inst.node for inst in result])
|
||||
self.assertIsInstance(result[0], _instance.Instance)
|
||||
|
||||
mock_sleep.assert_called_with(1)
|
||||
self.assertEqual(3, mock_sleep.call_count)
|
||||
|
|
Loading…
Reference in New Issue