Instance destroyed if ironic node in CLEANWAIT

Ironic added a new state 'CLEANWAIT' so nodes that previously had their
provision state as CLEANING will now be in either CLEANING or CLEANWAIT.

This patch updates the ironic driver so that it knows about the CLEANWAIT
state. In particular, when destroying an instance, from nova's perspective,
the instance has been removed if a node is in CLEANWAIT state.

Change-Id: Ib42142d67cf2a640a03ec87cbd5fcc0bfdbeb51f
Closes-Bug: #1479532
This commit is contained in:
Ruby Loo 2015-07-29 21:57:04 +00:00
parent 5eddd50537
commit d4ee706323
3 changed files with 29 additions and 4 deletions

View File

@ -586,6 +586,10 @@ class IronicDriverTestCase(test.NoDBTestCase):
{'uuid': uuidutils.generate_uuid(),
'power_state': ironic_states.POWER_ON,
'provision_state': ironic_states.CLEANING},
# a node in cleaning, waiting for a clean step to finish
{'uuid': uuidutils.generate_uuid(),
'power_state': ironic_states.POWER_ON,
'provision_state': ironic_states.CLEANWAIT},
# a node in deleting
{'uuid': uuidutils.generate_uuid(),
'power_state': ironic_states.POWER_ON,
@ -1120,13 +1124,14 @@ class IronicDriverTestCase(test.NoDBTestCase):
@mock.patch.object(FAKE_CLIENT, 'node')
@mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy')
def test_destroy_cleaning(self, mock_cleanup_deploy, mock_node):
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=ironic_states.CLEANING)
provision_state=state)
instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
mock_node.get_by_instance_uuid.return_value = node
@ -1136,6 +1141,12 @@ class IronicDriverTestCase(test.NoDBTestCase):
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(ironic_driver, '_validate_instance_and_node')
def test_destroy_trigger_undeploy_fail(self, fake_validate, mock_sps):
@ -1150,11 +1161,11 @@ class IronicDriverTestCase(test.NoDBTestCase):
self.ctx, instance, None, None)
@mock.patch.object(ironic_driver, '_validate_instance_and_node')
def test__unprovision_instance(self, mock_validate_inst):
def _test__unprovision_instance(self, mock_validate_inst, state=None):
fake_ironic_client = mock.Mock()
node = ironic_utils.get_test_node(
driver='fake',
provision_state=ironic_states.CLEANING)
provision_state=state)
instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid)
mock_validate_inst.return_value = node
self.driver._unprovision(fake_ironic_client, instance, node)
@ -1163,6 +1174,12 @@ class IronicDriverTestCase(test.NoDBTestCase):
fake_ironic_client.call.assert_called_once_with(
"node.set_provision_state", node.uuid, "deleted")
def test__unprovision_cleaning(self):
self._test__unprovision_instance(state=ironic_states.CLEANING)
def test__unprovision_cleanwait(self):
self._test__unprovision_instance(state=ironic_states.CLEANWAIT)
@mock.patch.object(ironic_driver, '_validate_instance_and_node')
def test__unprovision_fail_max_retries(self, mock_validate_inst):
CONF.set_default('api_max_retries', default=2, group='ironic')

View File

@ -821,6 +821,7 @@ class IronicDriver(virt_driver.ComputeDriver):
raise loopingcall.LoopingCallDone()
if node.provision_state in (ironic_states.NOSTATE,
ironic_states.CLEANING,
ironic_states.CLEANWAIT,
ironic_states.CLEANFAIL,
ironic_states.AVAILABLE):
# From a user standpoint, the node is unprovisioned. If a node

View File

@ -100,6 +100,13 @@ represented in target_provision_state.
CLEANING = 'cleaning'
""" Node is being automatically cleaned to prepare it for provisioning. """
CLEANWAIT = 'clean wait'
""" Node is waiting for a clean step to be finished.
This will be the node's `provision_state` while the node is waiting for
the driver to finish a cleaning step.
"""
CLEANFAIL = 'clean failed'
""" Node failed cleaning. This requires operator intervention to resolve. """