diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2024-06-24 15:52:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-24 15:52:06 +0200 |
commit | 339452c1050b5b8fa6fd916e00519dff90443ceb (patch) | |
tree | f881d9bf4663bb7e8533e04a1b570caddf1b78f0 /test | |
parent | add support for inactive option (#83355) (diff) | |
download | ansible-339452c1050b5b8fa6fd916e00519dff90443ceb.tar.xz ansible-339452c1050b5b8fa6fd916e00519dff90443ceb.zip |
Ensure the correct connection name is shown in results (#83354)
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/targets/callback_results/aliases (renamed from test/integration/targets/retry_task_name_in_callback/aliases) | 0 | ||||
-rw-r--r-- | test/integration/targets/callback_results/callback_plugins/track_connections.py | 40 | ||||
-rwxr-xr-x | test/integration/targets/callback_results/runme.sh (renamed from test/integration/targets/retry_task_name_in_callback/runme.sh) | 11 | ||||
-rw-r--r-- | test/integration/targets/callback_results/task_name.yml (renamed from test/integration/targets/retry_task_name_in_callback/test.yml) | 0 |
4 files changed, 49 insertions, 2 deletions
diff --git a/test/integration/targets/retry_task_name_in_callback/aliases b/test/integration/targets/callback_results/aliases index 1d28bdb2aa..1d28bdb2aa 100644 --- a/test/integration/targets/retry_task_name_in_callback/aliases +++ b/test/integration/targets/callback_results/aliases diff --git a/test/integration/targets/callback_results/callback_plugins/track_connections.py b/test/integration/targets/callback_results/callback_plugins/track_connections.py new file mode 100644 index 0000000000..ba161a7802 --- /dev/null +++ b/test/integration/targets/callback_results/callback_plugins/track_connections.py @@ -0,0 +1,40 @@ +# Copyright: Contributors to the Ansible project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import annotations + +DOCUMENTATION = ''' + name: track_connections + short_description: Track connection plugins used for hosts + description: + - Track connection plugins used for hosts + type: aggregate +''' + +import json +from collections import defaultdict + +from ansible.plugins.callback import CallbackBase + + +class CallbackModule(CallbackBase): + CALLBACK_VERSION = 2.0 + CALLBACK_TYPE = 'aggregate' + CALLBACK_NAME = 'track_connections' + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._conntrack = defaultdict(lambda : defaultdict(int)) + + def _track(self, result, *args, **kwargs): + host = result._host.get_name() + task = result._task + + self._conntrack[host][task.connection] += 1 + + v2_runner_on_ok = v2_runner_on_failed = _track + v2_runner_on_async_poll = v2_runner_on_async_ok = v2_runner_on_async_failed = _track + v2_runner_item_on_ok = v2_runner_item_on_failed = _track + + def v2_playbook_on_stats(self, stats): + self._display.display(json.dumps(self._conntrack, indent=4)) diff --git a/test/integration/targets/retry_task_name_in_callback/runme.sh b/test/integration/targets/callback_results/runme.sh index 5f636cd81b..6b051013ba 100755 --- a/test/integration/targets/retry_task_name_in_callback/runme.sh +++ b/test/integration/targets/callback_results/runme.sh @@ -4,10 +4,17 @@ set -eux # we are looking to verify the callback for v2_retry_runner gets a correct task name, include # if the value needs templating based on results of previous tasks -OUTFILE="callback_retry_task_name.out" +OUTFILE="callback_output_copy.out" trap 'rm -rf "${OUTFILE}"' EXIT +# test task retry name EXPECTED_REGEX="^.*TASK.*18236 callback task template fix OUTPUT 2" -ansible-playbook "$@" -i ../../inventory test.yml | tee "${OUTFILE}" +ansible-playbook "$@" -i ../../inventory task_name.yml | tee "${OUTFILE}" echo "Grepping for ${EXPECTED_REGEX} in stdout." grep -e "${EXPECTED_REGEX}" "${OUTFILE}" + +# test connection tracking +EXPECTED_CONNECTION='{"testhost":{"ssh":4}}' +OUTPUT_TAIL=$(tail -n5 ${OUTFILE} | tr -d '[:space:]') +[ "${EXPECTED_CONNECTION}" == "${OUTPUT_TAIL}" ] +echo $? diff --git a/test/integration/targets/retry_task_name_in_callback/test.yml b/test/integration/targets/callback_results/task_name.yml index 0e450cf94d..0e450cf94d 100644 --- a/test/integration/targets/retry_task_name_in_callback/test.yml +++ b/test/integration/targets/callback_results/task_name.yml |