diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:05:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:05:48 +0000 |
commit | ab76d0c3dcea928a1f252ce827027aca834213cd (patch) | |
tree | 7e3797bdd2403982f4a351608d9633c910aadc12 /test/integration/targets/until | |
parent | Initial commit. (diff) | |
download | ansible-core-ab76d0c3dcea928a1f252ce827027aca834213cd.tar.xz ansible-core-ab76d0c3dcea928a1f252ce827027aca834213cd.zip |
Adding upstream version 2.14.13.upstream/2.14.13
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/until')
-rw-r--r-- | test/integration/targets/until/action_plugins/shell_no_failed.py | 28 | ||||
-rw-r--r-- | test/integration/targets/until/aliases | 2 | ||||
-rw-r--r-- | test/integration/targets/until/tasks/main.yml | 84 |
3 files changed, 114 insertions, 0 deletions
diff --git a/test/integration/targets/until/action_plugins/shell_no_failed.py b/test/integration/targets/until/action_plugins/shell_no_failed.py new file mode 100644 index 0000000..594c014 --- /dev/null +++ b/test/integration/targets/until/action_plugins/shell_no_failed.py @@ -0,0 +1,28 @@ +# Copyright: (c) 2017, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action import ActionBase + + +class ActionModule(ActionBase): + + def run(self, tmp=None, task_vars=None): + del tmp # tmp no longer has any effect + + try: + self._task.args['_raw_params'] = self._task.args.pop('cmd') + except KeyError: + pass + shell_action = self._shared_loader_obj.action_loader.get('ansible.legacy.shell', + task=self._task, + connection=self._connection, + play_context=self._play_context, + loader=self._loader, + templar=self._templar, + shared_loader_obj=self._shared_loader_obj) + result = shell_action.run(task_vars=task_vars) + result.pop('failed', None) + return result diff --git a/test/integration/targets/until/aliases b/test/integration/targets/until/aliases new file mode 100644 index 0000000..498fedd --- /dev/null +++ b/test/integration/targets/until/aliases @@ -0,0 +1,2 @@ +shippable/posix/group4 +context/controller diff --git a/test/integration/targets/until/tasks/main.yml b/test/integration/targets/until/tasks/main.yml new file mode 100644 index 0000000..2b2ac94 --- /dev/null +++ b/test/integration/targets/until/tasks/main.yml @@ -0,0 +1,84 @@ +- shell: '{{ ansible_python.executable }} -c "import tempfile; print(tempfile.mkstemp()[1])"' + register: tempfilepath + +- set_fact: + until_tempfile_path: "{{ tempfilepath.stdout }}" + +- name: loop with default retries + shell: echo "run" >> {{ until_tempfile_path }} && wc -w < {{ until_tempfile_path }} | tr -d ' ' + register: runcount + until: runcount.stdout | int == 3 + delay: 0.01 + +- assert: + that: runcount.stdout | int == 3 + +- file: path="{{ until_tempfile_path }}" state=absent + +- name: loop with specified max retries + shell: echo "run" >> {{ until_tempfile_path }} + until: 1==0 + retries: 5 + delay: 0.01 + ignore_errors: true + +- name: validate output + shell: wc -l < {{ until_tempfile_path }} + register: runcount + +- assert: + that: runcount.stdout | int == 6 # initial + 5 retries + +- file: + path: "{{ until_tempfile_path }}" + state: absent + +- name: Test failed_when impacting until + shell: 'true' + register: failed_when_until + failed_when: True + until: failed_when_until is successful + retries: 3 + delay: 0.5 + ignore_errors: True + +- assert: + that: + - failed_when_until.attempts == 3 + +- name: Test changed_when impacting until + shell: 'true' + register: changed_when_until + changed_when: False + until: changed_when_until is changed + retries: 3 + delay: 0.5 + ignore_errors: True + +- assert: + that: + - changed_when_until.attempts == 3 + +# This task shouldn't fail, previously .attempts was not available to changed_when/failed_when +# and would cause the conditional to fail due to ``'dict object' has no attribute 'attempts'`` +# https://github.com/ansible/ansible/issues/34139 +- name: Test access to attempts in changed_when/failed_when + shell: 'true' + register: changed_when_attempts + until: 1 == 0 + retries: 5 + delay: 0.5 + failed_when: changed_when_attempts.attempts > 6 + +# Test until on module that doesn't return failed, but does return rc +- name: create counter file + copy: + dest: "{{ output_dir }}/until_counter" + content: 3 + +- shell_no_failed: + cmd: | + COUNTER=$(cat "{{ output_dir }}/until_counter"); NEW=$(expr $COUNTER - 1); echo $NEW > "{{ output_dir }}/until_counter"; exit $COUNTER + register: counter + delay: 0.5 + until: counter.rc == 0 |