Skip to content

Commit

Permalink
Fix flavor deletion when there is a deleted flavor
Browse files Browse the repository at this point in the history
If there is a deleted flavor with the same ID as an undeleted flavor,
the flavormanage delete code attempts to delete it again, which fails.
This patch makes sure to pass read_deleted='no' when the flavor is
retrieved for deletion so we get the undeleted flavor. Includes a
failing test to make sure the value is passed properly.

Fixes bug 1048678

Change-Id: If6a20de2526b7ba90ada4a40317a98f79b2141dc
  • Loading branch information
vishvananda committed Sep 10, 2012
1 parent 641223d commit d741328
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nova/api/openstack/compute/contrib/flavormanage.py
Expand Up @@ -42,7 +42,8 @@ def _delete(self, req, id):
authorize(context)

try:
flavor = instance_types.get_instance_type_by_flavor_id(id)
flavor = instance_types.get_instance_type_by_flavor_id(
id, read_deleted="no")
except exception.NotFound, e:
raise webob.exc.HTTPNotFound(explanation=str(e))

Expand Down
Expand Up @@ -25,11 +25,13 @@
from nova.tests.api.openstack import fakes


def fake_get_instance_type_by_flavor_id(flavorid):
def fake_get_instance_type_by_flavor_id(flavorid, read_deleted='yes'):
if flavorid == 'failtest':
raise exception.NotFound("Not found sucka!")
elif not str(flavorid) == '1234':
raise Exception("This test expects flavorid 1234, not %s" % flavorid)
if read_deleted != 'no':
raise test.TestingException("Should not be reading deleted")

return {
'root_gb': 1,
Expand Down Expand Up @@ -60,7 +62,8 @@ def fake_create(name, memory_mb, vcpus, root_gb, ephemeral_gb,
flavorid, swap, rxtx_factor, is_public):
if flavorid is None:
flavorid = 1234
newflavor = fake_get_instance_type_by_flavor_id(flavorid)
newflavor = fake_get_instance_type_by_flavor_id(flavorid,
read_deleted="no")

newflavor["name"] = name
newflavor["memory_mb"] = int(memory_mb)
Expand Down

0 comments on commit d741328

Please sign in to comment.