summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/compute/instance_types.py4
-rw-r--r--nova/db/sqlalchemy/models.py3
-rw-r--r--nova/tests/test_instance_types.py20
3 files changed, 23 insertions, 4 deletions
diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py
index c4a6f66f9..f0514cb73 100644
--- a/nova/compute/instance_types.py
+++ b/nova/compute/instance_types.py
@@ -144,5 +144,7 @@ def get_instance_type_by_flavor_id(flavorid):
:raises: FlavorNotFound
"""
- ctxt = context.get_admin_context()
+ # NOTE(jk0): Reading deleted is OK here because we're an admin and querying
+ # flavors directly.
+ ctxt = context.get_admin_context(read_deleted="yes")
return db.instance_type_get_by_flavor_id(ctxt, flavorid)
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index c07f2c9de..78fcaa7e5 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -319,8 +319,7 @@ class InstanceTypes(BASE, NovaBase):
foreign_keys=id,
primaryjoin='and_('
'Instance.instance_type_id == '
- 'InstanceTypes.id, '
- 'InstanceTypes.deleted == False)')
+ 'InstanceTypes.id)')
class Volume(BASE, NovaBase):
diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py
index b790d6b1e..0baeee770 100644
--- a/nova/tests/test_instance_types.py
+++ b/nova/tests/test_instance_types.py
@@ -152,7 +152,7 @@ class InstanceTypeTestCase(test.TestCase):
'name two', 256, 1, 120, 200, flavorid)
def test_will_not_destroy_with_no_name(self):
- """Ensure destroy sad path of no name raises error"""
+ """Ensure destroy said path of no name raises error"""
self.assertRaises(exception.InstanceTypeNotFoundByName,
instance_types.destroy, None)
@@ -201,6 +201,24 @@ class InstanceTypeTestCase(test.TestCase):
fetched = instance_types.get_instance_type_by_flavor_id(flavorid)
self.assertEqual(default_instance_type, fetched)
+ def test_will_list_deleted_type_for_active_instance(self):
+ """Ensure deleted instance types with active instances can be read"""
+ ctxt = context.get_admin_context()
+ inst_type = instance_types.create("test", 256, 1, 120, 100, "test1")
+
+ instance_params = {"instance_type_id": inst_type["id"]}
+ instance = db.instance_create(ctxt, instance_params)
+
+ # NOTE(jk0): Delete the instance type and reload the instance from the
+ # DB. The instance_type object will still be available to the active
+ # instance, otherwise being None.
+ instance_types.destroy(inst_type["name"])
+ instance = db.instance_get_by_uuid(ctxt, instance["uuid"])
+
+ self.assertRaises(exception.InstanceTypeNotFound,
+ instance_types.get_instance_type, inst_type["name"])
+ self.assertTrue(instance["instance_type"])
+
class InstanceTypeFilteringTest(test.TestCase):
"""Test cases for the filter option available for instance_type_get_all"""