summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-08-02 15:34:00 -0400
committerRussell Bryant <rbryant@redhat.com>2012-08-06 15:09:33 -0400
commit2ee42aafde64af6d64a1f34a6204fd80e7dd01fd (patch)
treefac26bea8720c878cd8b899002cf16249f3db3a6 /nova/tests
parent6b42978eb4bf740f148a6bb200b331660755b53b (diff)
Reduce db access in prep_resize in the compute manager.
This patch changes the arguments passed to prep_resize in the compute manager. Previously it took instance and instance_type IDs. It now receives a full dict for both of these. This cuts down on database access needed on the compute node. This method was not previously in the compute rpcapi module, so it has been added there. The scheduler had a bit of work done ot get it to use the rpcapi module for prep_resize, as well. Part of blueprint no-db-messaging. Change-Id: Idadbf4fc624d5d1b128f758a46c61b3c840b9898
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/compute/test_compute.py49
-rw-r--r--nova/tests/compute/test_rpcapi.py5
2 files changed, 38 insertions, 16 deletions
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index efb241b75..5d41cd7c6 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -1146,7 +1146,8 @@ class ComputeTestCase(BaseTestCase):
context = self.context.elevated()
instance = jsonutils.to_primitive(self._create_fake_instance())
- self.compute.prep_resize(context, instance['uuid'], 1, {})
+ self.compute.prep_resize(context, instance=instance, instance_type={},
+ image={})
migration_ref = db.migration_get_by_instance_and_status(context,
instance['uuid'], 'pre-migrating')
self.compute.finish_resize(context,
@@ -1167,7 +1168,8 @@ class ComputeTestCase(BaseTestCase):
context = self.context.elevated()
instance = jsonutils.to_primitive(self._create_fake_instance())
- self.compute.prep_resize(context, instance['uuid'], 1, {})
+ self.compute.prep_resize(context, instance=instance, instance_type={},
+ image={})
migration_ref = db.migration_get_by_instance_and_status(context,
instance['uuid'], 'pre-migrating')
@@ -1250,12 +1252,14 @@ class ComputeTestCase(BaseTestCase):
context = self.context.elevated()
old_type_id = instance_types.get_instance_type_by_name(
'm1.tiny')['id']
- new_type_id = instance_types.get_instance_type_by_name(
- 'm1.small')['id']
+ new_type = instance_types.get_instance_type_by_name('m1.small')
+ new_type = jsonutils.to_primitive(new_type)
+ new_type_id = new_type['id']
self.compute.run_instance(self.context, instance['uuid'])
db.instance_update(self.context, instance['uuid'], {'host': 'foo'})
- self.compute.prep_resize(context, instance['uuid'], new_type_id, {})
+ self.compute.prep_resize(context, instance=instance,
+ instance_type=new_type, image={})
migration_ref = db.migration_get_by_instance_and_status(context,
instance['uuid'],
'pre-migrating')
@@ -1304,7 +1308,9 @@ class ComputeTestCase(BaseTestCase):
test_notifier.NOTIFICATIONS = []
db.instance_update(self.context, instance['uuid'], {'host': 'foo'})
- self.compute.prep_resize(context, instance['uuid'], 1, {})
+ self.compute.prep_resize(context,
+ instance=jsonutils.to_primitive(instance),
+ instance_type={}, image={})
db.migration_get_by_instance_and_status(context,
instance['uuid'],
'pre-migrating')
@@ -1343,12 +1349,15 @@ class ComputeTestCase(BaseTestCase):
context = self.context.elevated()
self.compute.run_instance(self.context, instance['uuid'])
- db.instance_update(self.context, instance['uuid'], {'host': 'foo'})
+ new_instance = db.instance_update(self.context, instance['uuid'],
+ {'host': 'foo'})
self.assertRaises(exception.MigrationError, self.compute.prep_resize,
- context, instance['uuid'], 1, {})
+ context,
+ instance=jsonutils.to_primitive(new_instance),
+ instance_type={}, image={})
self.compute.terminate_instance(context,
- instance=jsonutils.to_primitive(instance))
+ instance=jsonutils.to_primitive(new_instance))
def test_resize_instance_driver_error(self):
"""Ensure instance status set to Error on resize error"""
@@ -1364,7 +1373,8 @@ class ComputeTestCase(BaseTestCase):
self.compute.run_instance(self.context, instance['uuid'])
db.instance_update(self.context, instance['uuid'], {'host': 'foo'})
- self.compute.prep_resize(context, instance['uuid'], 1, {})
+ self.compute.prep_resize(context, instance=instance,
+ instance_type={}, image={})
migration_ref = db.migration_get_by_instance_and_status(context,
instance['uuid'], 'pre-migrating')
@@ -1385,7 +1395,8 @@ class ComputeTestCase(BaseTestCase):
self.compute.run_instance(self.context, instance['uuid'])
db.instance_update(self.context, instance['uuid'],
{'host': 'foo'})
- self.compute.prep_resize(context, instance['uuid'], 1, {})
+ self.compute.prep_resize(context, instance=instance,
+ instance_type={}, image={})
migration_ref = db.migration_get_by_instance_and_status(context,
instance['uuid'], 'pre-migrating')
self.compute.resize_instance(context, migration_ref['id'], {},
@@ -1413,11 +1424,14 @@ class ComputeTestCase(BaseTestCase):
inst_ref['instance_type_id'])
self.assertEqual(instance_type_ref['flavorid'], '1')
- db.instance_update(self.context, instance['uuid'], {'host': 'foo'})
+ new_inst_ref = db.instance_update(self.context, instance['uuid'],
+ {'host': 'foo'})
new_instance_type_ref = db.instance_type_get_by_flavor_id(context, 3)
- self.compute.prep_resize(context, inst_ref['uuid'],
- new_instance_type_ref['id'], {})
+ self.compute.prep_resize(context,
+ instance=jsonutils.to_primitive(new_inst_ref),
+ instance_type=jsonutils.to_primitive(new_instance_type_ref),
+ image={})
migration_ref = db.migration_get_by_instance_and_status(context,
inst_ref['uuid'], 'pre-migrating')
@@ -1465,7 +1479,9 @@ class ComputeTestCase(BaseTestCase):
self.compute.run_instance(self.context, instance['uuid'])
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
self.assertRaises(exception.MigrationError, self.compute.prep_resize,
- self.context, instance['uuid'], 1, {})
+ self.context,
+ instance=jsonutils.to_primitive(instance),
+ instance_type={}, image={})
self.compute.terminate_instance(self.context,
instance=jsonutils.to_primitive(instance))
@@ -1482,7 +1498,8 @@ class ComputeTestCase(BaseTestCase):
self.compute.run_instance(self.context, inst_ref['uuid'])
db.instance_update(self.context, inst_ref['uuid'], {'host': 'foo'})
- self.compute.prep_resize(context, inst_ref['uuid'], 1, {})
+ self.compute.prep_resize(context, instance=inst_ref, instance_type={},
+ image={})
migration_ref = db.migration_get_by_instance_and_status(context,
inst_ref['uuid'], 'pre-migrating')
self.assertRaises(test.TestingException, self.compute.resize_instance,
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index a1062ea57..94b44b345 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -210,6 +210,11 @@ class ComputeRpcAPITestCase(test.TestCase):
instance=self.fake_instance, block_migration='block_migration',
disk='disk', host='host', version='1.23')
+ def test_prep_resize(self):
+ self._test_compute_api('prep_resize', 'cast',
+ instance=self.fake_instance, instance_type='fake_type',
+ image='fake_image', host='host', version='1.38')
+
def test_reboot_instance(self):
self._test_compute_api('reboot_instance', 'cast',
instance=self.fake_instance, reboot_type='type', version='1.4')