conftest.py 1.05 KiB
import glob
import os
import re
from lxml import etree
import inventory_provider
TEST_DATA_DIRNAME = os.path.realpath(os.path.join(
inventory_provider.__path__[0],
"..",
"test",
"data"))
def pytest_generate_tests(metafunc):
def _junosspace_hosts():
filename = os.path.join(TEST_DATA_DIRNAME, "junosspace-devices.xml")
with open(filename) as f:
doc = etree.fromstring(f.read().encode('utf-8'))
for name in doc.xpath('//devices/device/name/text()'):
m = re.match(r'^(mx[12].*)\.re0', name)
if m:
yield m.group(1) + '.geant.net'
# TODO: can we really not get netconf data for all routers?
def _available_netconf_hosts():
for fn in glob.glob(os.path.join(TEST_DATA_DIRNAME, '*-netconf.xml')):
m = re.match('(.*)-netconf.xml', os.path.basename(fn))
assert m # sanity
yield m.group(1)
routers = list(set(_junosspace_hosts()) & set(_available_netconf_hosts()))
metafunc.parametrize("router", routers)