summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-10 20:56:47 +0000
committerGerrit Code Review <review@openstack.org>2012-06-10 20:56:47 +0000
commit3ea7dcc6432d6247cb1dc536c31684b595841633 (patch)
treea04b9d191ac15ce1c183dbc870768896c31ffbe9
parentc3a12e6eafc4563ef44101629f1f4363c9cefdab (diff)
parent5157401f20158b2b99d01796f73a8ba5368c80a2 (diff)
downloadnova-3ea7dcc6432d6247cb1dc536c31684b595841633.tar.gz
nova-3ea7dcc6432d6247cb1dc536c31684b595841633.tar.xz
nova-3ea7dcc6432d6247cb1dc536c31684b595841633.zip
Merge "Do not always query deleted instance_types."
-rw-r--r--nova/api/openstack/compute/servers.py2
-rw-r--r--nova/compute/instance_types.py4
-rw-r--r--nova/tests/test_instance_types.py17
3 files changed, 19 insertions, 4 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 64af7222f..a92d9b6bb 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -676,7 +676,7 @@ class Controller(wsgi.Controller):
try:
_get_inst_type = instance_types.get_instance_type_by_flavor_id
- inst_type = _get_inst_type(flavor_id)
+ inst_type = _get_inst_type(flavor_id, read_deleted="no")
(instances, resv_id) = self.compute_api.create(context,
inst_type,
diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py
index 69eef7f83..d06252a6b 100644
--- a/nova/compute/instance_types.py
+++ b/nova/compute/instance_types.py
@@ -140,10 +140,10 @@ def get_instance_type_by_name(name):
# TODO(termie): flavor-specific code should probably be in the API that uses
# flavors.
-def get_instance_type_by_flavor_id(flavorid):
+def get_instance_type_by_flavor_id(flavorid, read_deleted="yes"):
"""Retrieve instance type by flavorid.
:raises: FlavorNotFound
"""
- ctxt = context.get_admin_context(read_deleted="yes")
+ ctxt = context.get_admin_context(read_deleted=read_deleted)
return db.instance_type_get_by_flavor_id(ctxt, flavorid)
diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py
index ab4af3bc1..0d0417d0f 100644
--- a/nova/tests/test_instance_types.py
+++ b/nova/tests/test_instance_types.py
@@ -211,12 +211,27 @@ class InstanceTypeTestCase(test.TestCase):
self.assertEqual(inst_type_name, inst_type["name"])
# NOTE(jk0): The deleted flavor will show up here because the context
- # in get_instance_type_by_flavor_id() is set to use read_deleted.
+ # in get_instance_type_by_flavor_id() is set to use read_deleted by
+ # default.
instance_types.destroy(inst_type["name"])
deleted_inst_type = instance_types.get_instance_type_by_flavor_id(
inst_type_flavor_id)
self.assertEqual(inst_type_name, deleted_inst_type["name"])
+ def test_read_deleted_false_converting_flavorid(self):
+ """
+ Ensure deleted instance types are not returned when not needed (for
+ example when creating a server and attempting to translate from
+ flavorid to instance_type_id.
+ """
+ instance_types.create("instance_type1", 256, 1, 120, 100, "test1")
+ instance_types.destroy("instance_type1")
+ instance_types.create("instance_type1_redo", 256, 1, 120, 100, "test1")
+
+ instance_type = instance_types.get_instance_type_by_flavor_id(
+ "test1", read_deleted="no")
+ self.assertEqual("instance_type1_redo", instance_type["name"])
+
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()