Merge "ReST API: Add an API for retrieving resource schemata"

This commit is contained in:
Jenkins 2013-08-12 23:59:49 +00:00 committed by Gerrit Code Review
commit 1d1c7927d1
3 changed files with 72 additions and 4 deletions

View File

@ -49,6 +49,10 @@ class API(wsgi.Router):
"/resource_types",
action="list_resource_types",
conditions={'method': 'GET'})
stack_mapper.connect("resource_schema",
"/resource_types/{type_name}",
action="resource_schema",
conditions={'method': 'GET'})
stack_mapper.connect("generate_template",
"/resource_types/{type_name}/template",
action="generate_template",

View File

@ -330,6 +330,13 @@ class StackController(object):
"""
return {'resource_types': self.engine.list_resource_types(req.context)}
@util.tenant_local
def resource_schema(self, req, type_name):
"""
Returns the schema of the given resource type.
"""
return self.engine.resource_schema(req.context, type_name)
@util.tenant_local
def generate_template(self, req, type_name):
"""

View File

@ -1167,10 +1167,6 @@ class StackControllerTest(ControllerTest, HeatTestCase):
def test_list_resource_types_error(self):
req = self._get('/resource_types')
engine_response = ['AWS::EC2::Instance',
'AWS::EC2::EIP',
'AWS::EC2::EIPAssociation']
error = heat_exc.ServerError(body='')
self.m.StubOutWithMock(rpc, 'call')
rpc.call(req.context, self.topic,
@ -1188,6 +1184,56 @@ class StackControllerTest(ControllerTest, HeatTestCase):
self.assertEqual(resp.json['error']['type'], 'ServerError')
self.m.VerifyAll()
def test_resource_schema(self):
req = self._get('/resource_types/ResourceWithProps')
type_name = 'ResourceWithProps'
engine_response = {
'resource_type': type_name,
'properties': {
'Foo': {'type': 'string', 'required': False},
},
'attributes': {
'foo': {'description': 'A generic attribute'},
'Foo': {'description': 'Another generic attribute'},
},
}
self.m.StubOutWithMock(rpc, 'call')
rpc.call(req.context, self.topic,
{'namespace': None,
'method': 'resource_schema',
'args': {'type_name': type_name},
'version': self.api_version},
None).AndReturn(engine_response)
self.m.ReplayAll()
response = self.controller.resource_schema(req,
tenant_id=self.tenant,
type_name=type_name)
self.assertEqual(response, engine_response)
self.m.VerifyAll()
def test_resource_schema_nonexist(self):
req = self._get('/resource_types/BogusResourceType')
type_name = 'BogusResourceType'
error = heat_exc.ResourceTypeNotFound(type_name='BogusResourceType')
self.m.StubOutWithMock(rpc, 'call')
rpc.call(req.context, self.topic,
{'namespace': None,
'method': 'resource_schema',
'args': {'type_name': type_name},
'version': self.api_version},
None).AndRaise(to_remote_error(error))
self.m.ReplayAll()
resp = request_with_middleware(fault.FaultWrapper,
self.controller.resource_schema,
req, tenant_id=self.tenant,
type_name=type_name)
self.assertEqual(resp.json['code'], 404)
self.assertEqual(resp.json['error']['type'], 'ResourceTypeNotFound')
self.m.VerifyAll()
def test_generate_template(self):
req = self._get('/resource_types/TEST_TYPE/template')
@ -2052,6 +2098,17 @@ class RoutesTest(HeatTestCase):
'tenant_id': 'aaaa',
})
self.assertRoute(
self.m,
'/aaaa/resource_types/test_type',
'GET',
'resource_schema',
'StackController',
{
'tenant_id': 'aaaa',
'type_name': 'test_type'
})
self.assertRoute(
self.m,
'/aaaa/resource_types/test_type/template',