diff --git a/src/config/predefined.node_config.yaml b/src/config/predefined.node_config.yaml index 2b666ca..c5e5d13 100644 --- a/src/config/predefined.node_config.yaml +++ b/src/config/predefined.node_config.yaml @@ -1,4 +1,4 @@ -node: +node_config: - name: n_hop node_img: gitlab.app.n-hop.com:5005/n-hop/bats-protocol-framework/bats_protocol:dev node_vols: diff --git a/src/containernet/config.py b/src/containernet/config.py index 20e0b6a..26ef98b 100644 --- a/src/containernet/config.py +++ b/src/containernet/config.py @@ -77,10 +77,10 @@ class TopologyConfig: json_description: Optional[str] = field(default=None) -supported_config_keys = ["node", "topology"] +supported_config_keys = ["node_config", "topology"] -class INodeConfig(ABC): +class IConfig(ABC): @staticmethod def is_supported_config_key(config_key: str): return config_key in supported_config_keys @@ -88,7 +88,7 @@ def is_supported_config_key(config_key: str): @staticmethod def load_config_reference(yaml_config_file: str, config_name: str, config_key: str): - if not INodeConfig.is_supported_config_key(config_key): + if not IConfig.is_supported_config_key(config_key): logging.error( f"load_config_reference: key %s is not supported.", config_key) @@ -123,7 +123,7 @@ def load_config_reference(yaml_config_file: str, f"load_config_reference: %s is not defined in %s", config_name, yaml_config_file) return None - if config_key == "node": + if config_key == "node_config": return NodeConfig(**loaded_config) if config_key == "topology": return TopologyConfig(**loaded_config) @@ -133,7 +133,7 @@ def load_config_reference(yaml_config_file: str, def load_yaml_config(yaml_description: str, config_key: str): # load it directly from the yaml_description or # load it from another yaml file. - if not INodeConfig.is_supported_config_key(config_key): + if not IConfig.is_supported_config_key(config_key): logging.error( f"load_yaml_config: key %s is not supported.", config_key) @@ -142,13 +142,13 @@ def load_yaml_config(yaml_description: str, config_key: str): is_load_from_file = ["config_file", "config_name"] if all(key in yaml_description for key in is_load_from_file): # load from the yaml file `config_file` - config_data = INodeConfig.load_config_reference( + config_data = IConfig.load_config_reference( yaml_description['config_file'], yaml_description['config_name'], config_key) else: # load directly from the yaml_description logging.info('load_yaml_config: %s', yaml_description) - if config_key == "node": + if config_key == "node_config": config_data = NodeConfig(**yaml_description) if config_key == "topology": config_data = TopologyConfig(**yaml_description) diff --git a/src/run_test.py b/src/run_test.py index 7e886db..f8b1b06 100755 --- a/src/run_test.py +++ b/src/run_test.py @@ -9,7 +9,7 @@ from containernet.linear_topology import LinearTopology from containernet.network import Network from containernet.config import ( - INodeConfig, NodeConfig, TopologyConfig) + IConfig, NodeConfig, TopologyConfig, supported_config_keys) from containernet.test_suites.test import (TestType, TestConfig) from containernet.test_suites.test_iperf import IperfTest from containernet.test_suites.test_ping import PingTest @@ -53,19 +53,26 @@ def load_test(test_yaml_file: str): def load_config(test_case_yaml) -> Tuple[NodeConfig, TopologyConfig]: - local_net_top_yaml = test_case_yaml['topology'] - local_node_conf_yaml = test_case_yaml['node_config'] - logging.info(f"Test: top_yaml %s, node_conf_yaml %s", - local_net_top_yaml, local_node_conf_yaml) - if local_net_top_yaml is None or local_node_conf_yaml is None: - logging.error("Error: top_yaml or node_conf_yaml is None.") - return None, None - node_config = INodeConfig.load_yaml_config(local_node_conf_yaml, 'node') - top_config = INodeConfig.load_yaml_config(local_net_top_yaml, 'topology') - if top_config is None or node_config is None: - logging.error("Error: topology/node configuration is None.") - return None, None - return node_config, top_config + configs = [] + for key in supported_config_keys: + if key not in test_case_yaml: + logging.error( + f"Error: missing key %s in the test case yaml.", + key) + return None, None + local_yaml = test_case_yaml[key] + logging.info(f"Test: local_yaml %s", + local_yaml) + if local_yaml is None: + logging.error(f"Error: content of %s is None.", key) + return None, None + loaded_conf = IConfig.load_yaml_config( + local_yaml, key) + if loaded_conf is None: + logging.error("Error: loaded_conf of %s is None.", key) + return None, None + configs.append(loaded_conf) + return configs[0], configs[1] def build_topology(top_config: TopologyConfig):