diff --git a/playbooks/zuul/run-base.yaml b/playbooks/zuul/run-base.yaml index 03dd275781..3a8a6cb062 100644 --- a/playbooks/zuul/run-base.yaml +++ b/playbooks/zuul/run-base.yaml @@ -114,6 +114,18 @@ - name: Run test playbook when: run_test_playbook is defined shell: "ANSIBLE_ROLES_PATH=/home/zuul/src/opendev.org/opendev/system-config/playbooks/roles ansible-playbook -v /home/zuul/src/opendev.org/opendev/system-config/{{ run_test_playbook }}" + + - name: Generate testinfra extra data fixture + set_fact: + testinfra_extra_data: + zuul_job: '{{ zuul.job }}' + zuul: '{{ zuul }}' + + - name: Write out testinfra extra data fixture + copy: + content: '{{ testinfra_extra_data | to_nice_yaml }}' + dest: '/home/zuul/testinfra_extra_data_fixture.yaml' + - name: Run testinfra to validate configuration include_role: name: tox @@ -121,4 +133,6 @@ tox_envlist: testinfra # This allows us to run from external projects (like testinfra # itself) + tox_environment: + TESTINFRA_EXTRA_DATA: '/home/zuul/testinfra_extra_data_fixture.yaml' zuul_work_dir: src/opendev.org/opendev/system-config diff --git a/testinfra/conftest.py b/testinfra/conftest.py new file mode 100644 index 0000000000..be545d7395 --- /dev/null +++ b/testinfra/conftest.py @@ -0,0 +1,20 @@ +import os +import pytest +import yaml + +@pytest.fixture +def zuul_data(): + + data = {} + + with open('/etc/ansible/hosts/inventory.yaml') as f: + inventory = yaml.load(f) + data['inventory'] = inventory + + zuul_extra_data_file = os.environ.get('TESTINFRA_EXTRA_DATA') + if os.path.exists(zuul_extra_data_file): + with open(zuul_extra_data_file, 'r') as f: + extra = yaml.load(f) + data['extra'] = extra + + return data diff --git a/testinfra/test_bridge.py b/testinfra/test_bridge.py index 3947bff963..61fff1dc8a 100644 --- a/testinfra/test_bridge.py +++ b/testinfra/test_bridge.py @@ -17,6 +17,13 @@ import pytest testinfra_hosts = ['bridge.openstack.org'] +def test_zuul_data(host, zuul_data): + # Test the zuul_data fixture that picks up things set by Zuul + assert 'inventory' in zuul_data + assert 'extra' in zuul_data + assert 'zuul' in zuul_data['extra'] + + def test_clouds_yaml(host): clouds_yaml = host.file('/etc/openstack/clouds.yaml') assert clouds_yaml.exists diff --git a/tox.ini b/tox.ini index 4f4e5c83e0..8cbe0a8a08 100644 --- a/tox.ini +++ b/tox.ini @@ -33,6 +33,8 @@ deps = -r{toxinidir}/doc/requirements.txt commands = sphinx-build -W -E -b html doc/source doc/build/html [testenv:testinfra] +passenv = + TESTINFRA_EXTRA_DATA commands = py.test --junit-xml junit.xml --connection=ansible --ansible-inventory=/etc/ansible/hosts/inventory.yaml -v testinfra {posargs} [flake8]