diff options
author | Clark Boylan <clark.boylan@gmail.com> | 2022-07-06 11:47:32 -0700 |
---|---|---|
committer | Clark Boylan <clark.boylan@gmail.com> | 2022-07-06 15:59:17 -0700 |
commit | 1cdf491a2e2536f1643cb7d36fa49148611e2f66 (patch) | |
tree | f5e89fb85ca25585e2ac6caabe1caaa457c9fdc2 /tests | |
parent | 35bee00c8e83f554d8a57dbfe476f43e3c7e7e6d (diff) | |
download | zuul-1cdf491a2e2536f1643cb7d36fa49148611e2f66.tar.gz |
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'(<ansible.plugins.callback.zuul_stream.CallbackModule object at'
b"0x7fbecc97c910>): '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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fixtures/config/streamer/git/common-config/playbooks/python27.yaml | 12 | ||||
-rw-r--r-- | tests/unit/test_streaming.py | 5 |
2 files changed, 17 insertions, 0 deletions
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() |