From f5b64b3e4d101c8400f546636f895a6082081518 Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Fri, 6 May 2016 15:43:35 +0300 Subject: [PATCH] Add to resource_schema returning description Add to resource_schema command ability to return resource description. @APIImpact @DocImpact Change-Id: I148bb7764af4db45b75ce63d7fa58daa210b3ed4 Closes-bug: #1558049 --- api-ref/source/v1/stack-templates.inc | 2 ++ heat/api/openstack/v1/stacks.py | 6 ++++-- heat/engine/service.py | 12 +++++++++--- heat/rpc/api.py | 4 ++-- heat/rpc/client.py | 10 +++++++--- heat/tests/api/openstack_v1/test_stacks.py | 12 +++++++++--- heat/tests/engine/test_resource_type.py | 6 ++++-- heat/tests/test_rpc_client.py | 3 ++- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/api-ref/source/v1/stack-templates.inc b/api-ref/source/v1/stack-templates.inc index f686e2c0e..51ff281cc 100644 --- a/api-ref/source/v1/stack-templates.inc +++ b/api-ref/source/v1/stack-templates.inc @@ -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 diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index 9a0d24d3c..31f909e7f 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -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): diff --git a/heat/engine/service.py b/heat/engine/service.py index f55017845..28f9d72f3 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -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. diff --git a/heat/rpc/api.py b/heat/rpc/api.py index fbb6af27e..3600926f6 100644 --- a/heat/rpc/api.py +++ b/heat/rpc/api.py @@ -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 = ( diff --git a/heat/rpc/client.py b/heat/rpc/client.py index 00fb97568..1f73101e2 100644 --- a/heat/rpc/client.py +++ b/heat/rpc/client.py @@ -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. diff --git a/heat/tests/api/openstack_v1/test_stacks.py b/heat/tests/api/openstack_v1/test_stacks.py index 36f046c1e..af47c031d 100644 --- a/heat/tests/api/openstack_v1/test_stacks.py +++ b/heat/tests/api/openstack_v1/test_stacks.py @@ -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() diff --git a/heat/tests/engine/test_resource_type.py b/heat/tests/engine/test_resource_type.py index bb6613809..9be79b292 100644 --- a/heat/tests/engine/test_resource_type.py +++ b/heat/tests/engine/test_resource_type.py @@ -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) diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index 743dc9076..5e1baaf47 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -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',