Handle FlavorNotFound when augmenting migrated flavors

When we migrate a partial flavor from system_metadata to a full
flavor in instance_extra, we need to query for the original flavor in
order to fill in the missing extra_specs. If that fails because the
flavor has been deleted, we need to just not augment the flavor, log
a warning, and continue instead of failing.

Change-Id: Ida49ddea525fb54e0d0238746b83b0202da437c3
Related-Bug: #1460673
This commit is contained in:
Dan Smith 2015-06-01 08:15:51 -07:00
parent 4a02d9415f
commit 68b22c1e31
2 changed files with 31 additions and 2 deletions

View File

@ -6046,8 +6046,15 @@ def _augment_flavors_to_migrate(instance, flavor_cache):
continue
flavorid = flavor.flavorid
if flavorid not in flavor_cache:
flavor_cache[flavorid] = objects.Flavor.get_by_flavor_id(
deleted_ctx, flavorid)
try:
flavor_cache[flavorid] = objects.Flavor.get_by_flavor_id(
deleted_ctx, flavorid)
except exception.FlavorNotFound:
LOG.warn(_LW('Flavor %(flavorid)s not found for instance '
'during migration; extra_specs will not be '
'available'),
{'flavorid': flavorid}, instance=instance)
continue
_augment_flavor_to_migrate(flavor, flavor_cache[flavorid])

View File

@ -7885,6 +7885,28 @@ class FlavorMigrationTestCase(test.TestCase):
self.assertEqual({}, flavor_cache)
self.assertFalse(mock_save.called)
@mock.patch('nova.objects.Flavor.get_by_flavor_id')
@mock.patch('nova.db.sqlalchemy.api._augment_flavor_to_migrate')
@mock.patch('nova.objects.Instance.save')
def test_migrate_flavor_with_missing_flavor(self, mock_save,
mock_augment,
mock_get_flavor):
ctxt = context.get_admin_context()
flavor = flavors.get_default_flavor()
sysmeta = flavors.save_flavor_info({}, flavor)
mock_get_flavor.side_effect = exception.FlavorNotFound(flavor_id=123)
values = {'uuid': str(stdlib_uuid.uuid4()),
'instance_type_id': 123,
'system_metadata': sysmeta,
}
db.instance_create(ctxt, values)
flavor_cache = {}
db.migrate_flavor_data(ctxt, None, flavor_cache)
self.assertFalse(mock_augment.called)
self.assertTrue(mock_save.called)
self.assertEqual({}, flavor_cache)
class ArchiveTestCase(test.TestCase):