Handle duplicate physical resources IDs

Because the unit tests create multiple stacks in different tenants with the
same physical resource ID, the database lookup code must change to
accomodate this.

This enables us to add a unit test for the describe_stack_resources RPC
API call for the case where we pass a physical resource ID to lookup.

Change-Id: Id37b15bee595ba10f207235a3ff59526e4423be6
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2012-12-21 17:25:25 +01:00
parent 8bad76c00e
commit 244d8a21f8
2 changed files with 19 additions and 7 deletions

View File

@ -76,13 +76,15 @@ def resource_get_by_name_and_stack(context, resource_name, stack_id):
def resource_get_by_physical_resource_id(context, physical_resource_id):
result = (model_query(context, models.Resource)
.filter_by(nova_instance=physical_resource_id)
.first())
if (result is not None and context is not None and
result.stack.tenant != context.tenant_id):
return None
return result
results = (model_query(context, models.Resource)
.filter_by(nova_instance=physical_resource_id)
.all())
for result in results:
if context is None or result.stack.tenant == context.tenant_id:
return result
return None
def resource_get_all(context):

View File

@ -618,6 +618,16 @@ class stackServiceTest(unittest.TestCase):
self.man.describe_stack_resources,
self.ctx, nonexist, None, 'WebServer')
def test_stack_resources_describe_physid(self):
resources = self.man.describe_stack_resources(self.ctx,
self.stack_identity,
None, None)
phys_id = resources[0]['physical_resource_id']
result = self.man.describe_stack_resources(self.ctx,
None, phys_id, None)
self.assertEqual(result, resources)
def test_stack_resources_describe_nonexist_physid(self):
self.assertRaises(AttributeError,
self.man.describe_stack_resources,