From 411bb77267ee63f152e04c0415569c6b932de093 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Tue, 5 Feb 2019 09:40:05 +0100 Subject: [PATCH] filter test router list by those with netconf data available --- test/per_router/conftest.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/per_router/conftest.py b/test/per_router/conftest.py index c349c9e9..0aea1c12 100644 --- a/test/per_router/conftest.py +++ b/test/per_router/conftest.py @@ -1,3 +1,4 @@ +import glob import os import re from lxml import etree @@ -12,14 +13,22 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join( def pytest_generate_tests(metafunc): - filename = os.path.join(TEST_DATA_DIRNAME, "junosspace-devices.xml") - with open(filename) as f: - doc = etree.fromstring(f.read().encode('utf-8')) - routers = [] - for name in doc.xpath('//devices/device/name/text()'): - m = re.match('^(mx[1|2].*)\.re0', name) - if m: - routers.append({'hostname': m.group(1) + '.geant.net'}) - metafunc.parametrize( - "router", - list([r['hostname'] for r in routers])) + + 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) -- GitLab