Merge "Makes sorting environments with capabilities-map optional"

This commit is contained in:
Zuul 2018-07-26 08:50:56 +00:00 committed by Gerrit Code Review
commit 02d1c1117f
2 changed files with 63 additions and 19 deletions

View File

@ -153,16 +153,20 @@ class UpdateCapabilitiesAction(base.TripleOAction):
:param purge_missing: remove any environments from the plan environment
that aren't included in the environments map
defaults to False
:param sort_environments: use the dependencies defined in the
capabilites-map.yaml file in the plan to order
the environments
:return: the updated plan environment
"""
def __init__(self, environments,
container=constants.DEFAULT_CONTAINER_NAME,
purge_missing=False):
purge_missing=False, sort_environments=False):
super(UpdateCapabilitiesAction, self).__init__()
self.container = container
self.environments = environments
self.purge_missing = purge_missing
self.sort_environments = sort_environments
def run(self, context):
swift = self.get_object_client(context)
@ -193,22 +197,24 @@ class UpdateCapabilitiesAction(base.TripleOAction):
self.cache_delete(context, self.container, "tripleo.parameters.get")
# get the capabilities-map content to perform the environment ordering
try:
swift = self.get_object_client(context)
map_file = swift.get_object(
self.container, 'capabilities-map.yaml')
capabilities = yaml.safe_load(map_file[1])
except swiftexceptions.ClientException as err:
err_msg = ("Error retrieving capabilities-map.yaml for "
"plan %s: %s" % (self.container, err))
LOG.exception(err_msg)
return actions.Result(error=err_msg)
if self.sort_environments:
# get the capabilities-map content to perform the environment
# ordering
try:
swift = self.get_object_client(context)
map_file = swift.get_object(
self.container, 'capabilities-map.yaml')
capabilities = yaml.safe_load(map_file[1])
except swiftexceptions.ClientException as err:
err_msg = ("Error retrieving capabilities-map.yaml for "
"plan %s: %s" % (self.container, err))
LOG.exception(err_msg)
return actions.Result(error=err_msg)
ordered_env = plan_utils.apply_environments_order(
capabilities, env.get('environments', []))
ordered_env = plan_utils.apply_environments_order(
capabilities, env.get('environments', []))
env['environments'] = ordered_env
env['environments'] = ordered_env
try:
plan_utils.put_env(swift, env)

View File

@ -246,6 +246,46 @@ class UpdateCapabilitiesActionTest(base.TestCase):
- path: /path/to/overcloud-default-env.yaml
- path: /path/to/ceph-storage-env.yaml
"""
swift.get_object.return_value = ({}, mocked_env)
get_object_client_mock.return_value = swift
environments = {
'/path/to/ceph-storage-env.yaml': False,
'/path/to/network-isolation.json': False,
'/path/to/poc-custom-env.yaml': True
}
action = heat_capabilities.UpdateCapabilitiesAction(
environments, self.container_name)
self.assertEqual({
'name': 'test-container',
'environments': [
{'path': '/path/to/overcloud-default-env.yaml'},
{'path': '/path/to/poc-custom-env.yaml'}
]},
action.run(mock_ctx))
mock_cache.assert_called_once_with(
mock_ctx,
self.container_name,
"tripleo.parameters.get"
)
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'cache_delete')
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
def test_run_with_sorting_environments(self, get_object_client_mock,
mock_cache):
mock_ctx = mock.MagicMock()
# setup swift
swift = mock.MagicMock()
mocked_env = """
name: test-container
environments:
- path: /path/to/overcloud-default-env.yaml
- path: /path/to/ceph-storage-env.yaml
"""
swift.get_object.side_effect = (
({}, mocked_env),
({}, MAPPING_YAML_CONTENTS))
@ -258,7 +298,7 @@ class UpdateCapabilitiesActionTest(base.TestCase):
}
action = heat_capabilities.UpdateCapabilitiesAction(
environments, self.container_name)
environments, self.container_name, sort_environments=True)
self.assertEqual({
'name': 'test-container',
'environments': [
@ -289,9 +329,7 @@ class UpdateCapabilitiesActionTest(base.TestCase):
- path: /path/to/overcloud-default-env.yaml
- path: /path/to/ceph-storage-env.yaml
"""
swift.get_object.side_effect = (
({}, mocked_env),
({}, MAPPING_YAML_CONTENTS))
swift.get_object.return_value = ({}, mocked_env)
get_object_client_mock.return_value = swift
environments = {