summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatt.dietz@rackspace.com <>2011-07-20 16:16:51 +0000
committerTarmac <>2011-07-20 16:16:51 +0000
commit1f8c3f1477eb5856dccb5d7bcdaa4cd5981174c8 (patch)
treeaba73fb6a3eefad940ff7ac0c411fd55e2d8feae
parent77db06c908f9c08c80beb11241c0e23247129ad6 (diff)
parentb2637c282fba3d542c4e157e3e5e22046d28bb29 (diff)
Fixes lp809587
The original flavor wasn't being applied to the instance on a reversion of a resize
-rw-r--r--nova/compute/manager.py14
-rw-r--r--nova/tests/test_compute.py51
2 files changed, 61 insertions, 4 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 47becdcc6..eb3996d29 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -720,7 +720,8 @@ class ComputeManager(manager.SchedulerDependentManager):
self.db.instance_update(context, instance_id,
dict(memory_mb=instance_type['memory_mb'],
vcpus=instance_type['vcpus'],
- local_gb=instance_type['local_gb']))
+ local_gb=instance_type['local_gb'],
+ instance_type_id=instance_type['id']))
self.driver.revert_resize(instance_ref)
self.db.migration_update(context, migration_id,
@@ -741,18 +742,20 @@ class ComputeManager(manager.SchedulerDependentManager):
"""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
+
if instance_ref['host'] == FLAGS.host:
raise exception.Error(_(
'Migration error: destination same as source!'))
- instance_type = self.db.instance_type_get_by_flavor_id(context,
- flavor_id)
+ old_instance_type = self.db.instance_type_get_by_id(context,
+ instance_ref['instance_type_id'])
+
migration_ref = self.db.migration_create(context,
{'instance_id': instance_id,
'source_compute': instance_ref['host'],
'dest_compute': FLAGS.host,
'dest_host': self.driver.get_host_ip_addr(),
- 'old_flavor_id': instance_type['flavorid'],
+ 'old_flavor_id': old_instance_type['flavorid'],
'new_flavor_id': flavor_id,
'status': 'pre-migrating'})
@@ -766,6 +769,9 @@ class ComputeManager(manager.SchedulerDependentManager):
'migration_id': migration_ref['id'],
'instance_id': instance_id, },
})
+
+ instance_type = self.db.instance_type_get_by_flavor_id(context,
+ flavor_id)
usage_info = utils.usage_from_instance(instance_ref,
new_instance_type=instance_type['name'],
new_instance_type_id=instance_type['id'])
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 2900c594e..dc3f0596d 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -519,6 +519,57 @@ class ComputeTestCase(test.TestCase):
self.compute.terminate_instance(context, instance_id)
+ def test_finish_revert_resize(self):
+ """Ensure that the flavor is reverted to the original on revert"""
+ context = self.context.elevated()
+ instance_id = self._create_instance()
+
+ def fake(*args, **kwargs):
+ pass
+
+ self.stubs.Set(self.compute.driver, 'finish_resize', fake)
+ self.stubs.Set(self.compute.driver, 'revert_resize', fake)
+ self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
+
+ self.compute.run_instance(self.context, instance_id)
+
+ # Confirm the instance size before the resize starts
+ inst_ref = db.instance_get(context, instance_id)
+ instance_type_ref = db.instance_type_get_by_id(context,
+ inst_ref['instance_type_id'])
+ self.assertEqual(instance_type_ref['flavorid'], 1)
+
+ db.instance_update(self.context, instance_id, {'host': 'foo'})
+
+ self.compute.prep_resize(context, instance_id, 3)
+
+ migration_ref = db.migration_get_by_instance_and_status(context,
+ instance_id, 'pre-migrating')
+
+ self.compute.resize_instance(context, instance_id,
+ migration_ref['id'])
+ self.compute.finish_resize(context, instance_id,
+ int(migration_ref['id']), {})
+
+ # Prove that the instance size is now the new size
+ inst_ref = db.instance_get(context, instance_id)
+ instance_type_ref = db.instance_type_get_by_id(context,
+ inst_ref['instance_type_id'])
+ self.assertEqual(instance_type_ref['flavorid'], 3)
+
+ # Finally, revert and confirm the old flavor has been applied
+ self.compute.revert_resize(context, instance_id,
+ migration_ref['id'])
+ self.compute.finish_revert_resize(context, instance_id,
+ migration_ref['id'])
+
+ inst_ref = db.instance_get(context, instance_id)
+ instance_type_ref = db.instance_type_get_by_id(context,
+ inst_ref['instance_type_id'])
+ self.assertEqual(instance_type_ref['flavorid'], 1)
+
+ self.compute.terminate_instance(context, instance_id)
+
def test_get_by_flavor_id(self):
type = instance_types.get_instance_type_by_flavor_id(1)
self.assertEqual(type['name'], 'm1.tiny')