0d004ea73d
Create a zuul_data fixture for testinfra. The fixture directly loads the inventory from the inventory YAML file written out. This lets you get easy access to the IP addresses of the hosts. We pass in the "zuul" variable by writing it out to a YAML file on disk, and then passing an environment variable to this. This is useful for things like determining which job is running. Additional arbitrary data could be added to this if required. Change-Id: I8adb7601f7eec6d48509f8f1a42840beca70120c
21 lines
461 B
Python
21 lines
461 B
Python
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
|