]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Handle duplicate physical resources IDs
authorZane Bitter <zbitter@redhat.com>
Fri, 21 Dec 2012 16:25:25 +0000 (17:25 +0100)
committerZane Bitter <zbitter@redhat.com>
Fri, 21 Dec 2012 17:52:21 +0000 (18:52 +0100)
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>
heat/db/sqlalchemy/api.py
heat/tests/test_engine_service.py

index 5f9b2ef9da9ca3610761e70b6ce99bd24fb33140..9acc4a3e0aa289415109d30da9837ce9505f641a 100644 (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):
index cc92a5e5487944c53f66c9af86798a48c7f9a5a0..16e41f5c376b11716ebe40f5a46c081d39ef7653 100644 (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,