Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ansible's resolved action #995

Merged
merged 3 commits into from Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible_runner/display_callback/callback/awx_display.py
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,4 +1,5 @@
pexpect>=4.5
packaging
python-daemon
pyyaml
six
26 changes: 26 additions & 0 deletions test/conftest.py
@@ -1,6 +1,8 @@
import shutil

from pathlib import Path
from packaging.version import Version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simaishi Can you check and see if this is available as an RPM from the standard repos?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞🏻 it's also used by ansible-core so my working assumption was that we had solved it for the necessary dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible-core has it bundled, but we do have an access to the standalone rpm as well.

import subprocess

from ansible_runner import defaults

Expand Down Expand Up @@ -46,6 +48,30 @@ def skipif_pre_ansible211(is_pre_ansible211):
pytest.skip("Valid only on Ansible 2.11+")


@pytest.fixture(scope="session")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not crazy about what the is_pre_ansible211 test does. It doesn't seem like it'll work in the general case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure how I feel about this implementation generally but it gets us there quick with whatever variant of Ansible is installed in the environment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_pre_ansible211 fixture should work in the general case. The ansible package used in our tests will be ansible-core for 2.11 or higher. 2.10 is ansible-base, and 2.9 and earlier is ansible.

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 Version(base_version) < Version("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):
Expand Down
27 changes: 26 additions & 1 deletion test/integration/test_display_callback.py
Expand Up @@ -198,7 +198,32 @@ def test_callback_plugin_task_args_leak(executor, playbook):
assert not events[-1]['event_data']['failures'], 'Unexpected playbook execution failure'


@pytest.mark.parametrize('playbook', [
@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)

# 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
Expand Down