test: env: Add support for querying global attributes

This will let other Infamy submodules tune their behavior based on the
particular test system they are running on.

Attributes are defined by creating graph-global attributes with an
"ix_" prefix.
This commit is contained in:
Tobias Waldekranz
2024-05-17 23:42:18 +02:00
parent 36cbb9199b
commit b272f1f6d0
+21
View File
@@ -7,6 +7,12 @@ import sys
from . import neigh, netconf, tap, topology
class NullEnv:
def attr(self, _, default=None):
return default
ENV = NullEnv()
class ArgumentParser(argparse.ArgumentParser):
def __init__(self, ltop):
super().__init__()
@@ -37,6 +43,21 @@ class Env(object):
print(repr(self.ltop))
global ENV
ENV = self
def attr(self, name, default=None):
val = self.ptop.get_attr("ix_" + name)
if val == None:
return default
try:
return int(val, 0)
except ValueError:
pass
return val
def attach(self, node, port, factory_default=True):
if self.ltop:
mapping = self.ltop.mapping[node]