diff options
author | Jordan Borean <jborean93@gmail.com> | 2023-05-18 21:49:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 21:49:07 +0200 |
commit | 8db9bd757444fba6dd23fcb067e261d877926a33 (patch) | |
tree | 6409b7bb8ee20d6efe02e77d9d24073684add0d9 /test | |
parent | command - Add option to disable argument var expansion (#80512) (diff) | |
download | ansible-8db9bd757444fba6dd23fcb067e261d877926a33.tar.xz ansible-8db9bd757444fba6dd23fcb067e261d877926a33.zip |
Remove deprecated include (#80752)
* Remove deprecated include
* Add tombstone entry for include
* Use string for date
* Use todays date
* Remove uneeded if statement
Diffstat (limited to 'test')
18 files changed, 73 insertions, 104 deletions
diff --git a/test/integration/targets/include_when_parent_is_dynamic/tasks.yml b/test/integration/targets/include_when_parent_is_dynamic/tasks.yml index 6831245c92..d500f0df7d 100644 --- a/test/integration/targets/include_when_parent_is_dynamic/tasks.yml +++ b/test/integration/targets/include_when_parent_is_dynamic/tasks.yml @@ -9,4 +9,4 @@ # perform an include task which should be static if all of the task's parents are static, otherwise it should be dynamic # this file was loaded using include_tasks, which is dynamic, so this include should also be dynamic -- include: syntax_error.yml +- include_tasks: syntax_error.yml diff --git a/test/integration/targets/include_when_parent_is_static/tasks.yml b/test/integration/targets/include_when_parent_is_static/tasks.yml index a234a3dd33..50dd2341c1 100644 --- a/test/integration/targets/include_when_parent_is_static/tasks.yml +++ b/test/integration/targets/include_when_parent_is_static/tasks.yml @@ -9,4 +9,4 @@ # perform an include task which should be static if all of the task's parents are static, otherwise it should be dynamic # this file was loaded using import_tasks, which is static, so this include should also be static -- include: syntax_error.yml +- import_tasks: syntax_error.yml diff --git a/test/integration/targets/includes/include_on_playbook_should_fail.yml b/test/integration/targets/includes/include_on_playbook_should_fail.yml index 953459dcf8..c9b1e81ac3 100644 --- a/test/integration/targets/includes/include_on_playbook_should_fail.yml +++ b/test/integration/targets/includes/include_on_playbook_should_fail.yml @@ -1 +1 @@ -- include: test_includes3.yml +- include_tasks: test_includes3.yml diff --git a/test/integration/targets/includes/roles/test_includes/handlers/main.yml b/test/integration/targets/includes/roles/test_includes/handlers/main.yml index 7d3e625f7f..453fa96d7f 100644 --- a/test/integration/targets/includes/roles/test_includes/handlers/main.yml +++ b/test/integration/targets/includes/roles/test_includes/handlers/main.yml @@ -1 +1 @@ -- include: more_handlers.yml +- import_tasks: more_handlers.yml diff --git a/test/integration/targets/includes/roles/test_includes/tasks/main.yml b/test/integration/targets/includes/roles/test_includes/tasks/main.yml index 83ca468baf..2ba1ae637a 100644 --- a/test/integration/targets/includes/roles/test_includes/tasks/main.yml +++ b/test/integration/targets/includes/roles/test_includes/tasks/main.yml @@ -17,47 +17,9 @@ # along with Ansible. If not, see <http://www.gnu.org/licenses/>. -- include: included_task1.yml a=1 b=2 c=3 - -- name: verify non-variable include params - assert: - that: - - "ca == '1'" - - "cb == '2'" - - "cc == '3'" - -- set_fact: - a: 101 - b: 102 - c: 103 - -- include: included_task1.yml a={{a}} b={{b}} c=103 - -- name: verify variable include params - assert: - that: - - "ca == 101" - - "cb == 102" - - "cc == 103" - -# Test that strings are not turned into numbers -- set_fact: - a: "101" - b: "102" - c: "103" - -- include: included_task1.yml a={{a}} b={{b}} c=103 - -- name: verify variable include params - assert: - that: - - "ca == '101'" - - "cb == '102'" - - "cc == '103'" - # now try long form includes -- include: included_task1.yml +- include_tasks: included_task1.yml vars: a: 201 b: 202 diff --git a/test/integration/targets/includes/roles/test_includes_free/tasks/main.yml b/test/integration/targets/includes/roles/test_includes_free/tasks/main.yml index 5ae7882f4c..d7bcf8eb5b 100644 --- a/test/integration/targets/includes/roles/test_includes_free/tasks/main.yml +++ b/test/integration/targets/includes/roles/test_includes_free/tasks/main.yml @@ -1,9 +1,9 @@ - name: this needs to be here debug: msg: "hello" -- include: inner.yml +- include_tasks: inner.yml with_items: - '1' -- ansible.builtin.include: inner_fqcn.yml +- ansible.builtin.include_tasks: inner_fqcn.yml with_items: - '1' diff --git a/test/integration/targets/includes/roles/test_includes_host_pinned/tasks/main.yml b/test/integration/targets/includes/roles/test_includes_host_pinned/tasks/main.yml index 7bc19faae1..c06d3febd9 100644 --- a/test/integration/targets/includes/roles/test_includes_host_pinned/tasks/main.yml +++ b/test/integration/targets/includes/roles/test_includes_host_pinned/tasks/main.yml @@ -1,6 +1,6 @@ - name: this needs to be here debug: msg: "hello" -- include: inner.yml +- include_tasks: inner.yml with_items: - '1' diff --git a/test/integration/targets/includes/runme.sh b/test/integration/targets/includes/runme.sh index e619feaf2a..8622cf6653 100755 --- a/test/integration/targets/includes/runme.sh +++ b/test/integration/targets/includes/runme.sh @@ -10,7 +10,7 @@ echo "EXPECTED ERROR: Ensure we fail if using 'include' to include a playbook." set +e result="$(ansible-playbook -i ../../inventory include_on_playbook_should_fail.yml -v "$@" 2>&1)" set -e -grep -q "ERROR! 'include' is not a valid attribute for a Play" <<< "$result" +grep -q "ERROR! 'include_tasks' is not a valid attribute for a Play" <<< "$result" ansible-playbook includes_loop_rescue.yml --extra-vars strategy=linear "$@" ansible-playbook includes_loop_rescue.yml --extra-vars strategy=free "$@" diff --git a/test/integration/targets/includes/test_includes2.yml b/test/integration/targets/includes/test_includes2.yml index a32e851384..da6b914fee 100644 --- a/test/integration/targets/includes/test_includes2.yml +++ b/test/integration/targets/includes/test_includes2.yml @@ -13,8 +13,8 @@ - role: test_includes tags: test_includes tasks: - - include: roles/test_includes/tasks/not_a_role_task.yml - - include: roles/test_includes/tasks/empty.yml + - include_tasks: roles/test_includes/tasks/not_a_role_task.yml + - include_tasks: roles/test_includes/tasks/empty.yml - assert: that: - "ca == 33000" diff --git a/test/integration/targets/includes/test_includes3.yml b/test/integration/targets/includes/test_includes3.yml index 0b4c631210..f3c4964ee8 100644 --- a/test/integration/targets/includes/test_includes3.yml +++ b/test/integration/targets/includes/test_includes3.yml @@ -1,6 +1,6 @@ - hosts: testhost tasks: - - include: test_includes4.yml + - include_tasks: test_includes4.yml with_items: ["a"] loop_control: loop_var: r diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml index d225c0f9f9..25e91f289f 100644 --- a/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml @@ -121,7 +121,10 @@ - result.cmd == "echo foo --arg=a --arg=b" - name: test includes with params - include: test_include.yml fact_name=include_params param="{{ test_input }}" + include_tasks: test_include.yml + vars: + fact_name: include_params + param: "{{ test_input }}" - name: assert the include set the correct fact for the param assert: @@ -129,7 +132,10 @@ - include_params == test_input - name: test includes with quoted params - include: test_include.yml fact_name=double_quoted_param param="this is a param with double quotes" + include_tasks: test_include.yml + vars: + fact_name: double_quoted_param + param: "this is a param with double quotes" - name: assert the include set the correct fact for the double quoted param assert: @@ -137,7 +143,10 @@ - double_quoted_param == "this is a param with double quotes" - name: test includes with single quoted params - include: test_include.yml fact_name=single_quoted_param param='this is a param with single quotes' + include_tasks: test_include.yml + vars: + fact_name: single_quoted_param + param: 'this is a param with single quotes' - name: assert the include set the correct fact for the single quoted param assert: @@ -145,7 +154,7 @@ - single_quoted_param == "this is a param with single quotes" - name: test includes with quoted params in complex args - include: test_include.yml + include_tasks: test_include.yml vars: fact_name: complex_param param: "this is a param in a complex arg with double quotes" @@ -165,7 +174,7 @@ - result.msg == "this should be debugged" - name: test conditional includes - include: test_include_conditional.yml + include_tasks: test_include_conditional.yml when: false - name: assert the nested include from test_include_conditional was not set diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml index 070888dad3..a1d8b7ce8a 100644 --- a/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml @@ -1 +1 @@ -- include: test_include_nested.yml +- include_tasks: test_include_nested.yml diff --git a/test/integration/targets/var_precedence/ansible-var-precedence-check.py b/test/integration/targets/var_precedence/ansible-var-precedence-check.py index a6c1dab0f6..b03c87b80f 100755 --- a/test/integration/targets/var_precedence/ansible-var-precedence-check.py +++ b/test/integration/targets/var_precedence/ansible-var-precedence-check.py @@ -363,9 +363,9 @@ class VarTestMaker(object): block_wrapper = [debug_task, test_task] if 'include_params' in self.features: - self.tasks.append(dict(name='including tasks', include='included_tasks.yml', vars=dict(findme='include_params'))) + self.tasks.append(dict(name='including tasks', include_tasks='included_tasks.yml', vars=dict(findme='include_params'))) else: - self.tasks.append(dict(include='included_tasks.yml')) + self.tasks.append(dict(include_tasks='included_tasks.yml')) fname = os.path.join(TESTDIR, 'included_tasks.yml') with open(fname, 'w') as f: diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 63a31a2ba1..8cbfa1dd7a 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -21,7 +21,6 @@ lib/ansible/parsing/yaml/constructor.py mypy-3.9:type-var # too many occurrence lib/ansible/parsing/yaml/constructor.py mypy-3.10:type-var # too many occurrences to ignore inline lib/ansible/parsing/yaml/constructor.py mypy-3.11:type-var # too many occurrences to ignore inline lib/ansible/keyword_desc.yml no-unwanted-files -lib/ansible/modules/_include.py validate-modules:ansible-deprecated-module lib/ansible/modules/apt.py validate-modules:parameter-invalid lib/ansible/modules/apt_repository.py validate-modules:parameter-invalid lib/ansible/modules/assemble.py validate-modules:nonexistent-parameter-documented @@ -242,5 +241,3 @@ test/units/utils/collection_loader/fixtures/collections_masked/ansible_collectio test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/__init__.py empty-init # testing that collections don't need inits test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/testcoll/__init__.py empty-init # testing that collections don't need inits test/units/utils/collection_loader/test_collection_loader.py pylint:undefined-variable # magic runtime local var splatting -lib/ansible/playbook/helpers.py pylint:ansible-deprecated-version -lib/ansible/playbook/included_file.py pylint:ansible-deprecated-version diff --git a/test/units/executor/test_play_iterator.py b/test/units/executor/test_play_iterator.py index 23301da0ef..d08cfda16c 100644 --- a/test/units/executor/test_play_iterator.py +++ b/test/units/executor/test_play_iterator.py @@ -86,7 +86,8 @@ class TestPlayIterator(unittest.TestCase): always: - name: role always task debug: msg="always task in block in role" - - include: foo.yml + - name: role include_tasks + include_tasks: foo.yml - name: role task after include debug: msg="after include in role" - block: @@ -171,12 +172,12 @@ class TestPlayIterator(unittest.TestCase): self.assertIsNotNone(task) self.assertEqual(task.name, "role always task") self.assertIsNotNone(task._role) - # role include task - # (host_state, task) = itr.get_next_task_for_host(hosts[0]) - # self.assertIsNotNone(task) - # self.assertEqual(task.action, 'debug') - # self.assertEqual(task.name, "role included task") - # self.assertIsNotNone(task._role) + # role include_tasks + (host_state, task) = itr.get_next_task_for_host(hosts[0]) + self.assertIsNotNone(task) + self.assertEqual(task.action, 'include_tasks') + self.assertEqual(task.name, "role include_tasks") + self.assertIsNotNone(task._role) # role task after include (host_state, task) = itr.get_next_task_for_host(hosts[0]) self.assertIsNotNone(task) diff --git a/test/units/parsing/test_dataloader.py b/test/units/parsing/test_dataloader.py index f60d33ab69..e3a26716a4 100644 --- a/test/units/parsing/test_dataloader.py +++ b/test/units/parsing/test_dataloader.py @@ -92,11 +92,11 @@ class TestDataLoader(unittest.TestCase): - { role: 'testrole' } testrole/tasks/main.yml: - - include: "include1.yml" + - include_tasks: "include1.yml" static: no testrole/tasks/include1.yml: - - include: include2.yml + - include_tasks: include2.yml static: no testrole/tasks/include2.yml: diff --git a/test/units/playbook/test_helpers.py b/test/units/playbook/test_helpers.py index 03a9062849..23385c00ef 100644 --- a/test/units/playbook/test_helpers.py +++ b/test/units/playbook/test_helpers.py @@ -65,11 +65,11 @@ class MixinForMocks(object): self._test_data_path = os.path.dirname(__file__) self.fake_include_loader = DictDataLoader({"/dev/null/includes/test_include.yml": """ - - include: other_test_include.yml + - include_tasks: other_test_include.yml - shell: echo 'hello world' """, "/dev/null/includes/static_test_include.yml": """ - - include: other_test_include.yml + - include_tasks: other_test_include.yml - shell: echo 'hello static world' """, "/dev/null/includes/other_test_include.yml": """ @@ -160,57 +160,57 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks): ds, play=self.mock_play, use_handlers=True, variable_manager=self.mock_variable_manager, loader=self.fake_loader) - def test_one_bogus_include(self): - ds = [{'include': 'somefile.yml'}] + def test_one_bogus_include_tasks(self): + ds = [{'include_tasks': 'somefile.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, variable_manager=self.mock_variable_manager, loader=self.fake_loader) self.assertIsInstance(res, list) - self.assertEqual(len(res), 0) + self.assertEqual(len(res), 1) + self.assertIsInstance(res[0], TaskInclude) - def test_one_bogus_include_use_handlers(self): - ds = [{'include': 'somefile.yml'}] + def test_one_bogus_include_tasks_use_handlers(self): + ds = [{'include_tasks': 'somefile.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, use_handlers=True, variable_manager=self.mock_variable_manager, loader=self.fake_loader) self.assertIsInstance(res, list) - self.assertEqual(len(res), 0) + self.assertEqual(len(res), 1) + self.assertIsInstance(res[0], TaskInclude) - def test_one_bogus_include_static(self): + def test_one_bogus_import_tasks(self): ds = [{'import_tasks': 'somefile.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, variable_manager=self.mock_variable_manager, loader=self.fake_loader) self.assertIsInstance(res, list) self.assertEqual(len(res), 0) - def test_one_include(self): - ds = [{'include': '/dev/null/includes/other_test_include.yml'}] + def test_one_include_tasks(self): + ds = [{'include_tasks': '/dev/null/includes/other_test_include.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, variable_manager=self.mock_variable_manager, loader=self.fake_include_loader) self.assertEqual(len(res), 1) self._assert_is_task_list_or_blocks(res) - def test_one_parent_include(self): - ds = [{'include': '/dev/null/includes/test_include.yml'}] + def test_one_parent_include_tasks(self): + ds = [{'include_tasks': '/dev/null/includes/test_include.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, variable_manager=self.mock_variable_manager, loader=self.fake_include_loader) self._assert_is_task_list_or_blocks(res) - self.assertIsInstance(res[0], Block) - self.assertIsInstance(res[0]._parent, TaskInclude) + self.assertIsInstance(res[0], TaskInclude) + self.assertIsNone(res[0]._parent) - # TODO/FIXME: do this non deprecated way - def test_one_include_tags(self): - ds = [{'include': '/dev/null/includes/other_test_include.yml', + def test_one_include_tasks_tags(self): + ds = [{'include_tasks': '/dev/null/includes/other_test_include.yml', 'tags': ['test_one_include_tags_tag1', 'and_another_tagB'] }] res = helpers.load_list_of_tasks(ds, play=self.mock_play, variable_manager=self.mock_variable_manager, loader=self.fake_include_loader) self._assert_is_task_list_or_blocks(res) - self.assertIsInstance(res[0], Block) + self.assertIsInstance(res[0], TaskInclude) self.assertIn('test_one_include_tags_tag1', res[0].tags) self.assertIn('and_another_tagB', res[0].tags) - # TODO/FIXME: do this non deprecated way - def test_one_parent_include_tags(self): - ds = [{'include': '/dev/null/includes/test_include.yml', + def test_one_parent_include_tasks_tags(self): + ds = [{'include_tasks': '/dev/null/includes/test_include.yml', # 'vars': {'tags': ['test_one_parent_include_tags_tag1', 'and_another_tag2']} 'tags': ['test_one_parent_include_tags_tag1', 'and_another_tag2'] } @@ -218,20 +218,20 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks): res = helpers.load_list_of_tasks(ds, play=self.mock_play, variable_manager=self.mock_variable_manager, loader=self.fake_include_loader) self._assert_is_task_list_or_blocks(res) - self.assertIsInstance(res[0], Block) + self.assertIsInstance(res[0], TaskInclude) self.assertIn('test_one_parent_include_tags_tag1', res[0].tags) self.assertIn('and_another_tag2', res[0].tags) - def test_one_include_use_handlers(self): - ds = [{'include': '/dev/null/includes/other_test_include.yml'}] + def test_one_include_tasks_use_handlers(self): + ds = [{'include_tasks': '/dev/null/includes/other_test_include.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, use_handlers=True, variable_manager=self.mock_variable_manager, loader=self.fake_include_loader) self._assert_is_task_list_or_blocks(res) self.assertIsInstance(res[0], Handler) - def test_one_parent_include_use_handlers(self): - ds = [{'include': '/dev/null/includes/test_include.yml'}] + def test_one_parent_include_tasks_use_handlers(self): + ds = [{'include_tasks': '/dev/null/includes/test_include.yml'}] res = helpers.load_list_of_tasks(ds, play=self.mock_play, use_handlers=True, variable_manager=self.mock_variable_manager, loader=self.fake_include_loader) diff --git a/test/units/playbook/test_included_file.py b/test/units/playbook/test_included_file.py index 7341dffa6b..c7a66b06dc 100644 --- a/test/units/playbook/test_included_file.py +++ b/test/units/playbook/test_included_file.py @@ -105,7 +105,7 @@ def test_included_file_instantiation(): assert inc_file._task is None -def test_process_include_results(mock_iterator, mock_variable_manager): +def test_process_include_tasks_results(mock_iterator, mock_variable_manager): hostname = "testhost1" hostname2 = "testhost2" @@ -113,7 +113,7 @@ def test_process_include_results(mock_iterator, mock_variable_manager): parent_task = Task.load(parent_task_ds) parent_task._play = None - task_ds = {'include': 'include_test.yml'} + task_ds = {'include_tasks': 'include_test.yml'} loaded_task = TaskInclude.load(task_ds, task_include=parent_task) return_data = {'include': 'include_test.yml'} @@ -133,7 +133,7 @@ def test_process_include_results(mock_iterator, mock_variable_manager): assert res[0]._vars == {} -def test_process_include_diff_files(mock_iterator, mock_variable_manager): +def test_process_include_tasks_diff_files(mock_iterator, mock_variable_manager): hostname = "testhost1" hostname2 = "testhost2" @@ -141,11 +141,11 @@ def test_process_include_diff_files(mock_iterator, mock_variable_manager): parent_task = Task.load(parent_task_ds) parent_task._play = None - task_ds = {'include': 'include_test.yml'} + task_ds = {'include_tasks': 'include_test.yml'} loaded_task = TaskInclude.load(task_ds, task_include=parent_task) loaded_task._play = None - child_task_ds = {'include': 'other_include_test.yml'} + child_task_ds = {'include_tasks': 'other_include_test.yml'} loaded_child_task = TaskInclude.load(child_task_ds, task_include=loaded_task) loaded_child_task._play = None @@ -175,7 +175,7 @@ def test_process_include_diff_files(mock_iterator, mock_variable_manager): assert res[1]._vars == {} -def test_process_include_simulate_free(mock_iterator, mock_variable_manager): +def test_process_include_tasks_simulate_free(mock_iterator, mock_variable_manager): hostname = "testhost1" hostname2 = "testhost2" @@ -186,7 +186,7 @@ def test_process_include_simulate_free(mock_iterator, mock_variable_manager): parent_task1._play = None parent_task2._play = None - task_ds = {'include': 'include_test.yml'} + task_ds = {'include_tasks': 'include_test.yml'} loaded_task1 = TaskInclude.load(task_ds, task_include=parent_task1) loaded_task2 = TaskInclude.load(task_ds, task_include=parent_task2) |