Fix ironic delete fails when flavor deleted

The ironic virt driver looks up the flavor of an instance
when it is going to delete it. This is to obtain extra
specs details that are not available in the instance details.
If the flavor has been deleted this lookup fails and causes
the delete to fail.

The fix makes the lookup include deleted flavors. Note that
extra specs handling is changing in nova, so this code is
likely to become obsolete when they are available by
other means.

Change-Id: I47ba78abfe60e82226acc6a17752db503d9f21d8
Co-Authored-By: Nicholas Randon <nicholas.randon@hp.com>
Co-Authored-By: Phil Day <phil.day@hp.com>
Closes-Bug: #1400269
(cherry picked from commit c4eab70623)
Conflicts:
        nova/tests/unit/virt/ironic/test_driver.py
        nova/virt/ironic/driver.py
This commit is contained in:
Paul Murray 2014-12-16 14:20:32 +00:00
parent fb2570da36
commit ee66c0436b
2 changed files with 13 additions and 1 deletions

View File

@ -659,12 +659,22 @@ class IronicDriverTestCase(test.NoDBTestCase):
@mock.patch.object(objects.Flavor, 'get_by_id')
@mock.patch.object(FAKE_CLIENT.node, 'update')
def test__cleanup_deploy_good(self, mock_update, mock_flavor):
self._get_by_id_reads_deleted = False
def side_effect(context, id):
self._get_by_id_reads_deleted = context._read_deleted == 'yes'
mock_flavor.side_effect = side_effect
mock_flavor.return_value = ironic_utils.get_test_flavor(extra_specs={})
node = ironic_utils.get_test_node(driver='fake',
instance_uuid='fake-id')
instance = fake_instance.fake_instance_obj(self.ctx,
node=node.uuid)
self.driver._cleanup_deploy(self.ctx, node, instance, None)
self.assertTrue(self._get_by_id_reads_deleted,
'Flavor.get_by_id was not called with '
'read_deleted set in the context')
expected_patch = [{'path': '/instance_uuid', 'op': 'remove'}]
mock_update.assert_called_once_with(node.uuid, expected_patch)

View File

@ -307,7 +307,9 @@ class IronicDriver(virt_driver.ComputeDriver):
icli = client_wrapper.IronicClientWrapper()
# TODO(mrda): It would be better to use instance.get_flavor() here
# but right now that doesn't include extra_specs which are required
flavor = objects.Flavor.get_by_id(context,
# NOTE(pmurray): Flavor may have been deleted
ctxt = context.elevated(read_deleted="yes")
flavor = objects.Flavor.get_by_id(ctxt,
instance['instance_type_id'])
patch = patcher.create(node).get_cleanup_patch(instance, network_info,
flavor)