From b272f1f6d0609a2825e52cc392d96822451a60cf Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Wed, 15 May 2024 09:01:30 +0000 Subject: [PATCH] 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. --- test/infamy/env.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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]