From 47a73d055e137bd7e881389a2289fdc494f256ba Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 2 Jun 2023 16:44:46 +0100 Subject: [PATCH 1/3] Create startup capture --- framework/testrun.py | 1 + net_orc/python/src/network_orchestrator.py | 34 +++++++++++++--------- net_orc/python/src/network_validator.py | 6 ++-- net_orc/python/src/ovs_control.py | 6 ++-- test_orc/python/src/test_orchestrator.py | 8 +++-- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/framework/testrun.py b/framework/testrun.py index a818c9a45..8cb384211 100644 --- a/framework/testrun.py +++ b/framework/testrun.py @@ -109,6 +109,7 @@ def start(self): [NetworkEvent.DEVICE_DISCOVERED] ) + self._net_orc.start_listener() LOGGER.info('Waiting for devices on the network...') # Check timeout and whether testing is currently diff --git a/net_orc/python/src/network_orchestrator.py b/net_orc/python/src/network_orchestrator.py index bb8d77f3d..128a01528 100644 --- a/net_orc/python/src/network_orchestrator.py +++ b/net_orc/python/src/network_orchestrator.py @@ -38,7 +38,7 @@ CONFIG_FILE = 'conf/system.json' EXAMPLE_CONFIG_FILE = 'conf/system.json.example' RUNTIME_DIR = 'runtime' -DEVICES_DIR = 'devices' +TEST_DIR = 'devices' MONITOR_PCAP = 'monitor.pcap' NET_DIR = 'runtime/network' NETWORK_MODULES_DIR = 'network/modules' @@ -93,7 +93,7 @@ def __init__(self, def start(self): """Start the network orchestrator.""" - LOGGER.info('Starting Network Orchestrator') + LOGGER.debug('Starting network orchestrator') # Get all components ready self.load_network_modules() @@ -125,6 +125,9 @@ def start_network(self): # Get network ready (via Network orchestrator) LOGGER.info('Network is ready.') + def start_listener(self): + self.listener.start_listener() + def stop(self, kill=False): """Stop the network orchestrator.""" self.stop_validator(kill=kill) @@ -172,16 +175,16 @@ def _device_discovered(self, mac_addr): f'Discovered device {mac_addr}. Waiting for device to obtain IP') device = self._get_device(mac_addr=mac_addr) os.makedirs( - os.path.join(RUNTIME_DIR, DEVICES_DIR, device.mac_addr.replace(':', - ''))) - - timeout = time.time() + self._startup_timeout + os.path.join(RUNTIME_DIR, + TEST_DIR, + device.mac_addr.replace(':', ''))) - while time.time() < timeout: - if device.ip_addr is None: - time.sleep(3) - else: - break + packet_capture = sniff(iface=self._dev_intf, + timeout=self._startup_timeout, + stop_filter=self._device_has_ip) + wrpcap( + os.path.join(RUNTIME_DIR, TEST_DIR, device.mac_addr.replace(':', ''), + 'startup.pcap'), packet_capture) if device.ip_addr is None: LOGGER.info( @@ -192,6 +195,12 @@ def _device_discovered(self, mac_addr): f'{device.ip_addr}') self._start_device_monitor(device) + def _device_has_ip(self, packet): + device = self._get_device(mac_addr=packet.src) + if device is None or device.ip_addr is None: + return False + return True + def _dhcp_lease_ack(self, packet): mac_addr = packet[BOOTP].chaddr.hex(':')[0:17] device = self._get_device(mac_addr=mac_addr) @@ -205,7 +214,7 @@ def _start_device_monitor(self, device): packet_capture = sniff(iface=self._dev_intf, timeout=self._monitor_period) wrpcap( - os.path.join(RUNTIME_DIR, DEVICES_DIR, device.mac_addr.replace(':', ''), + os.path.join(RUNTIME_DIR, TEST_DIR, device.mac_addr.replace(':', ''), 'monitor.pcap'), packet_capture) self.listener.call_callback(NetworkEvent.DEVICE_STABLE, device.mac_addr) @@ -340,7 +349,6 @@ def create_net(self): [NetworkEvent.DEVICE_DISCOVERED]) self.listener.register_callback(self._dhcp_lease_ack, [NetworkEvent.DHCP_LEASE_ACK]) - self.listener.start_listener() def load_network_modules(self): """Load network modules from module_config.json.""" diff --git a/net_orc/python/src/network_validator.py b/net_orc/python/src/network_validator.py index a90096f7d..e76e49a5c 100644 --- a/net_orc/python/src/network_validator.py +++ b/net_orc/python/src/network_validator.py @@ -47,16 +47,16 @@ def __init__(self): def start(self): """Start the network validator.""" - LOGGER.info('Starting validator') + LOGGER.debug('Starting validator') self._load_devices() self._build_network_devices() self._start_network_devices() def stop(self, kill=False): """Stop the network validator.""" - LOGGER.info('Stopping validator') + LOGGER.debug('Stopping validator') self._stop_network_devices(kill) - LOGGER.info('Validator stopped') + LOGGER.debug('Validator stopped') def _build_network_devices(self): LOGGER.debug('Building network validators...') diff --git a/net_orc/python/src/ovs_control.py b/net_orc/python/src/ovs_control.py index 4c989756b..ce316dba7 100644 --- a/net_orc/python/src/ovs_control.py +++ b/net_orc/python/src/ovs_control.py @@ -77,15 +77,15 @@ def port_exists(self, bridge_name, port): def validate_baseline_network(self): # Verify the OVS setup of the virtual network - LOGGER.info('Validating baseline network') + LOGGER.debug('Validating baseline network') # Verify the device bridge dev_bridge = self.verify_bridge(DEVICE_BRIDGE, [self._dev_intf]) - LOGGER.info('Device bridge verified: ' + str(dev_bridge)) + LOGGER.debug('Device bridge verified: ' + str(dev_bridge)) # Verify the internet bridge int_bridge = self.verify_bridge(INTERNET_BRIDGE, [self._int_intf]) - LOGGER.info('Internet bridge verified: ' + str(int_bridge)) + LOGGER.debug('Internet bridge verified: ' + str(int_bridge)) return dev_bridge and int_bridge diff --git a/test_orc/python/src/test_orchestrator.py b/test_orc/python/src/test_orchestrator.py index 14b39720d..d4d00ac85 100644 --- a/test_orc/python/src/test_orchestrator.py +++ b/test_orc/python/src/test_orchestrator.py @@ -49,7 +49,7 @@ def __init__(self, net_orc): os.makedirs(os.path.join(self._root_path, RUNTIME_DIR), exist_ok=True) def start(self): - LOGGER.info("Starting Test Orchestrator") + LOGGER.debug("Starting test orchestrator") self._load_test_modules() self.build_test_modules() @@ -64,8 +64,10 @@ def run_test_modules(self, device): for module in self._test_modules: self._run_test_module(module, device) LOGGER.info("All tests complete") - LOGGER.info(f"""Completed running test modules on device - with mac addr {device.mac_addr}""") + LOGGER.info( + f"""Completed running test + modules on device with mac + addr {device.mac_addr}""") self._generate_results(device) def _generate_results(self, device): From 2d8b4591f9414a64e9b6b3d40cd664f86faf9e8a Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Mon, 5 Jun 2023 16:32:33 +0100 Subject: [PATCH 2/3] Line break --- framework/testrun.py | 10 +--------- test_orc/python/src/test_orchestrator.py | 7 ++++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/framework/testrun.py b/framework/testrun.py index 8cb384211..cca4f35c6 100644 --- a/framework/testrun.py +++ b/framework/testrun.py @@ -48,7 +48,7 @@ LOGGER = logger.get_logger('test_run') CONFIG_FILE = 'conf/system.json' EXAMPLE_CONFIG_FILE = 'conf/system.json.example' -RUNTIME = 1500 +RUNTIME = 120 LOCAL_DEVICES_DIR = 'local/devices' RESOURCE_DEVICES_DIR = 'resources/devices' @@ -147,14 +147,6 @@ def _start_network(self): # Start the network orchestrator self._net_orc.start() - def _run_tests(self, device): - """Iterate through and start all test modules.""" - - # To Do: Make this configurable - time.sleep(60) # Let device bootup - - self._test_orc.run_test_modules(device) - def _stop_network(self, kill=False): self._net_orc.stop(kill=kill) diff --git a/test_orc/python/src/test_orchestrator.py b/test_orc/python/src/test_orchestrator.py index d4d00ac85..53cd3d80a 100644 --- a/test_orc/python/src/test_orchestrator.py +++ b/test_orc/python/src/test_orchestrator.py @@ -65,10 +65,11 @@ def run_test_modules(self, device): self._run_test_module(module, device) LOGGER.info("All tests complete") LOGGER.info( - f"""Completed running test - modules on device with mac - addr {device.mac_addr}""") + f"""Completed running test \ + modules on device with mac \ + addr {device.mac_addr}""") self._generate_results(device) + # TODO: Stop test run def _generate_results(self, device): results = {} From 9adbad5d665bba7fe75aaa3b858fef3be30aaa32 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Mon, 5 Jun 2023 17:02:19 +0100 Subject: [PATCH 3/3] Stop test run after testing finishes --- framework/testrun.py | 8 ++++++-- net_orc/python/src/network_orchestrator.py | 2 +- .../{Template => template}/device_config.json | 0 test_orc/python/src/test_orchestrator.py | 13 +++++++++---- 4 files changed, 16 insertions(+), 7 deletions(-) rename resources/devices/{Template => template}/device_config.json (100%) diff --git a/framework/testrun.py b/framework/testrun.py index cca4f35c6..25232f90c 100644 --- a/framework/testrun.py +++ b/framework/testrun.py @@ -112,10 +112,14 @@ def start(self): self._net_orc.start_listener() LOGGER.info('Waiting for devices on the network...') - # Check timeout and whether testing is currently - # in progress before stopping time.sleep(RUNTIME) + if not self._test_orc.test_in_progress(): + LOGGER.info('Timed out whilst waiting for device') + else: + while self._test_orc.test_in_progress(): + time.sleep(5) + self.stop() def stop(self, kill=False): diff --git a/net_orc/python/src/network_orchestrator.py b/net_orc/python/src/network_orchestrator.py index 128a01528..81b0e9e54 100644 --- a/net_orc/python/src/network_orchestrator.py +++ b/net_orc/python/src/network_orchestrator.py @@ -38,7 +38,7 @@ CONFIG_FILE = 'conf/system.json' EXAMPLE_CONFIG_FILE = 'conf/system.json.example' RUNTIME_DIR = 'runtime' -TEST_DIR = 'devices' +TEST_DIR = 'test' MONITOR_PCAP = 'monitor.pcap' NET_DIR = 'runtime/network' NETWORK_MODULES_DIR = 'network/modules' diff --git a/resources/devices/Template/device_config.json b/resources/devices/template/device_config.json similarity index 100% rename from resources/devices/Template/device_config.json rename to resources/devices/template/device_config.json diff --git a/test_orc/python/src/test_orchestrator.py b/test_orc/python/src/test_orchestrator.py index 53cd3d80a..08b720150 100644 --- a/test_orc/python/src/test_orchestrator.py +++ b/test_orc/python/src/test_orchestrator.py @@ -37,6 +37,7 @@ def __init__(self, net_orc): self._test_modules = [] self._module_config = None self._net_orc = net_orc + self._test_in_progress = False self._path = os.path.dirname( os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) @@ -59,6 +60,7 @@ def stop(self): def run_test_modules(self, device): """Iterates through each test module and starts the container.""" + self._test_in_progress = True LOGGER.info( f"Running test modules on device with mac addr {device.mac_addr}") for module in self._test_modules: @@ -66,10 +68,10 @@ def run_test_modules(self, device): LOGGER.info("All tests complete") LOGGER.info( f"""Completed running test \ - modules on device with mac \ - addr {device.mac_addr}""") +modules on device with mac \ +addr {device.mac_addr}""") self._generate_results(device) - # TODO: Stop test run + self._test_in_progress = False def _generate_results(self, device): results = {} @@ -91,7 +93,7 @@ def _generate_results(self, device): results[module.name] = module_results except (FileNotFoundError, PermissionError, json.JSONDecodeError) as results_error: - LOGGER.error("Module Results Errror " + module.name) + LOGGER.error("Error occured whilst running module " + module.name) LOGGER.debug(results_error) out_file = os.path.join( @@ -101,6 +103,9 @@ def _generate_results(self, device): json.dump(results, f, indent=2) return results + def test_in_progress(self): + return self._test_in_progress + def _is_module_enabled(self, module, device): enabled = True if device.test_modules is not None: