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
This commit is contained in:
Steven Hardy 2017-03-10 11:15:26 +00:00
parent 91395e9967
commit 0c1ed05bb5
2 changed files with 46 additions and 2 deletions

View File

@ -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

View File

@ -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(