Merge "Do not always query deleted instance_types."

This commit is contained in:
Jenkins
2012-06-10 20:56:47 +00:00
committed by Gerrit Code Review
3 changed files with 19 additions and 4 deletions

View File

@@ -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,

View File

@@ -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)

View File

@@ -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()