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,7 +197,9 @@ class UpdateCapabilitiesAction(base.TripleOAction):
self.cache_delete(context, self.container, "tripleo.parameters.get")
# get the capabilities-map content to perform the environment ordering
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(

View File

@ -238,6 +238,46 @@ class UpdateCapabilitiesActionTest(base.TestCase):
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.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 = """
@ -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 = {