#135 tests are run on localhost if inventory fails
Opened 7 years ago by bgoncalv. Modified 6 years ago

In this case Fedora Rawhide iamge was not a able to install packages, standard-inventory-docker reported error, and the tests were then executed on localhost.

The playbook should have failed without running the tests.

Launching Docker container for docker.io/library/fedora:rawhide
Redirecting to /bin/systemctl start docker.service
7be4877109d8e2376a1e14d73ac4e0785622743947c6ca345e19ddc288ed947e
Fedora - Rawhide - Developmental packages for t 5.3 MB/s |  60 MB     00:11    
Last metadata expiration check: 0:00:30 ago on Fri Mar  2 10:05:19 2018.
Dependencies resolved.
================================================================================
Package                       Arch      Version               Repository  Size
================================================================================
Installing:
python2                       x86_64    2.7.14-13.fc29        rawhide    101 k
python2-dnf                   noarch    2.7.5-8.fc28          rawhide    491 k
python2-libselinux            x86_64    2.7-11.fc28           rawhide    252 k
Upgrading:
dnf                           noarch    2.7.5-8.fc28          rawhide    352 k

<snip>

GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-28-x86_64
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: GPG check FAILED
standard-inventory-docker: Could not install Ansible dependencies in launched container
[WARNING]:  * Failed to parse /usr/share/ansible/inventory/standard-inventory-docker with script plugin: local variable 'err' referenced before assignment

[WARNING]:  * Failed to parse /usr/share/ansible/inventory/standard-inventory-docker with yaml plugin: Syntax Error while loading YAML.   The error appears to have been in '/usr/share/ansible/inventory
/standard-inventory-docker': line 18, column 15, but may be elsewhere in the file depending on the exact syntax problem.  The offending line appears to be:   def main(argv):               ^ here  exception
type: <class 'yaml.scanner.ScannerError'> exception: mapping values are not allowed in this context   in "<unicode string>", line 18, column 15

[WARNING]:  * Failed to parse /usr/share/ansible/inventory/standard-inventory-docker with ini plugin: /usr/share/ansible/inventory/standard-inventory-docker:3: Expected key=value host variable assignment, got:
argparse

[WARNING]: Unable to parse /usr/share/ansible/inventory/standard-inventory-docker as an inventory source

[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] **************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [str-common : Check if system is Atomic Host] ****************************************************************************************************************************************************************
ok: [localhost]

https://github.com/linux-system-roles/test-harness/blob/master/test/run-tests#L204 contains a task to fail when only localhost is available to make tests fail when the inventory script did not work - otherwise they would be skipped and ansible-playbook returns with success (if you use hosts: all). And this hosts specification also helps to not run accidentally on localhost.

'tasks': [{'debug': {'var': 'groups'}},
                                        {'fail': {'msg': inventory_fail_msg},
                                         'when': ['groups["all"] == []']}
                                       ]

Nice approach.

'tasks': [{'debug': {'var': 'groups'}},
{'fail': {'msg': inventory_fail_msg},
'when': ['groups["all"] == []']}
]

Nice approach.

Well, it is just a workaround. It seems wrong in the first place to run the tests after the VM setup (in the inventory or elsewhere) has failed, because one will not get the intended behavior in that case.

I would summarise:

  1. ANSIBLE_INVENTORY is not set. Then: TEST_SUBJECTS is ignored. ansible-playbook runs for localhost. Test environment: environment where actual test run takes place. Test environment == localhost. We skip this case there is nothing to do.

  2. ANSIBLE_INVENTORY is set to /usr/share/ansible/inventory.
    TEST_SUBJECTS influences on scripts at /usr/share/ansible/inventory.

Tests should run on localhost in two cases: A) TEST_SUBJECTS==local B) TEST_SUBJECTS is empty.

We need to add next Ansible task:

'tasks': [{'debug': {'var': 'groups'}},
                                        {'fail': {'msg': inventory_fail_msg},
                                         'when': ['groups["all"] == []']}
                                       ]

When:

  • Ansible inventory is empty.
  • TEST_SUBJECTS is not empty, and TEST_SUBJECTS != local.

I want to keep scripts in /usr/share/ansible/inventory independent. Each one should not take care about other.

Interesting, how we can do this.

What I mean is that one should not have to embed such task in the tests. @till's approach above is to create this task in the testing system, so it is invisible to the individual tests, and that is IMO correct.

What I mean is that one should not have to embed such task in the tests. @till's approach above is to create this task in the testing system, so it is invisible to the individual tests, and that is IMO correct.

@pcahyna Right. Part of the issue was fixed in standard-test-roles-2.13-1.

For example, commit: 183e5c0

But, how to fix this issue completely is a question.

Log in to comment on this ticket.

Metadata