diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-11-15 12:43:55 -0500 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-11-19 20:07:06 -0500 |
| commit | 2f6873deea0084998a9514f892e6b50ebef47174 (patch) | |
| tree | 5545902704e7b5648d35fd72e8719cb982257a61 | |
| parent | f5119ca582e5fd5f42ab32a765352314aa5ae28b (diff) | |
| download | nova-2f6873deea0084998a9514f892e6b50ebef47174.tar.gz nova-2f6873deea0084998a9514f892e6b50ebef47174.tar.xz nova-2f6873deea0084998a9514f892e6b50ebef47174.zip | |
Move db lookup for block device mappings.
This patch moves the db blookup for block device mappings for an
instance out of the _setup_block_device_mapping() function in the
compute manager. The db lookups are now done much closer to the rpc
entry-points to the compute manager.
There are two rpc methods that eventually call down into this function:
run_instance and rebuild_instance. This bit of refactoring will make it
a bit easier to update these methods to take in the block device
mappings over rpc.
Part of blueprint no-db-messaging.
Change-Id: Id7d061e10ddc9e0d081e0ee97331631796b47729
| -rw-r--r-- | nova/compute/manager.py | 18 | ||||
| -rw-r--r-- | nova/tests/compute/test_compute.py | 2 |
2 files changed, 12 insertions, 8 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 22f96bbee..fc506651b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -486,13 +486,12 @@ class ComputeManager(manager.SchedulerDependentManager): network_info = network_info.legacy() return network_info - def _setup_block_device_mapping(self, context, instance): + def _setup_block_device_mapping(self, context, instance, bdms): """setup volumes for block device mapping""" block_device_mapping = [] swap = None ephemerals = [] - for bdm in self.db.block_device_mapping_get_all_by_instance( - context, instance['uuid']): + for bdm in bdms: LOG.debug(_('Setting up bdm %s'), bdm, instance=instance) if bdm['no_device']: @@ -568,6 +567,8 @@ class ComputeManager(manager.SchedulerDependentManager): context, instance, "create.start", extra_usage_info=extra_usage_info) network_info = None + bdms = self.db.block_device_mapping_get_all_by_instance( + context, instance['uuid']) rt = self._get_resource_tracker(instance.get('node')) try: limits = filter_properties.get('limits', {}) @@ -576,7 +577,7 @@ class ComputeManager(manager.SchedulerDependentManager): network_info = self._allocate_network(context, instance, requested_networks) block_device_info = self._prep_block_device(context, - instance) + instance, bdms) instance = self._spawn(context, instance, image_meta, network_info, block_device_info, injected_files, admin_password) @@ -813,13 +814,13 @@ class ComputeManager(manager.SchedulerDependentManager): return network_info - def _prep_block_device(self, context, instance): + def _prep_block_device(self, context, instance, bdms): """Set up the block device for an instance with error logging""" self._instance_update(context, instance['uuid'], vm_state=vm_states.BUILDING, task_state=task_states.BLOCK_DEVICE_MAPPING) try: - return self._setup_block_device_mapping(context, instance) + return self._setup_block_device_mapping(context, instance, bdms) except Exception: LOG.exception(_('Instance failed block device setup'), instance=instance) @@ -1211,7 +1212,10 @@ class ComputeManager(manager.SchedulerDependentManager): instance.injected_files = injected_files network_info = self.network_api.get_instance_nw_info(context, instance) - device_info = self._setup_block_device_mapping(context, instance) + bdms = self.db.block_device_mapping_get_all_by_instance( + context, instance['uuid']) + device_info = self._setup_block_device_mapping(context, instance, + bdms) instance = self._instance_update(context, instance['uuid'], diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 662a90be4..087411112 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1480,7 +1480,7 @@ class ComputeTestCase(BaseTestCase): self.mox.StubOutWithMock(self.compute, "_setup_block_device_mapping") self.compute._setup_block_device_mapping( - mox.IgnoreArg(), + mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(rpc.common.RemoteError('', '', '')) self.mox.ReplayAll() |
