Returns project info while getting sd with admin context
This change adds project information of software configs if using admin context. Change-Id: Ia26919aa1177a9366c65710becb2097b79e02445 Closes-Bug: #1646312
This commit is contained in:
parent
b6e1be2f7a
commit
eaca4eb51b
@ -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
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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 = (
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user