From dfa0f2a8bdd776719b071540ecd8e8947ca9bd51 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 16 Nov 2023 13:20:59 +0000 Subject: [PATCH] Resolve some bugs --- framework/python/src/api/api.py | 5 +++-- framework/python/src/core/testrun.py | 5 ++--- framework/python/src/net_orc/network_orchestrator.py | 4 +++- framework/python/src/test_orc/test_orchestrator.py | 6 +++--- modules/test/conn/python/src/connection_module.py | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index f332bad74..9423cc030 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -259,7 +259,7 @@ async def delete_device(self, request: Request, response: Response): mac_addr = device_json.get("mac_addr").lower() # Check that device exists - device = self._sesison.get_device(mac_addr) + device = self._test_run.get_session().get_device(mac_addr) if device is None: response.status_code = 404 @@ -280,7 +280,8 @@ async def delete_device(self, request: Request, response: Response): return self._generate_msg(True, "Successfully deleted the device") # TODO: Find specific exception to catch - except Exception: + except Exception as e: + LOGGER.error(e) response.status_code = 500 return self._generate_msg(False, "An error occured whilst deleting " + "the device") diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 38d54c955..88c4a3f29 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -288,10 +288,8 @@ def delete_device(self, device: Device): LOCAL_DEVICES_DIR, device.device_folder) - # TODO: Remove associated testrun reports from session - # Delete the device directory - os.rmdir(device_folder) + shutil.rmtree(device_folder) # Remove the device from the current session device repository self.get_session().remove_device(device) @@ -409,6 +407,7 @@ def _device_stable(self, mac_addr): LOGGER.info(f'Device with mac address {mac_addr} is ready for testing.') result = self._test_orc.run_test_modules() self._set_status(result) + self._stop_network() def get_session(self): return self._session diff --git a/framework/python/src/net_orc/network_orchestrator.py b/framework/python/src/net_orc/network_orchestrator.py index 64eb1eaaf..eb6faf9b3 100644 --- a/framework/python/src/net_orc/network_orchestrator.py +++ b/framework/python/src/net_orc/network_orchestrator.py @@ -61,7 +61,6 @@ def __init__(self, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) self.validator = NetworkValidator() - shutil.rmtree(os.path.join(os.getcwd(), NET_DIR), ignore_errors=True) self.network_config = NetworkConfig() self._ovs = OVSControl(self._session) self._ip_ctrl = IPControl() @@ -71,6 +70,9 @@ def start(self): LOGGER.debug('Starting network orchestrator') + # Delete the runtime/network directory + shutil.rmtree(os.path.join(os.getcwd(), NET_DIR), ignore_errors=True) + # Get all components ready self.load_network_modules() diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index 7392dfd48..011d7e16f 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -235,7 +235,7 @@ def _timestamp_results(self, device): # Copy the results to the timestamp directory # leave current copy in place for quick reference to # most recent test - shutil.copytree(cur_results_dir, completed_results_dir) + shutil.copytree(cur_results_dir, completed_results_dir, dirs_exist_ok=True) util.run_command(f"chown -R {self._host_user} '{completed_results_dir}'") def test_in_progress(self): @@ -366,8 +366,8 @@ def _run_test_module(self, module): except (FileNotFoundError, PermissionError, json.JSONDecodeError) as results_error: LOGGER.error( - f"Error occured whilst obbtaining results for module {module.name}") - LOGGER.debug(results_error) + f"Error occurred whilst obtaining results for module {module.name}") + LOGGER.error(results_error) LOGGER.info(f"Test module {module.name} has finished") diff --git a/modules/test/conn/python/src/connection_module.py b/modules/test/conn/python/src/connection_module.py index 8aa8d652b..c8b950c35 100644 --- a/modules/test/conn/python/src/connection_module.py +++ b/modules/test/conn/python/src/connection_module.py @@ -143,7 +143,7 @@ def _connection_single_ip(self): # message-type, option 3 = DHCPREQUEST if 'message-type' in option and option[1] == 3: mac_address = packet[Ether].src - LOGGER.info('DHCPREQUEST detected MAC addres: ' + mac_address) + LOGGER.info('DHCPREQUEST detected MAC address: ' + mac_address) if not mac_address.startswith(TR_CONTAINER_MAC_PREFIX): mac_addresses.add(mac_address.upper())