From 02f58be126bc8429bf21d6fb07d7f0ca846eebc4 Mon Sep 17 00:00:00 2001 From: Tiago Mello Date: Mon, 2 Sep 2013 20:54:14 -0300 Subject: [PATCH] Adds 'instance_type' param to build_request_spec This change adds a new optional parameter to scheduler.utils.build_request_spec. It also fixes Bug 1219761 by adding the new 'flavor' for cold migration instead of the instance current one. Change-Id: I28ac5f636e22e4d02ad5495b7b50c8226678c413 --- nova/conductor/manager.py | 2 +- nova/scheduler/utils.py | 5 +++-- nova/tests/conductor/test_conductor.py | 24 ++++++++++++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index d99b5c09ff1a..5badd443c9aa 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -644,7 +644,7 @@ class ComputeTaskManager(base.Base): image = {} request_spec = scheduler_utils.build_request_spec( - context, image, [instance]) + context, image, [instance], instance_type=flavor) try: hosts = self.scheduler_rpcapi.select_destinations( diff --git a/nova/scheduler/utils.py b/nova/scheduler/utils.py index 8ef0e04eb857..1a436d30720b 100644 --- a/nova/scheduler/utils.py +++ b/nova/scheduler/utils.py @@ -28,14 +28,15 @@ from nova.openstack.common.notifier import api as notifier LOG = logging.getLogger(__name__) -def build_request_spec(ctxt, image, instances): +def build_request_spec(ctxt, image, instances, instance_type=None): """Build a request_spec for the scheduler. The request_spec assumes that all instances to be scheduled are the same type. """ instance = instances[0] - instance_type = flavors.extract_flavor(instance) + if instance_type is None: + instance_type = flavors.extract_flavor(instance) # NOTE(comstud): This is a bit ugly, but will get cleaned up when # we're passing an InstanceType internal object. extra_specs = db.flavor_extra_specs_get(ctxt, diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index b3e3f0a348e6..fc1ca4a76719 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -1257,15 +1257,16 @@ class _BaseTaskTestCase(object): inst = fake_instance.fake_db_instance(image_ref='image_ref') inst_obj = instance_obj.Instance._from_db_object( self.context, instance_obj.Instance(), inst, []) - instance_type = {} - instance_type['extra_specs'] = 'extra_specs' - request_spec = {'instance_type': instance_type} + flavor = flavors.get_default_flavor() + flavor['extra_specs'] = 'extra_specs' + request_spec = {'instance_type': flavor} self.conductor_manager.image_service.show( self.context, inst_obj['image_ref']).AndReturn('image') scheduler_utils.build_request_spec( self.context, 'image', - [mox.IsA(instance_obj.Instance)]).AndReturn(request_spec) + [mox.IsA(instance_obj.Instance)], + instance_type=flavor).AndReturn(request_spec) hosts = [dict(host='host1', nodename=None, limits={})] self.conductor_manager.scheduler_rpcapi.select_destinations( @@ -1275,7 +1276,7 @@ class _BaseTaskTestCase(object): self.conductor_manager.compute_rpcapi.prep_resize( self.context, 'image', mox.IsA(instance_obj.Instance), - 'flavor', 'host1', [], request_spec=request_spec, + mox.IsA(dict), 'host1', [], request_spec=request_spec, filter_properties=filter_properties, node=None) self.mox.ReplayAll() @@ -1287,11 +1288,11 @@ class _BaseTaskTestCase(object): # The API method is actually 'resize_instance'. It gets # converted into 'migrate_server' when doing RPC. self.conductor.resize_instance( - self.context, inst_obj, {}, scheduler_hint, 'flavor', []) + self.context, inst_obj, {}, scheduler_hint, flavor, []) else: self.conductor.migrate_server( self.context, inst_obj, scheduler_hint, - False, False, 'flavor', None, None, []) + False, False, flavor, None, None, []) def test_build_instances(self): instance_type = flavors.get_default_flavor() @@ -1531,7 +1532,8 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase): self.conductor._get_image(self.context, 'fake-image_ref').AndReturn(image) scheduler_utils.build_request_spec( - self.context, image, [inst_obj]).AndReturn(request_spec) + self.context, image, [inst_obj], + instance_type='flavor').AndReturn(request_spec) exc_info = exc.NoValidHost(reason="") @@ -1575,7 +1577,8 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase): self.conductor._get_image(self.context, 'fake-image_ref').AndReturn(image) scheduler_utils.build_request_spec( - self.context, image, [inst_obj]).AndReturn(request_spec) + self.context, image, [inst_obj], + instance_type='flavor').AndReturn(request_spec) exc_info = exc.NoValidHost(reason="") @@ -1623,7 +1626,8 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase): self.conductor._get_image(self.context, 'fake-image_ref').AndReturn(image) scheduler_utils.build_request_spec( - self.context, image, [inst_obj]).AndReturn(request_spec) + self.context, image, [inst_obj], + instance_type='flavor').AndReturn(request_spec) exc_info = exc.NoValidHost(reason="")