Refactor compute_utils to avoid db lookup
This simple change passes bdms into the following compute_utils function to avoid it doing a database lookup: get_device_name_for_instance() Related to bp/no-db-compute Change-Id: I1475b184d8e88b700d606aaf77cc7cd21e83efbb
This commit is contained in:
parent
cd4093e0f2
commit
df6302117c
|
@ -2464,8 +2464,11 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||
|
||||
@lockutils.synchronized(instance['uuid'], 'nova-')
|
||||
def do_reserve():
|
||||
bdms = self.conductor_api.block_device_mapping_get_all_by_instance(
|
||||
context, instance)
|
||||
result = compute_utils.get_device_name_for_instance(context,
|
||||
instance,
|
||||
bdms,
|
||||
device)
|
||||
# NOTE(vish): create bdm here to avoid race condition
|
||||
values = {'instance_uuid': instance['uuid'],
|
||||
|
|
|
@ -71,7 +71,7 @@ def add_instance_fault_from_exc(context, instance, fault, exc_info=None):
|
|||
db.instance_fault_create(context, values)
|
||||
|
||||
|
||||
def get_device_name_for_instance(context, instance, device):
|
||||
def get_device_name_for_instance(context, instance, bdms, device):
|
||||
"""Validates (or generates) a device name for instance.
|
||||
|
||||
If device is not set, it will generate a unique device appropriate
|
||||
|
@ -88,8 +88,6 @@ def get_device_name_for_instance(context, instance, device):
|
|||
req_prefix, req_letters = block_device.match_device(device)
|
||||
except (TypeError, AttributeError, ValueError):
|
||||
raise exception.InvalidDevicePath(path=device)
|
||||
bdms = db.block_device_mapping_get_all_by_instance(context,
|
||||
instance['uuid'])
|
||||
mappings = block_device.instance_block_mapping(instance, bdms)
|
||||
try:
|
||||
prefix = block_device.match_device(mappings['root'])[0]
|
||||
|
|
|
@ -69,8 +69,11 @@ class ComputeValidateDeviceTestCase(test.TestCase):
|
|||
lambda context, instance: self.data)
|
||||
|
||||
def _validate_device(self, device=None):
|
||||
bdms = db.block_device_mapping_get_all_by_instance(
|
||||
self.context, self.instance['uuid'])
|
||||
return compute_utils.get_device_name_for_instance(self.context,
|
||||
self.instance,
|
||||
bdms,
|
||||
device)
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue