From 21ee158cfb9d25fb466ee907ebf944738c5b0b21 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Thu, 28 Sep 2017 18:34:35 -0400 Subject: [PATCH] Remove system_metadata loading in Instance._load_flavor We migrated the embedded instance flavor from system_metadata to instance_extra back in Kilo, and you couldn't upgrade to Liberty without doing that, so we no longer need this data migration code to include system_metadata. Also cleans up a few other related remnants from the migration. Change-Id: I015755937fcbf4456ee502970e5d282ead570015 --- nova/objects/instance.py | 13 ++----------- nova/tests/unit/compute/test_compute.py | 4 +--- nova/tests/unit/objects/test_instance.py | 7 +++---- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/nova/objects/instance.py b/nova/objects/instance.py index 96408e2cc2..3c166addd2 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -776,11 +776,8 @@ class Instance(base.NovaPersistentObject, base.NovaObject, # NOTE(alaski): We need to pull system_metadata for the # notification.send_update() below. If we don't there's a KeyError # when it tries to extract the flavor. - # NOTE(danms): If we have sysmeta, we need flavor since the caller - # might be expecting flavor information as a result if 'system_metadata' not in expected_attrs: expected_attrs.append('system_metadata') - expected_attrs.append('flavor') old_ref, inst_ref = db.instance_update_and_get_original( context, self.uuid, updates, columns_to_join=_expected_cols(expected_attrs)) @@ -888,7 +885,7 @@ class Instance(base.NovaPersistentObject, base.NovaObject, def _load_flavor(self): instance = self.__class__.get_by_uuid( self._context, uuid=self.uuid, - expected_attrs=['flavor', 'system_metadata']) + expected_attrs=['flavor']) # NOTE(danms): Orphan the instance to make sure we don't lazy-load # anything below @@ -897,12 +894,6 @@ class Instance(base.NovaPersistentObject, base.NovaObject, self.old_flavor = instance.old_flavor self.new_flavor = instance.new_flavor - # NOTE(danms): The query above may have migrated the flavor from - # system_metadata. Since we have it anyway, go ahead and refresh - # our system_metadata from it so that a save will be accurate. - instance.system_metadata.update(self.get('system_metadata', {})) - self.system_metadata = instance.system_metadata - def _load_vcpu_model(self, db_vcpu_model=_NO_DATA_SENTINEL): if db_vcpu_model is None: self.vcpu_model = None @@ -1100,7 +1091,7 @@ class Instance(base.NovaPersistentObject, base.NovaObject, return getattr(self, attr) except exception.FlavorNotFound: # NOTE(danms): This only happens in the case where we don't - # have flavor information in sysmeta or extra, and doing + # have flavor information in instance_extra, and doing # this triggers a lookup based on our instance_type_id for # (very) legacy instances. That legacy code expects a None here, # so emulate it for this helper, even though the actual attribute diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 45ea2c30b0..5b3944c9a7 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -2992,9 +2992,7 @@ class ComputeTestCase(BaseTestCase, {'task_state': task_pending, 'expected_task_state': expected_tasks, 'power_state': fake_power_state1}, - columns_to_join=['system_metadata', - 'extra', - 'extra.flavor']), + columns_to_join=['system_metadata']), mock.call(econtext, updated_dbinstance1['uuid'], {'task_state': task_started, 'expected_task_state': task_pending}, diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py index 3bb7ecbf10..a08868dd38 100644 --- a/nova/tests/unit/objects/test_instance.py +++ b/nova/tests/unit/objects/test_instance.py @@ -453,7 +453,7 @@ class _TestInstanceObject(object): mock_db_instance_update_and_get_original.assert_called_once_with( self.context, fake_uuid, expected_updates, columns_to_join=['info_cache', 'security_groups', - 'system_metadata', 'extra', 'extra.flavor'] + 'system_metadata'] ) if cell_type == 'api': mock_cells_rpcapi_CellsAPI.return_value.instance_update_from_api \ @@ -523,7 +523,7 @@ class _TestInstanceObject(object): columns_to_join=['info_cache', 'security_groups']) mock_update_and_get.assert_called_once_with(self.context, fake_uuid, expected_updates, columns_to_join=['info_cache', 'security_groups', - 'system_metadata', 'extra', 'extra.flavor']) + 'system_metadata']) mock_send.assert_called_once_with(self.context, mock.ANY, mock.ANY) @mock.patch('nova.db.instance_extra_update_by_uuid') @@ -732,8 +732,7 @@ class _TestInstanceObject(object): mock.call(self.context, inst.uuid, {'vm_state': 'foo', 'task_state': 'bar', 'cell_name': 'foo!bar@baz'}, - columns_to_join=['tags', 'system_metadata', - 'extra', 'extra.flavor']), + columns_to_join=['tags', 'system_metadata']), mock.call(self.context, inst.uuid, {'vm_state': 'bar', 'task_state': 'foo'}, columns_to_join=['system_metadata', 'tags'])]