summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJian Wen <wenjianhn@gmail.com>2012-11-04 15:39:51 +0800
committerJian Wen <wenjianhn@gmail.com>2012-11-04 16:39:33 +0800
commit25743e4fc3dc845afacebe7f790c11cf35fbadea (patch)
tree142e4ad161c747c0fad6e598f242bad97bf9822c /nova
parentdd086638b8c6e43f275fc45b3fc7df2de90bb2c2 (diff)
downloadnova-25743e4fc3dc845afacebe7f790c11cf35fbadea.tar.gz
nova-25743e4fc3dc845afacebe7f790c11cf35fbadea.tar.xz
nova-25743e4fc3dc845afacebe7f790c11cf35fbadea.zip
Forbid resizing instance to deleted instance types
Sets read_deleted="no" while get_instance_type_by_flavor_id to forbid resizing instance to deleted instance types Fixes bug 1068539 Change-Id: I3859f63a33391a840e041f06f08af361b6d64157
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/api.py2
-rw-r--r--nova/tests/compute/test_compute.py33
2 files changed, 30 insertions, 5 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 1bbcdbda9..f7032e1d1 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1676,7 +1676,7 @@ class API(base.Base):
new_instance_type = current_instance_type
else:
new_instance_type = instance_types.get_instance_type_by_flavor_id(
- flavor_id)
+ flavor_id, read_deleted="no")
current_instance_type_name = current_instance_type['name']
new_instance_type_name = new_instance_type['name']
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index a7cb2f856..f9147c5d4 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -3856,6 +3856,25 @@ class ComputeAPITestCase(BaseTestCase):
self.compute.terminate_instance(self.context, instance=instance)
+ def test_resize_deleted_flavor_fails(self):
+ instance = self._create_fake_instance()
+ instance = db.instance_get_by_uuid(self.context, instance['uuid'])
+ instance = jsonutils.to_primitive(instance)
+ self.compute.run_instance(self.context, instance=instance)
+
+ name = 'test_resize_new_flavor'
+ flavorid = 11
+ memory_mb = 128
+ root_gb = 0
+ vcpus = 1
+ instance_types.create(name, memory_mb, vcpus, root_gb, 0,
+ flavorid, 0, 1.0, True)
+ instance_types.destroy(name)
+ self.assertRaises(exception.FlavorNotFound, self.compute_api.resize,
+ self.context, instance, 200)
+
+ self.compute.terminate_instance(self.context, instance=instance)
+
def test_resize_same_flavor_fails(self):
"""Ensure invalid flavors raise"""
instance = self._create_fake_instance()
@@ -5474,8 +5493,11 @@ class DisabledInstanceTypesTestCase(BaseTestCase):
orig_get_instance_type_by_flavor_id =\
instance_types.get_instance_type_by_flavor_id
- def fake_get_instance_type_by_flavor_id(flavor_id):
- instance_type = orig_get_instance_type_by_flavor_id(flavor_id)
+ def fake_get_instance_type_by_flavor_id(flavor_id, ctxt=None,
+ read_deleted="yes"):
+ instance_type = orig_get_instance_type_by_flavor_id(flavor_id,
+ ctxt,
+ read_deleted)
instance_type['disabled'] = False
return instance_type
@@ -5492,8 +5514,11 @@ class DisabledInstanceTypesTestCase(BaseTestCase):
orig_get_instance_type_by_flavor_id = \
instance_types.get_instance_type_by_flavor_id
- def fake_get_instance_type_by_flavor_id(flavor_id):
- instance_type = orig_get_instance_type_by_flavor_id(flavor_id)
+ def fake_get_instance_type_by_flavor_id(flavor_id, ctxt=None,
+ read_deleted="yes"):
+ instance_type = orig_get_instance_type_by_flavor_id(flavor_id,
+ ctxt,
+ read_deleted)
instance_type['disabled'] = True
return instance_type