diff options
-rw-r--r-- | nova/compute/api.py | 10 | ||||
-rw-r--r-- | nova/tests/test_compute.py | 14 |
2 files changed, 20 insertions, 4 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index c2738f6f5..01eead4ac 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -260,7 +260,7 @@ class API(base.Base): db.migration_get_by_instance_and_status(context, instance_id, 'finished') return True - except Exception, e: + except exception.NotFound: return False def ensure_default_security_group(self, context): @@ -512,10 +512,14 @@ class API(base.Base): raise exception.ApiError(_("Requested flavor %(flavor_id)d " "does not exist") % locals()) - if current_instance_type['memory_mb'] >= \ - new_instance_type['memory_mb']: + current_memory_mb = current_instance_type['memory_mb'] + new_memory_mb = new_instance_type['memory_mb'] + if current_memory_mb > new_memory_mb: raise exception.ApiError(_("Invalid flavor: cannot downsize" "instances")) + if current_memory_mb == new_memory_mb: + raise exception.ApiError(_("Invalid flavor: cannot use" + "the same flavor. ")) self._cast_scheduler_message(context, {"method": "prep_resize", diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 444be5dd8..44d04a12f 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -336,7 +336,7 @@ class ComputeTestCase(test.TestCase): self.compute.terminate_instance(context, instance_id) def test_resize_down_fails(self): - """Ensure invalid flavors raise""" + """Ensure resizing down raises and fails""" context = self.context.elevated() instance_id = self._create_instance() @@ -349,6 +349,18 @@ class ComputeTestCase(test.TestCase): self.compute.terminate_instance(context, instance_id) + def test_resize_same_size_fails(self): + """Ensure invalid flavors raise""" + context = self.context.elevated() + instance_id = self._create_instance() + + self.compute.run_instance(self.context, instance_id) + + self.assertRaises(exception.ApiError, self.compute_api.resize, + context, instance_id, 1) + + self.compute.terminate_instance(context, instance_id) + def test_get_by_flavor_id(self): type = instance_types.get_by_flavor_id(1) self.assertEqual(type, 'm1.tiny') |