From 2f3f98f58d4ffe401cb542508bd62da4f14f0dbf Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 6 Mar 2013 16:22:58 +1300 Subject: [PATCH] Allow REST stack lookup by ARN 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 | 13 ++++++++----- heat/tests/test_api_openstack_v1.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index 162890a1..dc522e4e 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -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: diff --git a/heat/tests/test_api_openstack_v1.py b/heat/tests/test_api_openstack_v1.py index d1a5edeb..ffac4e9c 100644 --- a/heat/tests/test_api_openstack_v1.py +++ b/heat/tests/test_api_openstack_v1.py @@ -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' -- 2.45.2