diff --git a/test/infamy/env.py b/test/infamy/env.py index e38c8127..be54ef60 100644 --- a/test/infamy/env.py +++ b/test/infamy/env.py @@ -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]