From 3512a5608c3e0b7a082381d54b61fbab8054a1a0 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Tue, 12 Jun 2018 10:29:37 +0200 Subject: [PATCH] Fix command tasks with free play strategy When using the free play strategy the command and shell tasks fail logging due to an undefined variable. Fix that and add tests for it. Change-Id: I830d64d6089f869dc5a0e3d4fe346e6480884793 --- .../git/org_project/playbooks/command.yaml | 8 ++++++++ tests/remote/test_remote_zuul_stream.py | 2 ++ zuul/ansible/callback/zuul_stream.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml b/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml index 41c603b3e0..ea3c92d8fb 100644 --- a/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml +++ b/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml @@ -38,3 +38,11 @@ handlers: - name: test handler command: echo "This is a handler" + +- hosts: all + strategy: free + tasks: + - name: Command task 1 within free strategy + command: echo "First free task" + - name: Command task 2 within free strategy + command: echo "Second free task" diff --git a/tests/remote/test_remote_zuul_stream.py b/tests/remote/test_remote_zuul_stream.py index a6024f6014..6aefdc6b46 100644 --- a/tests/remote/test_remote_zuul_stream.py +++ b/tests/remote/test_remote_zuul_stream.py @@ -96,6 +96,8 @@ class TestZuulStream(AnsibleZuulTestCase): self.assertLogLine('TASK \[Show contents of second file\]', text) self.assertLogLine('controller \| command test two', text) self.assertLogLine('controller \| This is a handler', text) + self.assertLogLine('controller \| First free task', text) + self.assertLogLine('controller \| Second free task', text) self.assertLogLine( 'controller \| ok: Runtime: \d:\d\d:\d\d\.\d\d\d\d\d\d', text) self.assertLogLine('PLAY RECAP', text) diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py index 00e1a78abd..6c60ff62e1 100644 --- a/zuul/ansible/callback/zuul_stream.py +++ b/zuul/ansible/callback/zuul_stream.py @@ -210,6 +210,9 @@ class CallbackModule(default.CallbackModule): if self._play.strategy != 'free': task_name = self._print_task_banner(task) + else: + task_name = task.get_name().strip() + if task.action in ('command', 'shell'): log_id = uuid.uuid4().hex task.args['zuul_log_id'] = log_id