From e073112c1db2910dceb034ca2d42884c3213f860 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Wed, 22 Jul 2020 09:27:35 -0400 Subject: [PATCH] Generate a play per step for external_deploy_tasks external_deploy_tasks will now be written out in per step files in the config download directory. This will allow including the task files for a specific step only at that step, and saving time by not having to skip so many tasks. Change-Id: I7ded2cb74afe73eab5c423fcb31ec9046ea47790 (cherry picked from commit eddc1e60941b96310d96a26bfb8d403993547249) --- tripleo_common/constants.py | 4 +++- tripleo_common/tests/fake_config/fakes.py | 5 ++++- tripleo_common/tests/utils/test_config.py | 7 ++++++- tripleo_common/utils/config.py | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tripleo_common/constants.py b/tripleo_common/constants.py index dfcd22a6f..85e26b114 100644 --- a/tripleo_common/constants.py +++ b/tripleo_common/constants.py @@ -208,7 +208,9 @@ TRIPLEO_NETWORK_CONFIG_RESOURCE = 'NetworkConfig' HOST_NETWORK = 'ctlplane' -EXTERNAL_TASKS = ['external_deploy_tasks'] +# The key is different in RoleConfig than in RoleData, so we need both so they +# are correctly found. +EXTERNAL_TASKS = ['external_deploy_tasks', 'external_deploy_steps_tasks'] ANSIBLE_ERRORS_FILE = 'ansible-errors.json' diff --git a/tripleo_common/tests/fake_config/fakes.py b/tripleo_common/tests/fake_config/fakes.py index 18f579f08..97c857041 100644 --- a/tripleo_common/tests/fake_config/fakes.py +++ b/tripleo_common/tests/fake_config/fakes.py @@ -29,7 +29,10 @@ FAKE_STACK = { 'outputs': [ {'output_key': 'RoleConfig', 'output_value': { - 'foo_config': 'foo'}}, + 'foo_config': 'foo', + 'external_deploy_steps_tasks': [{'name': 'Fake external task', + 'debug': 'name=hello', + 'when': 'step|int == 1'}]}}, {'output_key': 'HostnameNetworkConfigMap', 'output_value': {}}, {'output_key': 'RoleData', diff --git a/tripleo_common/tests/utils/test_config.py b/tripleo_common/tests/utils/test_config.py index b04508a50..208349d26 100644 --- a/tripleo_common/tests/utils/test_config.py +++ b/tripleo_common/tests/utils/test_config.py @@ -59,7 +59,7 @@ class TestConfig(base.TestCase): 'service_metadata_settings', 'service_names', 'upgrade_batch_tasks', 'upgrade_tasks', - 'external_deploy_tasks'] + 'external_deploy_steps_tasks'] heat = mock.MagicMock() heat.stacks.get.return_value = fakes.create_tht_stack() @@ -74,6 +74,11 @@ class TestConfig(base.TestCase): mock_mkdir.assert_called() expected_calls = [] for config in config_type_list: + if 'external' in config: + for step in range(constants.DEFAULT_STEPS_MAX): + expected_calls += [call('/tmp/tht/%s_step%s.yaml' % + (config, step))] + for role in fake_role: if 'external' in config: continue diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index 0a0ca34e4..7809dc950 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -285,6 +285,16 @@ class Config(object): role_config = self.get_role_config() for config_name, config in six.iteritems(role_config): + + # External tasks are in RoleConfig and not defined per role. + # So we don't use the RoleData to create the per step playbooks. + if config_name in constants.EXTERNAL_TASKS: + for i in range(constants.DEFAULT_STEPS_MAX): + filepath = os.path.join(config_dir, + '%s_step%s.yaml' + % (config_name, i)) + self._write_tasks_per_step(config, filepath, i) + conf_path = os.path.join(config_dir, config_name) # Add .yaml extension only if there's no extension already if '.' not in conf_path: