diff --git a/heat/engine/api.py b/heat/engine/api.py index a5ad74fe3..cdbf215b4 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -569,7 +569,7 @@ def format_validate_parameter(param): return res -def format_software_config(sc, detail=True): +def format_software_config(sc, detail=True, include_project=False): if sc is None: return result = { @@ -584,6 +584,9 @@ def format_software_config(sc, detail=True): result[rpc_api.SOFTWARE_CONFIG_INPUTS] = sc.config['inputs'] result[rpc_api.SOFTWARE_CONFIG_OUTPUTS] = sc.config['outputs'] result[rpc_api.SOFTWARE_CONFIG_OPTIONS] = sc.config['options'] + + if include_project: + result[rpc_api.SOFTWARE_CONFIG_PROJECT] = sc.tenant return result diff --git a/heat/engine/service_software_config.py b/heat/engine/service_software_config.py index 7f433c797..72801e025 100644 --- a/heat/engine/service_software_config.py +++ b/heat/engine/service_software_config.py @@ -47,7 +47,9 @@ class SoftwareConfigService(object): cnxt, limit=limit, marker=marker) - result = [api.format_software_config(sc, detail=False) for sc in scs] + result = [api.format_software_config(sc, detail=False, + include_project=cnxt.is_admin) + for sc in scs] return result def create_software_config(self, cnxt, group, name, config, diff --git a/heat/rpc/api.py b/heat/rpc/api.py index 403971b73..d2d2dd4cf 100644 --- a/heat/rpc/api.py +++ b/heat/rpc/api.py @@ -218,7 +218,8 @@ SOFTWARE_CONFIG_KEYS = ( SOFTWARE_CONFIG_INPUTS, SOFTWARE_CONFIG_OUTPUTS, SOFTWARE_CONFIG_OPTIONS, - SOFTWARE_CONFIG_CREATION_TIME + SOFTWARE_CONFIG_CREATION_TIME, + SOFTWARE_CONFIG_PROJECT ) = ( 'id', 'name', @@ -227,7 +228,8 @@ SOFTWARE_CONFIG_KEYS = ( 'inputs', 'outputs', 'options', - 'creation_time' + 'creation_time', + 'project' ) SOFTWARE_DEPLOYMENT_KEYS = ( diff --git a/heat/tests/engine/service/test_software_config.py b/heat/tests/engine/service/test_software_config.py index 17328d44d..32cb46ecb 100644 --- a/heat/tests/engine/service/test_software_config.py +++ b/heat/tests/engine/service/test_software_config.py @@ -81,12 +81,13 @@ class SoftwareConfigServiceTest(common.HeatTestCase): def _create_software_config( self, group='Heat::Shell', name='config_mysql', config=None, - inputs=None, outputs=None, options=None): + inputs=None, outputs=None, options=None, context=None): + cntx = context if context else self.ctx inputs = inputs or [] outputs = outputs or [] options = options or {} return self.engine.create_software_config( - self.ctx, group, name, config, inputs, outputs, options) + cntx, group, name, config, inputs, outputs, options) def _create_dummy_config_object(self): obj_config = software_config_object.SoftwareConfig() @@ -107,14 +108,27 @@ class SoftwareConfigServiceTest(common.HeatTestCase): def test_list_software_configs(self): config = self._create_software_config() - config_id = config['id'] self.assertIsNotNone(config) + config_id = config['id'] configs = self.engine.list_software_configs(self.ctx) self.assertIsNotNone(configs) config_ids = [x['id'] for x in configs] self.assertIn(config_id, config_ids) + admin_cntx = utils.dummy_context(is_admin=True) + + admin_config = self._create_software_config(context=admin_cntx) + admin_config_id = admin_config['id'] + configs = self.engine.list_software_configs(admin_cntx) + self.assertIsNotNone(configs) + config_ids = [x['id'] for x in configs] + project_ids = [x['project'] for x in configs] + self.assertEqual(2, len(project_ids)) + self.assertEqual(2, len(config_ids)) + self.assertIn(config_id, config_ids) + self.assertIn(admin_config_id, config_ids) + def test_show_software_config(self): config_id = str(uuid.uuid4()) diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index 82e79ac10..9fc1167a0 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -1028,6 +1028,7 @@ class FormatSoftwareConfigDeploymentTest(common.HeatTestCase): 'options': {}, 'config': '#!/bin/bash\n' } + config.tenant = str(uuid.uuid4()) return config def _dummy_software_deployment(self): @@ -1055,6 +1056,17 @@ class FormatSoftwareConfigDeploymentTest(common.HeatTestCase): self.assertEqual({}, result['options']) self.assertEqual(heat_timeutils.isotime(self.now), result['creation_time']) + self.assertNotIn('project', result) + + result = api.format_software_config(config, include_project=True) + self.assertIsNotNone(result) + self.assertEqual([{'name': 'bar'}], result['inputs']) + self.assertEqual([{'name': 'result'}], result['outputs']) + self.assertEqual([{'name': 'result'}], result['outputs']) + self.assertEqual({}, result['options']) + self.assertEqual(heat_timeutils.isotime(self.now), + result['creation_time']) + self.assertIn('project', result) def test_format_software_config_none(self): self.assertIsNone(api.format_software_config(None))