From: Zane Bitter Date: Fri, 21 Dec 2012 16:25:25 +0000 (+0100) Subject: Handle duplicate physical resources IDs X-Git-Tag: 2014.1~1041 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=244d8a21f887913d19b8b92530767d4695d1e224;p=openstack-build%2Fheat-build.git 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 --- diff --git a/heat/db/sqlalchemy/api.py b/heat/db/sqlalchemy/api.py index 5f9b2ef9..9acc4a3e 100644 --- a/heat/db/sqlalchemy/api.py +++ b/heat/db/sqlalchemy/api.py @@ -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): diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index cc92a5e5..16e41f5c 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -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,