ReST API: Add a convenience redirect for resources
Since the path stacks/{stack_name}/{stack_id}/resources exists for each valid stack we can safely redirect to it from stacks/{stack_name}/resources without having to perform any further checks in the engine, so we may as well allow it. Change-Id: I0169493479f8c6840de3edad271cf98e8fd5d1da Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
parent
d892d8166c
commit
f844bf3511
20
docs/api.md
20
docs/api.md
|
@ -176,6 +176,26 @@ Parameters:
|
|||
* `stack_name` The name of the stack to look up
|
||||
* `stack_id` The unique identifier of the stack to look up
|
||||
|
||||
Find Stack Resources by Name
|
||||
----------------------------
|
||||
|
||||
```
|
||||
GET /v1/{tenant_id}/stacks/{stack_name}/resources
|
||||
```
|
||||
|
||||
Parameters:
|
||||
|
||||
* `stack_name` The name of the stack to look up
|
||||
|
||||
Result:
|
||||
|
||||
```
|
||||
HTTP/1.1 302 Found
|
||||
Location: http://heat.example.com:8004/v1/{tenant_id}/stacks/{stack_name}/{stack_id}/resources
|
||||
```
|
||||
|
||||
This is a shortcut to go directly to the list of stack resources when only the stack name is known.
|
||||
|
||||
Get Resource
|
||||
------------
|
||||
|
||||
|
|
|
@ -69,6 +69,10 @@ class API(wsgi.Router):
|
|||
stack_mapper.connect("stack_lookup",
|
||||
"/stacks/{stack_name}",
|
||||
action="lookup")
|
||||
stack_mapper.connect("stack_lookup_subpath",
|
||||
"/stacks/{stack_name}/{path:resources}",
|
||||
action="lookup",
|
||||
conditions={'method': 'GET'})
|
||||
stack_mapper.connect("stack_show",
|
||||
"/stacks/{stack_name}/{stack_id}",
|
||||
action="show",
|
||||
|
|
|
@ -210,7 +210,7 @@ class StackController(object):
|
|||
raise exc.HTTPCreated(location=util.make_url(req, result))
|
||||
|
||||
@util.tenant_local
|
||||
def lookup(self, req, stack_name, body=None):
|
||||
def lookup(self, req, stack_name, path='', body=None):
|
||||
"""
|
||||
Redirect to the canonical URL for a stack
|
||||
"""
|
||||
|
@ -221,7 +221,11 @@ class StackController(object):
|
|||
except rpc_common.RemoteError as ex:
|
||||
return util.remote_error(ex)
|
||||
|
||||
raise exc.HTTPFound(location=util.make_url(req, identity))
|
||||
location = util.make_url(req, identity)
|
||||
if path:
|
||||
location = '/'.join([location, path])
|
||||
|
||||
raise exc.HTTPFound(location=location)
|
||||
|
||||
@util.identified_stack
|
||||
def show(self, req, identity):
|
||||
|
|
|
@ -433,6 +433,49 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
req, tenant_id=self.tenant, stack_name=stack_name)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_lookup_resource(self):
|
||||
identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')
|
||||
|
||||
req = self._get('/stacks/%(stack_name)s/resources' % identity)
|
||||
|
||||
self.m.StubOutWithMock(rpc, 'call')
|
||||
rpc.call(req.context, self.topic,
|
||||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': identity.stack_name},
|
||||
'version': self.api_version},
|
||||
None).AndReturn(identity)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
try:
|
||||
result = self.controller.lookup(req, tenant_id=identity.tenant,
|
||||
stack_name=identity.stack_name,
|
||||
path='resources')
|
||||
except webob.exc.HTTPFound as found:
|
||||
self.assertEqual(found.location, self._url(identity) +
|
||||
'/resources')
|
||||
else:
|
||||
self.fail('No redirect generated')
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_lookup_resource_nonexistant(self):
|
||||
stack_name = 'wibble'
|
||||
|
||||
req = self._get('/stacks/%(stack_name)s/resources' % locals())
|
||||
|
||||
self.m.StubOutWithMock(rpc, 'call')
|
||||
rpc.call(req.context, self.topic,
|
||||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.lookup,
|
||||
req, tenant_id=self.tenant, stack_name=stack_name,
|
||||
path='resources')
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_show(self):
|
||||
identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
|
||||
|
||||
|
|
Loading…
Reference in New Issue