diff --git a/tripleo_common/tests/fake_config/fakes.py b/tripleo_common/tests/fake_config/fakes.py index c6b3a751d..fbe6d0cf2 100644 --- a/tripleo_common/tests/fake_config/fakes.py +++ b/tripleo_common/tests/fake_config/fakes.py @@ -50,13 +50,15 @@ FAKE_STACK = { 'upgrade_batch_tasks': [], 'upgrade_tasks': [{'name': 'Stop fake service', 'service': 'name=fake state=stopped', - 'tags': 'step1', - 'when': 'existingcondition'}, + 'when': ['nova_api_enabled.rc == 0', + 'httpd_enabled.rc != 0', + 'step|int == 1']}, {'name': 'Stop nova-compute service', 'service': 'name=openstack-nova-compute ' 'state=stopped', - 'tags': 'step1', - 'when': ['existing', 'list']}] + 'when': ['nova_compute_enabled.rc == 0', + 'step|int == 2', 'existing', + 'list']}] }, 'FakeController': { 'config_settings': {'tripleo::haproxy::user': 'admin'}, @@ -75,7 +77,7 @@ FAKE_STACK = { 'upgrade_batch_tasks': [], 'upgrade_tasks': [{'name': 'Stop fake service', 'service': 'name=fake state=stopped', - 'tags': 'step1'}]}}}]} + 'when': 'step|int == 1'}]}}}]} def create_to_dict_mock(**kwargs): diff --git a/tripleo_common/tests/utils/test_config.py b/tripleo_common/tests/utils/test_config.py index 1ef9fa014..ef9d9e4ed 100644 --- a/tripleo_common/tests/utils/test_config.py +++ b/tripleo_common/tests/utils/test_config.py @@ -124,22 +124,22 @@ class TestConfig(base.TestCase): expected_tasks = {'FakeController': [{'name': 'Stop fake service', 'service': 'name=fake ' 'state=stopped', - 'tags': 'step1', 'when': 'step|int == 1'}], 'FakeCompute': [{'name': 'Stop fake service', 'service': 'name=fake state=stopped', - 'tags': 'step1', - 'when': ['step|int == 1', - 'existingcondition']}, + 'when': ['nova_api_enabled.rc == 0', + 'httpd_enabled.rc != 0', + 'step|int == 1']}, {'name': 'Stop nova-' 'compute service', 'service': 'name=openstack-nova-' 'compute state=stopped', - 'tags': 'step1', - 'when': ['step|int == 1', - 'existing', 'list']}]} + 'when': [ + 'nova_compute_enabled.rc == 0', + 'step|int == 2', 'existing', + 'list']}]} for role in fake_role: filedir = os.path.join(self.tmp_dir, role) os.makedirs(filedir) diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index ca35cb87b..9f2e2b8bf 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -101,34 +101,24 @@ class Config(object): os.O_WRONLY | os.O_CREAT, 0o600), 'w') - def _step_tags_to_when(self, sorted_tasks): - for task in sorted_tasks: - tag = task.get('tags', '') - match = re.search('step([0-9]+)', tag) - if match: - step = match.group(1) - whenexpr = task.get('when', None) - if whenexpr is None: - task.update({"when": "step|int == %s" % step}) - else: - # Handle when: foo and a list of when conditionals - if not isinstance(whenexpr, list): - whenexpr = [whenexpr] - for w in whenexpr: - when_exists = re.search('step|int == [0-9]', "%s" % w) - if when_exists: - break - if when_exists: - # Skip to the next task, - # there is an existing 'step|int == N' - continue - whenexpr.insert(0, "step|int == %s" % step) - task['when'] = whenexpr - def _write_playbook_get_tasks(self, tasks, role, filepath): playbook = [] - sorted_tasks = sorted(tasks, key=lambda x: x.get('tags', None)) - self._step_tags_to_when(sorted_tasks) + + def get_key(task): + whenexpr = task.get('when', None) + if whenexpr is None: + return '' + if not isinstance(whenexpr, list): + whenexpr = [whenexpr] + for w in whenexpr: + # make \|int optional incase forgotten; use only step digit: + match = re.search('step(\|int)? == ([0-9]+)', "%s" % w) + if match: + matches = len(match.groups()) + return match.group(matches) + return '' + + sorted_tasks = sorted(tasks, key=get_key) playbook.append({'name': '%s playbook' % role, 'hosts': role, 'tasks': sorted_tasks})