zuul/tests/fixtures/config/secrets
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
..
git Remove auto-add of localhost from unit test inventory 2019-09-12 14:42:09 +10:00
main.yaml Handle secrets in branches 2018-01-18 13:38:02 -08:00