Skip to content

Commit

Permalink
Do not always query deleted instance_types.
Browse files Browse the repository at this point in the history
When converting from flavorid to instance_type_id in the OSAPI,
it isn't always desired to return deleted instance_types. In the case
of OSAPI create(), we explicitly do not want to query deleted flavors.

Fixes bug 1010638

Change-Id: I9c26c7130f8c3d6680143e36b4aaa1f662c682a7
  • Loading branch information
Brian Lamar committed Jun 8, 2012
1 parent e391180 commit 5157401
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nova/api/openstack/compute/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def create(self, req, body):

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,
Expand Down
4 changes: 2 additions & 2 deletions nova/compute/instance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 16 additions & 1 deletion nova/tests/test_instance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,27 @@ def test_can_read_deleted_types_using_flavor_id(self):
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()
Expand Down

0 comments on commit 5157401

Please sign in to comment.