Only query BDMs once in API during rebuild

We were unnecessarily looking up BDMs from the database
more than once during rebuild in the API. This makes that
a single read.

Change-Id: Iab929210d11336d09d9eef14ff6904e630ba195a
(cherry picked from commit 718e5af486)
(cherry picked from commit 6c1a0889bc)
This commit is contained in:
Matt Riedemann 2017-10-04 13:57:40 -04:00
parent fe5e3e7e61
commit e26c91588e
2 changed files with 5 additions and 4 deletions

View File

@ -2990,7 +2990,9 @@ class API(base.Base):
self._check_auto_disk_config(image=image, **kwargs)
flavor = instance.get_flavor()
root_bdm = compute_utils.get_root_bdm(context, instance)
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
context, instance.uuid)
root_bdm = compute_utils.get_root_bdm(context, instance, bdms)
self._checks_for_create_and_rebuild(context, image_id, image,
flavor, metadata, files_to_inject, root_bdm)
@ -3042,9 +3044,6 @@ class API(base.Base):
# system metadata... and copy in the properties for the new image.
orig_sys_metadata = _reset_image_metadata()
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
context, instance.uuid)
self._record_action_start(context, instance, instance_actions.REBUILD)
# NOTE(sbauza): The migration script we provided in Newton should make

View File

@ -3181,6 +3181,8 @@ class _ComputeAPIUnitTestMixIn(object):
_checks_for_create_and_rebuild.assert_called_once_with(self.context,
None, image, flavor, {}, [], None)
self.assertNotEqual(orig_system_metadata, instance.system_metadata)
bdm_get_by_instance_uuid.assert_called_once_with(
self.context, instance.uuid)
@mock.patch.object(objects.RequestSpec, 'save')
@mock.patch.object(objects.RequestSpec, 'get_by_instance_uuid')