summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-03-08 12:46:24 -0500
committerDan Smith <danms@us.ibm.com>2013-03-08 13:09:56 -0500
commitcc8ec3d40678c3a7d868c4d4e4eabf242ec081db (patch)
treea52341719a9fcb23d5928ae4eb9c99da2618d7b6
parentd64f61f976a0243f48effd97d1e5e2e0bc20040b (diff)
downloadnova-cc8ec3d40678c3a7d868c4d4e4eabf242ec081db.tar.gz
nova-cc8ec3d40678c3a7d868c4d4e4eabf242ec081db.tar.xz
nova-cc8ec3d40678c3a7d868c4d4e4eabf242ec081db.zip
Remove uses of instance['instance_type'] from nova/scheduler
This is a tiny change in the actual code, but requires a bunch of silly changes in the tests because we're so inconsistent with our (ab)use of instance types there. This attempts to help clean that up locally a bit. This is one change in a series aimed at removing the use of instance-linked instance_type objects, in favor of the decoupled type data in system_metadata. See bug 1140119 for more details. Change-Id: Ied1a944a7c762129597d18ded61ce1632657f070
-rw-r--r--nova/scheduler/filter_scheduler.py3
-rw-r--r--nova/tests/scheduler/test_filter_scheduler.py3
-rw-r--r--nova/tests/scheduler/test_scheduler.py34
3 files changed, 27 insertions, 13 deletions
diff --git a/nova/scheduler/filter_scheduler.py b/nova/scheduler/filter_scheduler.py
index b9768e11b..2714e93bb 100644
--- a/nova/scheduler/filter_scheduler.py
+++ b/nova/scheduler/filter_scheduler.py
@@ -23,6 +23,7 @@ import random
from oslo.config import cfg
+from nova.compute import instance_types
from nova import exception
from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier
@@ -375,7 +376,7 @@ class FilterScheduler(driver.Scheduler):
host_state = self.host_manager.host_state_cls(dest, node)
host_state.update_from_compute_node(compute)
- instance_type = instance_ref['instance_type']
+ instance_type = instance_types.extract_instance_type(instance_ref)
filter_properties = {'instance_type': instance_type}
hosts = self.host_manager.get_filtered_hosts([host_state],
diff --git a/nova/tests/scheduler/test_filter_scheduler.py b/nova/tests/scheduler/test_filter_scheduler.py
index 5256dc35f..d2d6994d7 100644
--- a/nova/tests/scheduler/test_filter_scheduler.py
+++ b/nova/tests/scheduler/test_filter_scheduler.py
@@ -357,6 +357,8 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
filter_properties['retry']['hosts'])
def test_live_migration_dest_check_service_memory_overcommit(self):
+ instance = self._live_migration_instance()
+
# Live-migration should work since default is to overcommit memory.
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
@@ -369,7 +371,6 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
dest = 'fake_host2'
block_migration = False
disk_over_commit = False
- instance = self._live_migration_instance()
self.driver._live_migration_src_check(self.context, instance)
db.service_get_by_compute_host(self.context,
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index 4e95061a7..8c8181cb1 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -22,6 +22,7 @@ Tests For Scheduler
import mox
from nova.compute import api as compute_api
+from nova.compute import instance_types
from nova.compute import power_state
from nova.compute import rpcapi as compute_rpcapi
from nova.compute import task_states
@@ -43,6 +44,7 @@ from nova.tests import fake_instance_actions
from nova.tests.image import fake as fake_image
from nova.tests import matchers
from nova.tests.scheduler import fakes
+from nova import utils
class SchedulerManagerTestCase(test.TestCase):
@@ -392,6 +394,11 @@ class SchedulerTestCase(test.TestCase):
self.assertEqual(result, ['host2'])
def _live_migration_instance(self):
+ inst_type = instance_types.get_instance_type(1)
+ # NOTE(danms): we have _got_ to stop doing this!
+ inst_type['memory_mb'] = 1024
+ sys_meta = utils.dict_to_metadata(
+ instance_types.save_instance_type_info({}, inst_type))
return {'id': 31337,
'uuid': 'fake_uuid',
'name': 'fake-instance',
@@ -402,9 +409,9 @@ class SchedulerTestCase(test.TestCase):
'ephemeral_gb': 0,
'vm_state': '',
'task_state': '',
- 'instance_type': {'memory_mb': 1024},
- 'instance_type_id': 1,
- 'image_ref': 'fake-image-ref'}
+ 'instance_type_id': inst_type['id'],
+ 'image_ref': 'fake-image-ref',
+ 'system_metadata': sys_meta}
def test_live_migration_basic(self):
# Test basic schedule_live_migration functionality.
@@ -735,13 +742,15 @@ class SchedulerTestCase(test.TestCase):
disk_over_commit=disk_over_commit)
def test_live_migration_dest_check_auto_set_host(self):
+ instance = self._live_migration_instance()
+
# Confirm dest is picked by scheduler if not set.
self.mox.StubOutWithMock(self.driver, 'select_hosts')
self.mox.StubOutWithMock(db, 'instance_type_get')
- instance = self._live_migration_instance()
+ instance_type = instance_types.extract_instance_type(instance)
request_spec = {'instance_properties': instance,
- 'instance_type': instance['instance_type'],
+ 'instance_type': instance_type,
'instance_uuids': [instance['uuid']],
'image': self.image_service.show(self.context,
instance['image_ref'])
@@ -749,8 +758,8 @@ class SchedulerTestCase(test.TestCase):
ignore_hosts = [instance['host']]
filter_properties = {'ignore_hosts': ignore_hosts}
- db.instance_type_get(self.context, 1).AndReturn(
- instance['instance_type'])
+ db.instance_type_get(self.context, instance_type['id']).AndReturn(
+ instance_type)
self.driver.select_hosts(self.context, request_spec,
filter_properties).AndReturn(['fake_host2'])
@@ -760,6 +769,8 @@ class SchedulerTestCase(test.TestCase):
self.assertEqual('fake_host2', result)
def test_live_migration_auto_set_dest(self):
+ instance = self._live_migration_instance()
+
# Confirm scheduler picks target host if none given.
self.mox.StubOutWithMock(db, 'instance_type_get')
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
@@ -771,9 +782,9 @@ class SchedulerTestCase(test.TestCase):
dest = None
block_migration = False
disk_over_commit = False
- instance = self._live_migration_instance()
+ instance_type = instance_types.extract_instance_type(instance)
request_spec = {'instance_properties': instance,
- 'instance_type': instance['instance_type'],
+ 'instance_type': instance_type,
'instance_uuids': [instance['uuid']],
'image': self.image_service.show(self.context,
instance['image_ref'])
@@ -781,8 +792,9 @@ class SchedulerTestCase(test.TestCase):
self.driver._live_migration_src_check(self.context, instance)
- db.instance_type_get(self.context, 1).MultipleTimes().AndReturn(
- instance['instance_type'])
+ db.instance_type_get(self.context,
+ instance_type['id']).MultipleTimes().AndReturn(
+ instance_type)
# First selected host raises exception.InvalidHypervisorType
self.driver.select_hosts(self.context, request_spec,