]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Allow REST stack lookup by ARN
authorSteve Baker <sbaker@redhat.com>
Wed, 6 Mar 2013 03:22:58 +0000 (16:22 +1300)
committerSteve Baker <sbaker@redhat.com>
Wed, 6 Mar 2013 20:09:31 +0000 (09:09 +1300)
This uses the same approach as the cfn api, which assumes the stack
name is an arn, before falling back to an identify_stack call.

Change-Id: I64e9826fa58e05863e9459d3aab041a8d7997405
Fixes: Bug #1131759
heat/api/openstack/v1/stacks.py
heat/tests/test_api_openstack_v1.py

index 162890a18bc36adc7c24afe74768258d6119c6d1..dc522e4efb937682945e14bace713072d14da079 100644 (file)
@@ -21,6 +21,7 @@ import itertools
 from webob import exc
 
 from heat.api.openstack.v1 import util
+from heat.common import identifier
 from heat.common import wsgi
 from heat.common import template_format
 from heat.rpc import api as engine_api
@@ -190,12 +191,14 @@ class StackController(object):
         """
         Redirect to the canonical URL for a stack
         """
-
         try:
-            identity = self.engine.identify_stack(req.context,
-                                                  stack_name)
-        except rpc_common.RemoteError as ex:
-            return util.remote_error(ex)
+            identity = dict(identifier.HeatIdentifier.from_arn(stack_name))
+        except ValueError:
+            try:
+                identity = self.engine.identify_stack(req.context,
+                                                      stack_name)
+            except rpc_common.RemoteError as ex:
+                return util.remote_error(ex)
 
         location = util.make_url(req, identity)
         if path:
index d1a5edebf17288df5816446250661973b35b2219..ffac4e9c16e9433c4ca72de5e2cdbc44917b60de 100644 (file)
@@ -459,6 +459,22 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
             self.fail('No redirect generated')
         self.m.VerifyAll()
 
+    def test_lookup_arn(self):
+        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')
+
+        req = self._get('/stacks%s' % identity.arn_url_path())
+
+        self.m.ReplayAll()
+
+        try:
+            result = self.controller.lookup(req, tenant_id=identity.tenant,
+                                            stack_name=identity.arn())
+        except webob.exc.HTTPFound as found:
+            self.assertEqual(found.location, self._url(identity))
+        else:
+            self.fail('No redirect generated')
+        self.m.VerifyAll()
+
     def test_lookup_nonexistant(self):
         stack_name = 'wibble'