From 152b42c46ca58d9b057fb75b3b5918849a9fd5f0 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 10 Dec 2019 10:05:30 -0500 Subject: [PATCH] config: refactor how per step tasks are generated The per step tasks generation was introduced by: I4d864f374d6f840585fafef2c7678e55c154898e This patch is refactoring a little bit so we can easily re-use that interface for the other tasks. It introduces a new constant: PER_STEP_TASKS It's a list of tasks that are "per step" ready. Note about the 'else' in tripleo_common/utils/config.py : Once all tasks are adapted in THT to run per step, we will be able to move this condition to the upper level We include it here to allow the CI to pass until THT changed is not merged. Backport note: Included in this backport is the switch in tripleo_common/tests/utils/test_config.py from UPGRADE_STEPS_MAX to DEFAULT_STEPS_MAX to maintain a functional result. Change-Id: Ie03084bb599b7b06aeeb321d2a7938a908487788 (cherry picked from commit d9c82d8c79c33f261e4335f2ffa09bd4e44fd719) (cherry picked from commit ccfa1ad1949f1473d41a218cfa3ed85d95f471ce) --- tripleo_common/constants.py | 4 +++- tripleo_common/tests/utils/test_config.py | 2 +- tripleo_common/utils/config.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tripleo_common/constants.py b/tripleo_common/constants.py index 7d19ebc79..5c3935ddc 100644 --- a/tripleo_common/constants.py +++ b/tripleo_common/constants.py @@ -211,4 +211,6 @@ MISTRAL_WORK_DIR = '/var/lib/mistral' EXCLUSIVE_NEUTRON_DRIVERS = ['ovn', 'openvswitch'] -UPGRADE_STEPS_MAX = 6 +DEFAULT_STEPS_MAX = 6 + +PER_STEP_TASKS = ['upgrade_tasks'] diff --git a/tripleo_common/tests/utils/test_config.py b/tripleo_common/tests/utils/test_config.py index 908abcf71..40ac34dd4 100644 --- a/tripleo_common/tests/utils/test_config.py +++ b/tripleo_common/tests/utils/test_config.py @@ -163,7 +163,7 @@ class TestConfig(base.TestCase): for role in fake_role: filedir = os.path.join(self.tmp_dir, role) os.makedirs(filedir) - for step in range(constants.UPGRADE_STEPS_MAX): + for step in range(constants.DEFAULT_STEPS_MAX): filepath = os.path.join(filedir, "upgrade_tasks_step%s.yaml" % step) playbook_tasks = self.config._write_tasks_per_step( diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index 8eb0f7054..0d2ed61d4 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -223,15 +223,18 @@ class Config(object): role_group_vars[role_name] = {} role_group_vars[role_name].update(role[config]) else: - # NOTE(jfrancoa): Move this upgrade_tasks condition to the - # upper level once THT is adapted. We include it here to - # allow the CI to pass until THT changed is not merged. - if config == 'upgrade_tasks': - for i in range(constants.UPGRADE_STEPS_MAX): + # NOTE(emilien): Move this condition to the + # upper level once THT is adapted for all tasks to be + # run per step. + # We include it here to allow the CI to pass until THT + # changed is not merged. + if config in constants.PER_STEP_TASKS: + for i in range(constants.DEFAULT_STEPS_MAX): filepath = os.path.join(role_path, '%s_step%s.yaml' % (config, i)) self._write_tasks_per_step(role[config], role_name, filepath, i) + try: data = role[config] except KeyError as e: