Remove unnecessary db call in scheduler driver live-migration code
When the scheduler selects a destination host for live-migration, a db call is made to get instance_type info for the instance. To avoid the db call, this should instead call instance_types.extract_instance_type on the instance. Resolves bug 1167811. Change-Id: I2025fdf1d34e70158360ff71e8545c8e3bc6bc80
This commit is contained in:
@@ -25,6 +25,7 @@ import sys
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova.compute import rpcapi as compute_rpcapi
|
||||
from nova.compute import utils as compute_utils
|
||||
@@ -256,8 +257,7 @@ class Scheduler(object):
|
||||
|
||||
# If dest is not specified, have scheduler pick one.
|
||||
if dest is None:
|
||||
instance_type = db.instance_type_get(
|
||||
context, instance_ref['instance_type_id'])
|
||||
instance_type = instance_types.extract_instance_type(instance_ref)
|
||||
image = self.image_service.show(context, instance_ref['image_ref'])
|
||||
request_spec = {'instance_properties': instance_ref,
|
||||
'instance_type': instance_type,
|
||||
|
||||
@@ -746,11 +746,10 @@ class SchedulerTestCase(test.TestCase):
|
||||
|
||||
# Confirm dest is picked by scheduler if not set.
|
||||
self.mox.StubOutWithMock(self.driver, 'select_hosts')
|
||||
self.mox.StubOutWithMock(db, 'instance_type_get')
|
||||
self.mox.StubOutWithMock(instance_types, 'extract_instance_type')
|
||||
|
||||
instance_type = instance_types.extract_instance_type(instance)
|
||||
request_spec = {'instance_properties': instance,
|
||||
'instance_type': instance_type,
|
||||
'instance_type': {},
|
||||
'instance_uuids': [instance['uuid']],
|
||||
'image': self.image_service.show(self.context,
|
||||
instance['image_ref'])
|
||||
@@ -758,8 +757,7 @@ class SchedulerTestCase(test.TestCase):
|
||||
ignore_hosts = [instance['host']]
|
||||
filter_properties = {'ignore_hosts': ignore_hosts}
|
||||
|
||||
db.instance_type_get(self.context, instance_type['id']).AndReturn(
|
||||
instance_type)
|
||||
instance_types.extract_instance_type(instance).AndReturn({})
|
||||
self.driver.select_hosts(self.context, request_spec,
|
||||
filter_properties).AndReturn(['fake_host2'])
|
||||
|
||||
@@ -772,7 +770,7 @@ class SchedulerTestCase(test.TestCase):
|
||||
instance = self._live_migration_instance()
|
||||
|
||||
# Confirm scheduler picks target host if none given.
|
||||
self.mox.StubOutWithMock(db, 'instance_type_get')
|
||||
self.mox.StubOutWithMock(instance_types, 'extract_instance_type')
|
||||
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
|
||||
self.mox.StubOutWithMock(self.driver, 'select_hosts')
|
||||
self.mox.StubOutWithMock(self.driver, '_live_migration_common_check')
|
||||
@@ -782,9 +780,8 @@ class SchedulerTestCase(test.TestCase):
|
||||
dest = None
|
||||
block_migration = False
|
||||
disk_over_commit = False
|
||||
instance_type = instance_types.extract_instance_type(instance)
|
||||
request_spec = {'instance_properties': instance,
|
||||
'instance_type': instance_type,
|
||||
'instance_type': {},
|
||||
'instance_uuids': [instance['uuid']],
|
||||
'image': self.image_service.show(self.context,
|
||||
instance['image_ref'])
|
||||
@@ -792,9 +789,8 @@ class SchedulerTestCase(test.TestCase):
|
||||
|
||||
self.driver._live_migration_src_check(self.context, instance)
|
||||
|
||||
db.instance_type_get(self.context,
|
||||
instance_type['id']).MultipleTimes().AndReturn(
|
||||
instance_type)
|
||||
instance_types.extract_instance_type(
|
||||
instance).MultipleTimes().AndReturn({})
|
||||
|
||||
# First selected host raises exception.InvalidHypervisorType
|
||||
self.driver.select_hosts(self.context, request_spec,
|
||||
|
||||
Reference in New Issue
Block a user