From 0c1ed05bb556743126af273eac11daeb47bded98 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Fri, 10 Mar 2017 11:15:26 +0000 Subject: [PATCH] UpdateCapabilitiesAction add purge_missing option Currently any paths not included in the input map are ignored, but for the CLI we have an exact list we want to set, which will be easier with this option. Change-Id: I7ebc8b657ff5ab9cc275b29b4d17053888a251ee Partial-Bug: #1635409 --- tripleo_common/actions/heat_capabilities.py | 17 ++++++++-- .../tests/actions/test_heat_capabilities.py | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tripleo_common/actions/heat_capabilities.py b/tripleo_common/actions/heat_capabilities.py index 6b6a6aa3f..246ff4582 100644 --- a/tripleo_common/actions/heat_capabilities.py +++ b/tripleo_common/actions/heat_capabilities.py @@ -145,16 +145,24 @@ class UpdateCapabilitiesAction(base.TripleOAction): Takes a list of environment files and depending on the value of the enabled flag, adds or removes them from the Mistral Environment. - :param environments: list of environments + :param environments: map of environments {'environment_path': True} + the value passed can be false for disabled + environments, these will be removed from the + mistral environment. :param container: name of the swift container / plan name + :param purge_missing: remove any environments from the mistral environment + that aren't included in the environments map + defaults to False :return: the updated mistral environment """ def __init__(self, environments, - container=constants.DEFAULT_CONTAINER_NAME): + container=constants.DEFAULT_CONTAINER_NAME, + purge_missing=False): super(UpdateCapabilitiesAction, self).__init__() self.container = container self.environments = environments + self.purge_missing = purge_missing def run(self): mistral_client = self.get_workflow_client() @@ -181,6 +189,11 @@ class UpdateCapabilitiesAction(base.TripleOAction): if found: mistral_env.variables['environments'].remove({'path': k}) + if self.purge_missing: + for env in mistral_env.variables['environments']: + if env.get('path') not in self.environments: + mistral_env.variables['environments'].remove(env) + env_kwargs = { 'name': mistral_env.name, 'variables': mistral_env.variables diff --git a/tripleo_common/tests/actions/test_heat_capabilities.py b/tripleo_common/tests/actions/test_heat_capabilities.py index 77071dbfc..a97ccf3d2 100644 --- a/tripleo_common/tests/actions/test_heat_capabilities.py +++ b/tripleo_common/tests/actions/test_heat_capabilities.py @@ -269,6 +269,37 @@ class UpdateCapabilitiesActionTest(base.TestCase): ]}, action.run()) + @mock.patch( + 'tripleo_common.actions.base.TripleOAction.get_workflow_client') + def test_run_purge_missing(self, get_workflow_client_mock): + + # setup mistral + mistral = mock.MagicMock() + mocked_env = mock.MagicMock() + mocked_env.variables = { + 'environments': [ + {'path': '/path/to/overcloud-default-env.yaml'}, + {'path': '/path/to/ceph-storage-env.yaml'}, + ] + } + mistral.environments.get.return_value = mocked_env + get_workflow_client_mock.return_value = mistral + + environments = { + '/path/to/overcloud-default-env.yaml': True, + '/path/to/network-isolation.json': False, + '/path/to/poc-custom-env.yaml': True + } + + action = heat_capabilities.UpdateCapabilitiesAction( + environments, self.container_name, True) + self.assertEqual({ + 'environments': [ + {'path': '/path/to/overcloud-default-env.yaml'}, + {'path': '/path/to/poc-custom-env.yaml'} + ]}, + action.run()) + @mock.patch( 'tripleo_common.actions.base.TripleOAction.get_object_client') @mock.patch(