summaryrefslogtreecommitdiff
path: root/tests/fixtures
diff options
context:
space:
mode:
authorJames E. Blair <jim@acmegating.com>2022-05-17 16:31:35 -0700
committerJames E. Blair <jim@acmegating.com>2022-05-21 08:42:03 -0700
commit096e47dc436b73f8876a1afec8874e13269a4abd (patch)
tree3d4d3b13ff7b9e7f023430f823608fd7dd9abf46 /tests/fixtures
parent50a8d8ab96154c6dba54a84f56bba8067942de55 (diff)
downloadzuul-096e47dc436b73f8876a1afec8874e13269a4abd.tar.gz
Fix console log streaming with duplicated roles
If a role is applied to a host more than once (via either play roles or include_roles, but not via an include_role loop), it will have the same task UUID from ansible which means Zuul's command plugin will write the streaming output to the same filename, and the log streaming will request the same file. That means the file might look this after the second invocation: 2022-05-19 17:06:23.673625 | one 2022-05-19 17:06:23.673781 | [Zuul] Task exit code: 0 2022-05-19 17:06:29.226463 | two 2022-05-19 17:06:29.226605 | [Zuul] Task exit code: 0 But since we stop reading the log after "Task exit code", the user would see "one" twice, and never see "two". Here are some potential fixes for this that don't work: * Accessing the task vars from zuul_stream to store any additional information: the callback plugins are not given the task vars. * Setting the log id on the task args in zuul_stream instead of command: the same Task object is used for each host and therefore the command module might see the task object after it has been further modified (in other words, nothing host-specific can be set on the task object). * Setting an even more unique uuid than Task._uuid on the Task object in zuul_stream and using that in the command module instead of Task._uuid: in some rare cases, the actual task Python object may be different between the callback and command plugin, yet still have the same _uuid; therefore the new attribute would be missing. Instead, a global variable is used in order to transfer data between zuul_stream and command. This variable holds a counter for each task+host combination. Most of the time it will be 1, but if we run the same task on the same host again, it will increment. Since Ansible will not run more than one task on a host simultaneously, so there is no race between the counter being incremented in zuul_stream and used in command. Because Ansible is re-invoked for each playbook, the memory usage is not a concern. There may be a fork between zuul_stream and command, but that's fine as long as we treat it as read-only in the command plugin. It will have the data for our current task+host from the most recent zuul_stream callback invocation. This change also includes a somewhat unrelated change to the test infrastructure. Because we were not setting the log stream port on the executor in tests, we were actually relying on the "real" OpenDev Zuul starting zuul_console on the test nodes rather than the zuul_console we set up for each specific Ansible version from the tests. This corrects that and uses the correct zuul_console port, so that if we make any changes to zuul_console in the future, we will test the changed version, not the one from the Zuul which actually runs the tox-remote job. Change-Id: Ia656db5f3dade52c8dbd0505b24049fe0fff67a5
Diffstat (limited to 'tests/fixtures')
-rw-r--r--tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml19
-rw-r--r--tests/fixtures/config/remote-zuul-stream/git/org_project/roles/echo-role/tasks/main.yaml2
-rw-r--r--tests/fixtures/config/remote-zuul-stream/git/org_project/roles/include-echo-role/tasks/main.yaml3
3 files changed, 24 insertions, 0 deletions
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 d6a53be74..8d5667f10 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
@@ -89,3 +89,22 @@
- failed_in_loop1
- failed_in_loop2
ignore_errors: True
+
+# Try transitive includes two different ways
+- hosts: compute1
+ tasks:
+ - include_role:
+ name: include-echo-role
+ vars:
+ item: transitive-one
+ - include_role:
+ name: include-echo-role
+ vars:
+ item: transitive-two
+
+- hosts: compute1
+ roles:
+ - role: include-echo-role
+ item: transitive-three
+ - role: include-echo-role
+ item: transitive-four
diff --git a/tests/fixtures/config/remote-zuul-stream/git/org_project/roles/echo-role/tasks/main.yaml b/tests/fixtures/config/remote-zuul-stream/git/org_project/roles/echo-role/tasks/main.yaml
new file mode 100644
index 000000000..500329797
--- /dev/null
+++ b/tests/fixtures/config/remote-zuul-stream/git/org_project/roles/echo-role/tasks/main.yaml
@@ -0,0 +1,2 @@
+- name: Echo message
+ command: "echo {{item}}"
diff --git a/tests/fixtures/config/remote-zuul-stream/git/org_project/roles/include-echo-role/tasks/main.yaml b/tests/fixtures/config/remote-zuul-stream/git/org_project/roles/include-echo-role/tasks/main.yaml
new file mode 100644
index 000000000..79eade799
--- /dev/null
+++ b/tests/fixtures/config/remote-zuul-stream/git/org_project/roles/include-echo-role/tasks/main.yaml
@@ -0,0 +1,3 @@
+- name: Include echo role
+ include_role:
+ name: echo-role