Commit Graph

8 Commits

Author SHA1 Message Date
Simon Westphahl 3b011296e6 Keep task stdout/stderr separate in result object
Combining stdout/stderr in the result can lead to problems when e.g.
the stdout of a task is used as an input for another task.

This is also different from the normal Ansible behavior and can be
surprising and hard to debug for users.

The new behavior is configurable and off by default to retain backward
compatibility.

Change-Id: Icaced970650913f9632a8db75a5970a38d3a6bc4
Co-Authored-By: James E. Blair <jim@acmegating.com>
2023-08-17 16:22:41 -07:00
Ian Wienand b6544f514f Remove auto-add of localhost from unit test inventory
Unit test playbooks are generally written as

 - hosts: all
   tasks:
     ...

However, many of the unit tests don't specify any nodes for their
jobs.  With no nodes specified, Ansible gets a empty host list and
thus the only host available is the special "implicit localhost".
Since "all" doesn't match the implicit localhost, under normal
circumstances Ansible does not match anything and doesn't run any of
the playbooks.

To get around this, the extant code in
RecordingAnsibleJob:getHostList() (tests/base.py) overrides the host
list and explicitly adds a host named "localhost".  This is put into
the Ansible inventory and now the "all" matcher has something to match
against and the playbooks run.  This work-around was initially added
with I5e23f330476f064acf3cb87f746c5d3193cce274.

The situation became a bit more confused with
Iacf670d992bb051560a0c46c313beaa6721489c4 where the "localhost" fake
node is only added if other nodes are *not* specified.  Several tests
rely on this now as they specify various forms of nodes explicitly and
don't want this fake node added.

This change removes the automatic addition of "localhost" in
unit-tests all together.  I believe this is the correct direction to
move in, because it's a fairly confusing anti-feature if, for example,
you write a unit test that *is* explicitly executor-only (i.e. a blank
node list).  Such a test fails because the unit-test framework adds a
host for you; something that does not happen in production.  It's also
a bit confusing if you're reading the config files and thinking
"hosts: all shouldn't match anything here" without digging into the
test framework.

There are two ways this could be fixed.  The playbooks that are part
of jobs that have no nodes defined could be re-written to "hosts:
localhost" so that they match the "implicit localhost" and always run.
This does not really seem to be their intent, however.  The other
option, which is taken here, is to always add nodes to the job.  I
believe this is a better approach, as it more closely matches what you
would see in actual jobs.

Change-Id: I6b52b7e4bc591c09034461b534ca5225945f76cf
2019-09-12 14:42:09 +10:00
Simon Westphahl 6e424878ae Fix error reporting for special task failures
For some tasks the Ansible log will not contain enough information to
debug failures (e.g. missing role with include_role).

Ansible treats those issues not like an error (exit code 1) but like a
failed task, leading to an exit code of 2.

Change-Id: Iea754814e3d55be6be1c2de7f2d45ceda757f480
2019-02-06 10:25:56 +01:00
Tobias Henkel 5e9f77326c
Fix reporting ansible errors in buildlog
We had a mechanism that collects ansible errors like missing roles
that are catched early during parsing the playbook. However we had no
tests for this and this mechanism is now broken. The reason is that we
check if the first line of the syntax buffer containing the ansible
output is 'ERROR!'. However now this is the second line while the
first line tells us which ansible.cfg file it used.

To fix that just output the buffer starting with the first found line
that starts with 'ERROR!' and add a test case to it such it won't
break again.

Change-Id: Idf86bacf1117a3e95b69b45d6c70db9abb92cffc
Story: 2004289
Task: 27841
2018-11-07 15:11:17 +01:00
Ian Wienand 548c43c265 Update playbook paths with extension
These playbook paths were missing ".yaml" extentions which fails when
implied matching goes away (Ie2519f2b4144761b8e4d17ec3299cf4238e16f08).

Change-Id: Iff04d894fffdcec0a0861d2460635b4c44a15ae4
2017-12-05 14:25:07 +11:00
James E. Blair 2f589fec6b Update test fixtures to use explicit run
Change-Id: I3060a2bf57cef10a5a7ec5299e3491f1f6751221
2017-10-26 15:59:41 -07:00
Monty Taylor 0e2489a4cd
Grab json log contents for final post playbook failures
If the final post playbook fails, something has gone wrong with log
uploading, which means it's very hard to debug. Grab the contents of the
json log file, extract the log for the last playbook and add it to the
executor log.

Change-Id: Ia930311e121c350e73e41b20e9b742b2eac9c9f6
2017-10-10 14:02:02 -05:00
James E. Blair a00910c9ed Add a test to verify basic console output
This also fixes a condition in zuul_stream which would cause us
not to see stdout from tasks run on the executor (localhost).

Change-Id: I24df40adaf06a7bf0b238be33b8ab29cb692f836
2017-08-23 10:14:58 -07:00