Merge "testinfra: pass inventory and zuul data"
This commit is contained in:
commit
fc39f87f1e
@ -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
|
||||
|
20
testinfra/conftest.py
Normal file
20
testinfra/conftest.py
Normal file
@ -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
|
@ -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
|
||||
|
2
tox.ini
2
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]
|
||||
|
Loading…
Reference in New Issue
Block a user