From e88acb9c094dc01d91a93878a717653f519003bf Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 11 Feb 2022 20:26:07 +0000 Subject: [PATCH 1/3] Adding tests for fqcn detail in job events as resolved actions --- test/conftest.py | 26 +++++++++++++++++++++++ test/integration/test_display_callback.py | 26 ++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/test/conftest.py b/test/conftest.py index 5e786f408..2ba0ae8e3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,8 @@ import shutil from pathlib import Path +from distutils.version import LooseVersion +import subprocess from ansible_runner import defaults @@ -46,6 +48,30 @@ def skipif_pre_ansible211(is_pre_ansible211): pytest.skip("Valid only on Ansible 2.11+") +@pytest.fixture(scope="session") +def is_pre_ansible212(): + try: + base_version = ( + subprocess.run( + "python -c 'import ansible; print(ansible.__version__)'", + capture_output=True, + shell=True, + ) + .stdout.strip() + .decode() + ) + if LooseVersion(base_version) < LooseVersion("2.12"): + return True + except pkg_resources.DistributionNotFound: + pass + + +@pytest.fixture(scope="session") +def skipif_pre_ansible212(is_pre_ansible212): + if is_pre_ansible212: + pytest.skip("Valid only on Ansible 2.12+") + + # TODO: determine if we want to add docker / podman # to zuul instances in order to run these tests def pytest_generate_tests(metafunc): diff --git a/test/integration/test_display_callback.py b/test/integration/test_display_callback.py index 24bc9075f..f150fc3ad 100644 --- a/test/integration/test_display_callback.py +++ b/test/integration/test_display_callback.py @@ -197,8 +197,32 @@ def test_callback_plugin_task_args_leak(executor, playbook): # make sure playbook was successful, so all tasks were hit assert not events[-1]['event_data']['failures'], 'Unexpected playbook execution failure' +@pytest.mark.parametrize( + "playbook", + [ + { + "simple.yml": """ +- name: simpletask + connection: local + hosts: all + gather_facts: no + tasks: + - shell: echo "resolved actions test!" +""" + }, # noqa + ], +) +def test_resolved_actions(executor, playbook, skipif_pre_ansible212): + executor.run() + events = list(executor.events) -@pytest.mark.parametrize('playbook', [ + # task 1 + assert events[2]["event"] == "playbook_on_task_start" + assert "resolved_action" in events[2]["event_data"] + assert events[2]["event_data"]["resolved_action"] == "ansible.builtin.shell" + + +@pytest.mark.parametrize("playbook", [ {'loop_with_no_log.yml': ''' - name: playbook variable should not be overwritten when using no log connection: local From 02c051ed5b5139b9ae538f1c75474a99b5497415 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Fri, 3 Sep 2021 10:07:04 -0400 Subject: [PATCH 2/3] add fqcn to job events --- ansible_runner/display_callback/callback/awx_display.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible_runner/display_callback/callback/awx_display.py b/ansible_runner/display_callback/callback/awx_display.py index 0388a9a94..aa29f39db 100644 --- a/ansible_runner/display_callback/callback/awx_display.py +++ b/ansible_runner/display_callback/callback/awx_display.py @@ -554,6 +554,7 @@ def v2_playbook_on_task_start(self, task, is_conditional): name=task.get_name(), is_conditional=is_conditional, uuid=task_uuid, + resolved_action=getattr(task, 'resolved_action', '') ) with self.capture_event_data('playbook_on_task_start', **event_data): super(CallbackModule, self).v2_playbook_on_task_start(task, is_conditional) From 47ee0e5fe63d1a45c133b2df4bd207a6d7ca70e9 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Sat, 12 Feb 2022 01:30:23 +0000 Subject: [PATCH 3/3] Drop usage of distutils and use 'packaging' for version comparison ansible-core also depends on packaging so this seems like a reasonable dependency --- requirements.txt | 1 + test/conftest.py | 4 ++-- test/integration/test_display_callback.py | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 99995ce35..09cf067a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pexpect>=4.5 +packaging python-daemon pyyaml six diff --git a/test/conftest.py b/test/conftest.py index 2ba0ae8e3..558dc24b3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,7 +1,7 @@ import shutil from pathlib import Path -from distutils.version import LooseVersion +from packaging.version import Version import subprocess from ansible_runner import defaults @@ -60,7 +60,7 @@ def is_pre_ansible212(): .stdout.strip() .decode() ) - if LooseVersion(base_version) < LooseVersion("2.12"): + if Version(base_version) < Version("2.12"): return True except pkg_resources.DistributionNotFound: pass diff --git a/test/integration/test_display_callback.py b/test/integration/test_display_callback.py index f150fc3ad..5d05d71fc 100644 --- a/test/integration/test_display_callback.py +++ b/test/integration/test_display_callback.py @@ -197,6 +197,7 @@ def test_callback_plugin_task_args_leak(executor, playbook): # make sure playbook was successful, so all tasks were hit assert not events[-1]['event_data']['failures'], 'Unexpected playbook execution failure' + @pytest.mark.parametrize( "playbook", [