Add to resource_schema returning description

Add to resource_schema command ability to return
resource description.

@APIImpact
@DocImpact

Change-Id: I148bb7764af4db45b75ce63d7fa58daa210b3ed4
Closes-bug: #1558049
This commit is contained in:
Peter Razumovsky 2016-05-06 15:43:35 +03:00
parent 42bfc8a282
commit f5b64b3e4d
8 changed files with 39 additions and 16 deletions

View File

@ -271,6 +271,7 @@ Request
- tenant_id: tenant_id
- type_name: type_name
- with_description: with_description
Response Parameters
@ -285,6 +286,7 @@ Response Parameters
- attributes: attributes
- type: type
- properties: properties
- description: resource_description
- resource_type: resource_type

View File

@ -659,9 +659,11 @@ class StackController(object):
}
@util.policy_enforce
def resource_schema(self, req, type_name):
def resource_schema(self, req, type_name, with_description=False):
"""Returns the schema of the given resource type."""
return self.rpc_client.resource_schema(req.context, type_name)
return self.rpc_client.resource_schema(
req.context, type_name,
self._extract_bool_param('with_description', with_description))
@util.policy_enforce
def generate_template(self, req, type_name):

View File

@ -1487,11 +1487,12 @@ class EngineService(service.Service):
)
return functions
def resource_schema(self, cnxt, type_name):
def resource_schema(self, cnxt, type_name, with_description=False):
"""Return the schema of the specified type.
:param cnxt: RPC context.
:param type_name: Name of the resource type to obtain the schema of.
:param with_description: Return result with description or not.
"""
self.resource_enforcer.enforce(cnxt, type_name)
try:
@ -1532,13 +1533,18 @@ class EngineService(service.Service):
schema = attributes.Schema.from_attribute(schema_data)
yield name, dict(schema)
return {
result = {
rpc_api.RES_SCHEMA_RES_TYPE: type_name,
rpc_api.RES_SCHEMA_PROPERTIES: dict(properties_schema()),
rpc_api.RES_SCHEMA_ATTRIBUTES: dict(attributes_schema()),
rpc_api.RES_SCHEMA_SUPPORT_STATUS:
resource_class.support_status.to_dict(),
resource_class.support_status.to_dict()
}
if with_description:
docstring = resource_class.__doc__
description = api.build_resource_description(docstring)
result[rpc_api.RES_SCHEMA_DESCRIPTION] = description
return result
def generate_template(self, cnxt, type_name, template_type='cfn'):
"""Generate a template based on the specified type.

View File

@ -78,9 +78,9 @@ RES_KEYS = (
RES_SCHEMA_KEYS = (
RES_SCHEMA_RES_TYPE, RES_SCHEMA_PROPERTIES, RES_SCHEMA_ATTRIBUTES,
RES_SCHEMA_SUPPORT_STATUS,
RES_SCHEMA_SUPPORT_STATUS, RES_SCHEMA_DESCRIPTION
) = (
RES_TYPE, 'properties', 'attributes', 'support_status'
RES_TYPE, 'properties', 'attributes', 'support_status', 'description'
)
EVENT_KEYS = (

View File

@ -469,13 +469,17 @@ class EngineClient(object):
'list_template_functions', template_version=template_version),
version='1.13')
def resource_schema(self, ctxt, type_name):
def resource_schema(self, ctxt, type_name, with_description=False):
"""Get the schema for a resource type.
:param ctxt: RPC context.
:param with_description: Return resource with description or not.
"""
return self.call(ctxt, self.make_msg('resource_schema',
type_name=type_name))
return self.call(ctxt,
self.make_msg('resource_schema',
type_name=type_name,
with_description=with_description),
version='1.30')
def generate_template(self, ctxt, type_name, template_type='cfn'):
"""Generate a template based on the specified type.

View File

@ -2610,7 +2610,9 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
('resource_schema', {'type_name': type_name})
('resource_schema', {'type_name': type_name,
'with_description': False}),
version='1.30'
).AndReturn(engine_response)
self.m.ReplayAll()
response = self.controller.resource_schema(req,
@ -2629,7 +2631,9 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
('resource_schema', {'type_name': type_name})
('resource_schema', {'type_name': type_name,
'with_description': False}),
version='1.30'
).AndRaise(tools.to_remote_error(error))
self.m.ReplayAll()
@ -2650,7 +2654,9 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
('resource_schema', {'type_name': type_name})
('resource_schema', {'type_name': type_name,
'with_description': False}),
version='1.30'
).AndRaise(tools.to_remote_error(error))
self.m.ReplayAll()

View File

@ -115,9 +115,11 @@ class ResourceTypeTest(common.HeatTestCase):
'message': None,
'previous_status': None
},
'description': 'No description given'
}
schema = self.eng.resource_schema(self.ctx, type_name=type_name)
schema = self.eng.resource_schema(self.ctx, type_name=type_name,
with_description=True)
self.assertEqual(expected, schema)
def test_resource_schema_with_attr_type(self):
@ -140,7 +142,7 @@ class ResourceTypeTest(common.HeatTestCase):
'version': None,
'message': None,
'previous_status': None
},
}
}
schema = self.eng.resource_schema(self.ctx, type_name=type_name)
self.assertEqual(expected, schema)

View File

@ -226,7 +226,8 @@ class EngineRpcAPITestCase(common.HeatTestCase):
version='1.30')
def test_resource_schema(self):
self._test_engine_api('resource_schema', 'call', type_name="TYPE")
self._test_engine_api('resource_schema', 'call', type_name="TYPE",
with_description=False, version='1.30')
def test_generate_template(self):
self._test_engine_api('generate_template', 'call',