Merge "Ironic: Call unprovison for nodes in DEPLOYING state"
This commit is contained in:
commit
e68db1157a
|
@ -1135,12 +1135,12 @@ class IronicDriverTestCase(test.NoDBTestCase):
|
||||||
|
|
||||||
@mock.patch.object(FAKE_CLIENT, 'node')
|
@mock.patch.object(FAKE_CLIENT, 'node')
|
||||||
@mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy')
|
@mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy')
|
||||||
def test_destroy(self, mock_cleanup_deploy, mock_node):
|
def _test_destroy(self, state, mock_cleanup_deploy, mock_node):
|
||||||
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
||||||
network_info = 'foo'
|
network_info = 'foo'
|
||||||
|
|
||||||
node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid,
|
node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid,
|
||||||
provision_state=ironic_states.ACTIVE)
|
provision_state=state)
|
||||||
instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
|
instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
|
||||||
|
|
||||||
def fake_set_provision_state(*_):
|
def fake_set_provision_state(*_):
|
||||||
|
@ -1149,54 +1149,22 @@ class IronicDriverTestCase(test.NoDBTestCase):
|
||||||
mock_node.get_by_instance_uuid.return_value = node
|
mock_node.get_by_instance_uuid.return_value = node
|
||||||
mock_node.set_provision_state.side_effect = fake_set_provision_state
|
mock_node.set_provision_state.side_effect = fake_set_provision_state
|
||||||
self.driver.destroy(self.ctx, instance, network_info, None)
|
self.driver.destroy(self.ctx, instance, network_info, None)
|
||||||
mock_node.set_provision_state.assert_called_once_with(node_uuid,
|
|
||||||
'deleted')
|
|
||||||
mock_node.get_by_instance_uuid.assert_called_with(instance.uuid)
|
mock_node.get_by_instance_uuid.assert_called_with(instance.uuid)
|
||||||
mock_cleanup_deploy.assert_called_with(self.ctx, node,
|
mock_cleanup_deploy.assert_called_with(self.ctx, node,
|
||||||
instance, network_info)
|
instance, network_info)
|
||||||
|
|
||||||
@mock.patch.object(FAKE_CLIENT, 'node')
|
# For states that makes sense check if set_provision_state has
|
||||||
@mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy')
|
# been called
|
||||||
def test_destroy_ignore_unexpected_state(self, mock_cleanup_deploy,
|
if state in ironic_driver._UNPROVISION_STATES:
|
||||||
mock_node):
|
mock_node.set_provision_state.assert_called_once_with(
|
||||||
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
node_uuid, 'deleted')
|
||||||
network_info = 'foo'
|
else:
|
||||||
|
self.assertFalse(mock_node.set_provision_state.called)
|
||||||
|
|
||||||
node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid,
|
def test_destroy(self):
|
||||||
provision_state=ironic_states.DELETING)
|
for state in ironic_states.PROVISION_STATE_LIST:
|
||||||
instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
|
self._test_destroy(state)
|
||||||
|
|
||||||
mock_node.get_by_instance_uuid.return_value = node
|
|
||||||
self.driver.destroy(self.ctx, instance, network_info, None)
|
|
||||||
self.assertFalse(mock_node.set_provision_state.called)
|
|
||||||
mock_node.get_by_instance_uuid.assert_called_with(instance.uuid)
|
|
||||||
mock_cleanup_deploy.assert_called_with(self.ctx, node, instance,
|
|
||||||
network_info)
|
|
||||||
|
|
||||||
@mock.patch.object(FAKE_CLIENT, 'node')
|
|
||||||
@mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy')
|
|
||||||
def _test_destroy_cleaning(self, mock_cleanup_deploy, mock_node,
|
|
||||||
state=None):
|
|
||||||
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
|
||||||
network_info = 'foo'
|
|
||||||
|
|
||||||
node = ironic_utils.get_test_node(
|
|
||||||
driver='fake', uuid=node_uuid,
|
|
||||||
provision_state=state)
|
|
||||||
instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
|
|
||||||
|
|
||||||
mock_node.get_by_instance_uuid.return_value = node
|
|
||||||
self.driver.destroy(self.ctx, instance, network_info, None)
|
|
||||||
self.assertFalse(mock_node.set_provision_state.called)
|
|
||||||
mock_node.get_by_instance_uuid.assert_called_with(instance.uuid)
|
|
||||||
mock_cleanup_deploy.assert_called_with(self.ctx, node, instance,
|
|
||||||
network_info)
|
|
||||||
|
|
||||||
def test_destroy_cleaning(self):
|
|
||||||
self._test_destroy_cleaning(state=ironic_states.CLEANING)
|
|
||||||
|
|
||||||
def test_destroy_cleanwait(self):
|
|
||||||
self._test_destroy_cleaning(state=ironic_states.CLEANWAIT)
|
|
||||||
|
|
||||||
@mock.patch.object(FAKE_CLIENT.node, 'set_provision_state')
|
@mock.patch.object(FAKE_CLIENT.node, 'set_provision_state')
|
||||||
@mock.patch.object(ironic_driver, '_validate_instance_and_node')
|
@mock.patch.object(ironic_driver, '_validate_instance_and_node')
|
||||||
|
|
|
@ -112,6 +112,10 @@ _POWER_STATE_MAP = {
|
||||||
ironic_states.POWER_OFF: power_state.SHUTDOWN,
|
ironic_states.POWER_OFF: power_state.SHUTDOWN,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_UNPROVISION_STATES = (ironic_states.ACTIVE, ironic_states.DEPLOYFAIL,
|
||||||
|
ironic_states.ERROR, ironic_states.DEPLOYWAIT,
|
||||||
|
ironic_states.DEPLOYING)
|
||||||
|
|
||||||
|
|
||||||
def map_power_state(state):
|
def map_power_state(state):
|
||||||
try:
|
try:
|
||||||
|
@ -902,10 +906,7 @@ class IronicDriver(virt_driver.ComputeDriver):
|
||||||
# without raising any exceptions.
|
# without raising any exceptions.
|
||||||
return
|
return
|
||||||
|
|
||||||
if node.provision_state in (ironic_states.ACTIVE,
|
if node.provision_state in _UNPROVISION_STATES:
|
||||||
ironic_states.DEPLOYFAIL,
|
|
||||||
ironic_states.ERROR,
|
|
||||||
ironic_states.DEPLOYWAIT):
|
|
||||||
self._unprovision(self.ironicclient, instance, node)
|
self._unprovision(self.ironicclient, instance, node)
|
||||||
|
|
||||||
self._cleanup_deploy(context, node, instance, network_info)
|
self._cleanup_deploy(context, node, instance, network_info)
|
||||||
|
|
|
@ -128,7 +128,6 @@ This is the provision state used when inspection is started. A successfully
|
||||||
inspected node shall transition to MANAGEABLE status.
|
inspected node shall transition to MANAGEABLE status.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
INSPECTFAIL = 'inspect failed'
|
INSPECTFAIL = 'inspect failed'
|
||||||
""" Node inspection failed. """
|
""" Node inspection failed. """
|
||||||
|
|
||||||
|
@ -145,3 +144,13 @@ POWER_OFF = 'power off'
|
||||||
|
|
||||||
REBOOT = 'rebooting'
|
REBOOT = 'rebooting'
|
||||||
""" Node is rebooting. """
|
""" Node is rebooting. """
|
||||||
|
|
||||||
|
##################
|
||||||
|
# Helper constants
|
||||||
|
##################
|
||||||
|
|
||||||
|
PROVISION_STATE_LIST = (NOSTATE, MANAGEABLE, AVAILABLE, ACTIVE, DEPLOYWAIT,
|
||||||
|
DEPLOYING, DEPLOYFAIL, DEPLOYDONE, DELETING, DELETED,
|
||||||
|
CLEANING, CLEANWAIT, CLEANFAIL, ERROR, REBUILD,
|
||||||
|
INSPECTING, INSPECTFAIL)
|
||||||
|
""" A list of all provision states. """
|
||||||
|
|
Loading…
Reference in New Issue