diff --git a/test_orc/modules/base/python/src/test_module.py b/test_orc/modules/base/python/src/test_module.py index 2ca686fa9..22b9e0773 100644 --- a/test_orc/modules/base/python/src/test_module.py +++ b/test_orc/modules/base/python/src/test_module.py @@ -66,7 +66,7 @@ def run_tests(self): result = None if ("enabled" in test and test["enabled"]) or "enabled" not in test: LOGGER.info("Attempting to run test: " + test["name"]) - + test['start'] = datetime.now().isoformat() # Resolve the correct python method by test name and run test if hasattr(self, test_method_name): if "config" in test: @@ -85,7 +85,9 @@ def run_tests(self): test["result"] = "compliant" if result else "non-compliant" else: test["result"] = "skipped" - test["timestamp"] = datetime.now().isoformat() + test['end'] = datetime.now().isoformat() + duration = datetime.fromisoformat(test['end']) - datetime.fromisoformat(test['start']) + test['duration'] = str(duration) json_results = json.dumps({"results": tests}, indent=2) self._write_results(json_results) diff --git a/test_orc/python/src/module.py b/test_orc/python/src/module.py index 6b2f14f9d..54f920fa1 100644 --- a/test_orc/python/src/module.py +++ b/test_orc/python/src/module.py @@ -1,27 +1,27 @@ -"""Represemts a test module.""" -from dataclasses import dataclass -from docker.models.containers import Container - -@dataclass -class TestModule: # pylint: disable=too-few-public-methods,too-many-instance-attributes - """Represents a test module.""" - - name: str = None - display_name: str = None - description: str = None - - build_file: str = None - container: Container = None - container_name: str = None - image_name :str = None - enable_container: bool = True - network: bool = True - - timeout: int = 60 - - # Absolute path - dir: str = None - dir_name: str = None - - #Set IP Index for all test modules - ip_index: str = 9 +"""Represemts a test module.""" +from dataclasses import dataclass +from docker.models.containers import Container + +@dataclass +class TestModule: # pylint: disable=too-few-public-methods,too-many-instance-attributes + """Represents a test module.""" + + name: str = None + display_name: str = None + description: str = None + + build_file: str = None + container: Container = None + container_name: str = None + image_name :str = None + enable_container: bool = True + network: bool = True + + timeout: int = 60 + + # Absolute path + dir: str = None + dir_name: str = None + + #Set IP Index for all test modules + ip_index: str = 9 diff --git a/test_orc/python/src/test_orchestrator.py b/test_orc/python/src/test_orchestrator.py index acd24b59a..f1e45e2f6 100644 --- a/test_orc/python/src/test_orchestrator.py +++ b/test_orc/python/src/test_orchestrator.py @@ -56,18 +56,25 @@ def run_test_modules(self, device): def _generate_results(self, device): results = {} + results["device"] = {} + if device.make is not None: + results["device"]["make"] = device.make + if device.make is not None: + results["device"]["model"] = device.model + results["device"]["mac_addr"] = device.mac_addr for module in self._test_modules: - container_runtime_dir = os.path.join( - self._root_path, 'runtime/test/' + device.mac_addr.replace(':', '') + - '/' + module.name) - results_file = container_runtime_dir + '/' + module.name + '-result.json' - try: - with open(results_file, 'r', encoding='UTF-8') as f: - module_results = json.load(f) - results[module.name] = module_results - except (FileNotFoundError, PermissionError, json.JSONDecodeError) as results_error: - LOGGER.error("Module Results Errror " + module.name) - LOGGER.debug(results_error) + if module.enable_container and self._is_module_enabled(module,device): + container_runtime_dir = os.path.join( + self._root_path, 'runtime/test/' + device.mac_addr.replace(':', '') + + '/' + module.name) + results_file = container_runtime_dir + '/' + module.name + '-result.json' + try: + with open(results_file, 'r', encoding='UTF-8') as f: + module_results = json.load(f) + results[module.name] = module_results + except (FileNotFoundError, PermissionError, json.JSONDecodeError) as results_error: + LOGGER.error("Module Results Errror " + module.name) + LOGGER.debug(results_error) out_file = os.path.join( self._root_path, 'runtime/test/' + device.mac_addr.replace(':', '') + '/results.json') @@ -75,12 +82,24 @@ def _generate_results(self, device): json.dump(results,f,indent=2) return results + def _is_module_enabled(self,module,device): + enabled = True + if device.test_modules is not None: + test_modules = json.loads(device.test_modules) + if module.name in test_modules: + if 'enabled' in test_modules[module.name]: + enabled = test_modules[module.name]["enabled"] + return enabled + def _run_test_module(self, module, device): """Start the test container and extract the results.""" if module is None or not module.enable_container: return + if not self._is_module_enabled(module,device): + return + LOGGER.info("Running test module " + module.name) try: