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 :param purge_missing: remove any environments from the plan environment
that aren't included in the environments map that aren't included in the environments map
defaults to False 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 :return: the updated plan environment
""" """
def __init__(self, environments, def __init__(self, environments,
container=constants.DEFAULT_CONTAINER_NAME, container=constants.DEFAULT_CONTAINER_NAME,
purge_missing=False): purge_missing=False, sort_environments=False):
super(UpdateCapabilitiesAction, self).__init__() super(UpdateCapabilitiesAction, self).__init__()
self.container = container self.container = container
self.environments = environments self.environments = environments
self.purge_missing = purge_missing self.purge_missing = purge_missing
self.sort_environments = sort_environments
def run(self, context): def run(self, context):
swift = self.get_object_client(context) swift = self.get_object_client(context)
@ -193,22 +197,24 @@ class UpdateCapabilitiesAction(base.TripleOAction):
self.cache_delete(context, self.container, "tripleo.parameters.get") self.cache_delete(context, self.container, "tripleo.parameters.get")
# get the capabilities-map content to perform the environment ordering if self.sort_environments:
try: # get the capabilities-map content to perform the environment
swift = self.get_object_client(context) # ordering
map_file = swift.get_object( try:
self.container, 'capabilities-map.yaml') swift = self.get_object_client(context)
capabilities = yaml.safe_load(map_file[1]) map_file = swift.get_object(
except swiftexceptions.ClientException as err: self.container, 'capabilities-map.yaml')
err_msg = ("Error retrieving capabilities-map.yaml for " capabilities = yaml.safe_load(map_file[1])
"plan %s: %s" % (self.container, err)) except swiftexceptions.ClientException as err:
LOG.exception(err_msg) err_msg = ("Error retrieving capabilities-map.yaml for "
return actions.Result(error=err_msg) "plan %s: %s" % (self.container, err))
LOG.exception(err_msg)
return actions.Result(error=err_msg)
ordered_env = plan_utils.apply_environments_order( ordered_env = plan_utils.apply_environments_order(
capabilities, env.get('environments', [])) capabilities, env.get('environments', []))
env['environments'] = ordered_env env['environments'] = ordered_env
try: try:
plan_utils.put_env(swift, env) 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/overcloud-default-env.yaml
- path: /path/to/ceph-storage-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 = ( swift.get_object.side_effect = (
({}, mocked_env), ({}, mocked_env),
({}, MAPPING_YAML_CONTENTS)) ({}, MAPPING_YAML_CONTENTS))
@ -258,7 +298,7 @@ class UpdateCapabilitiesActionTest(base.TestCase):
} }
action = heat_capabilities.UpdateCapabilitiesAction( action = heat_capabilities.UpdateCapabilitiesAction(
environments, self.container_name) environments, self.container_name, sort_environments=True)
self.assertEqual({ self.assertEqual({
'name': 'test-container', 'name': 'test-container',
'environments': [ 'environments': [
@ -289,9 +329,7 @@ class UpdateCapabilitiesActionTest(base.TestCase):
- path: /path/to/overcloud-default-env.yaml - path: /path/to/overcloud-default-env.yaml
- path: /path/to/ceph-storage-env.yaml - path: /path/to/ceph-storage-env.yaml
""" """
swift.get_object.side_effect = ( swift.get_object.return_value = ({}, mocked_env)
({}, mocked_env),
({}, MAPPING_YAML_CONTENTS))
get_object_client_mock.return_value = swift get_object_client_mock.return_value = swift
environments = { environments = {