From 1cdf491a2e2536f1643cb7d36fa49148611e2f66 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 6 Jul 2022 11:47:32 -0700 Subject: Handle non default loopvars in Ansible callback stream plugin The Zuul Ansible callback stream plugin assumed that the ansible loop var was always called 'item' in the result_dict. You can override this value (and it is often necessary to do so to avoid collisions) to something less generic. In those cases we would get errors like: b'[WARNING]: Failure using method (v2_runner_item_on_ok) in callback plugin' b'(): 'item'" And stream output would not include the info typically logged. Address this by checking if ansible_loop_var is in the results_dict and using that value for the loop var name instead. We still fall back to 'item' as I'm not sure that ansible_loop_var is always present. Change-Id: I408e6d4af632f8097d63c04cbcb611d843086f6c --- .../streamer/git/common-config/playbooks/python27.yaml | 12 ++++++++++++ tests/unit/test_streaming.py | 5 +++++ 2 files changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/fixtures/config/streamer/git/common-config/playbooks/python27.yaml b/tests/fixtures/config/streamer/git/common-config/playbooks/python27.yaml index 8485b04ce..397439f61 100644 --- a/tests/fixtures/config/streamer/git/common-config/playbooks/python27.yaml +++ b/tests/fixtures/config/streamer/git/common-config/playbooks/python27.yaml @@ -11,6 +11,18 @@ Debug Test Token String Message + # Logging of loops is special so we do a simple one iteration + # loop and check that we log things properly + - name: Override ansible_loop_var + set_fact: + _testing_fact: "{{ other_loop_var }}" + with_random_choice: + - "one" + - "two" + - "three" + loop_control: + loop_var: "other_loop_var" + # Do not finish until test creates the flag file - wait_for: state: present diff --git a/tests/unit/test_streaming.py b/tests/unit/test_streaming.py index f323cd82a..ba3117f59 100644 --- a/tests/unit/test_streaming.py +++ b/tests/unit/test_streaming.py @@ -295,6 +295,11 @@ class TestStreaming(TestStreamingBase): match = r.search(self.streaming_data[None]) self.assertNotEqual(match, None) + # Check that we logged loop_var contents properly + pattern = r'ok: "(one|two|three)"' + m = re.search(pattern, self.streaming_data[None]) + self.assertNotEqual(m, None) + def runWSClient(self, port, build_uuid): client = WSClient(port, build_uuid) client.event.wait() -- cgit v1.2.1