Only delete workflows with the tripleo-common-managed tag
The new workflow tag allows us to detect tripleo-common workflows. It is
safe to delete and reload these. Workflows that come from other places
shouldn't be removed.
There is some upgrade logic here that handles the O -> P upgrade, as on
the first run the workflows will not have the tripleo-common-managed
tag. If the tag isn't found, we revert to the current behaviour and then
on future undercloud installations this wont be a problem.
The new test is a duplication of a previous test but with multiple
workflows that have tripleo in the name. Only the one with the tag is
deleted.
Depends-On: Ieeb51f8e705b8988fb4d0f5d17d7fce6b5b04f36
Closes-Bug: #1715389
Change-Id: I84d441daedcafe686b9576d47b037977b493dbc7
(cherry picked from commit d6c0636421
)
This commit is contained in:
parent
3737e1fbc5
commit
72ce841253
|
@ -1011,6 +1011,48 @@ class TestPostConfig(base.BaseTestCase):
|
|||
mock_workflows = [mock.Mock() for m in range(2)]
|
||||
mock_workflows[0].name = 'foo'
|
||||
mock_workflows[1].name = 'tripleo.bar'
|
||||
mock_workflows[0].tags = []
|
||||
mock_workflows[1].tags = []
|
||||
mock_mistral.workflows.list.return_value = mock_workflows
|
||||
mock_listdir.return_value = ['foo.yaml', 'bar.yaml']
|
||||
undercloud._post_config_mistral(instack_env, mock_mistral, mock_swift)
|
||||
self.assertEqual([mock.call('tripleo.bar')],
|
||||
mock_mistral.workbooks.delete.mock_calls)
|
||||
self.assertEqual([mock.call('tripleo.bar')],
|
||||
mock_mistral.workflows.delete.mock_calls)
|
||||
self.assertEqual([mock.call(undercloud.PATHS.WORKBOOK_PATH +
|
||||
'/foo.yaml'),
|
||||
mock.call(undercloud.PATHS.WORKBOOK_PATH +
|
||||
'/bar.yaml')],
|
||||
mock_mistral.workbooks.create.mock_calls)
|
||||
mock_cmce.assert_called_once_with(instack_env, mock_mistral)
|
||||
mock_migrate.assert_called_once_with(mock_mistral, mock_swift,
|
||||
['hut8'])
|
||||
mock_create.assert_called_once_with(mock_mistral, ['hut8'])
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
@mock.patch('os.listdir')
|
||||
@mock.patch('instack_undercloud.undercloud._create_mistral_config_'
|
||||
'environment')
|
||||
@mock.patch('instack_undercloud.undercloud._migrate_plans')
|
||||
@mock.patch('instack_undercloud.undercloud._create_default_plan')
|
||||
def test_post_config_mistral_with_tags(self, mock_create, mock_migrate,
|
||||
mock_cmce, mock_listdir,
|
||||
mock_isfile):
|
||||
instack_env = {}
|
||||
mock_mistral = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_swift.get_account.return_value = [None, [{'name': 'hut8'}]]
|
||||
|
||||
mock_workbooks = [mock.Mock() for m in range(2)]
|
||||
mock_workbooks[0].name = 'foo'
|
||||
mock_workbooks[1].name = 'tripleo.bar'
|
||||
mock_mistral.workbooks.list.return_value = mock_workbooks
|
||||
mock_workflows = [mock.Mock() for m in range(2)]
|
||||
mock_workflows[0].name = 'tripleo.foo'
|
||||
mock_workflows[1].name = 'tripleo.bar'
|
||||
mock_workflows[0].tags = []
|
||||
mock_workflows[1].tags = ['tripleo-common-managed', ]
|
||||
mock_mistral.workflows.list.return_value = mock_workflows
|
||||
mock_listdir.return_value = ['foo.yaml', 'bar.yaml']
|
||||
undercloud._post_config_mistral(instack_env, mock_mistral, mock_swift)
|
||||
|
|
|
@ -1532,12 +1532,31 @@ def _prepare_ssh_environment(mistral):
|
|||
|
||||
def _post_config_mistral(instack_env, mistral, swift):
|
||||
LOG.info('Configuring Mistral workbooks')
|
||||
|
||||
for workbook in [w for w in mistral.workbooks.list()
|
||||
if 'tripleo' in w.name]:
|
||||
mistral.workbooks.delete(workbook.name)
|
||||
for workflow in [w for w in mistral.workflows.list()
|
||||
if 'tripleo' in w.name]:
|
||||
|
||||
managed_tag = 'tripleo-common-managed'
|
||||
|
||||
all_workflows = mistral.workflows.list()
|
||||
workflow_tags = set()
|
||||
for workflow in all_workflows:
|
||||
workflow_tags.update(workflow.tags)
|
||||
|
||||
# If at least one workflow is tagged, then we should only delete those.
|
||||
# Otherwise we should revert to the previous behaviour - this is required
|
||||
# for the initial upgrade.
|
||||
# TODO(d0ugal): From Q onwards we should only ever delete workflows with
|
||||
# the tripleo-common tag.
|
||||
if 'tripleo-common-managed' in workflow_tags:
|
||||
workflows_delete = [w for w in all_workflows if managed_tag in w.tags]
|
||||
else:
|
||||
workflows_delete = [w for w in all_workflows if 'tripleo' in w.name]
|
||||
|
||||
for workflow in workflows_delete:
|
||||
mistral.workflows.delete(workflow.name)
|
||||
|
||||
for workbook in [f for f in os.listdir(PATHS.WORKBOOK_PATH)
|
||||
if os.path.isfile(os.path.join(PATHS.WORKBOOK_PATH, f))]:
|
||||
mistral.workbooks.create(os.path.join(PATHS.WORKBOOK_PATH, workbook))
|
||||
|
|
Loading…
Reference in New Issue