diff --git a/framework/testrun.py b/framework/testrun.py index a818c9a45..25232f90c 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' @@ -109,12 +109,17 @@ 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 - # 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): @@ -146,14 +151,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/net_orc/python/src/network_orchestrator.py b/net_orc/python/src/network_orchestrator.py index bb8d77f3d..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' -DEVICES_DIR = 'devices' +TEST_DIR = 'test' 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/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 14b39720d..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__)))) @@ -49,7 +50,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() @@ -59,14 +60,18 @@ 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: 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) + self._test_in_progress = False def _generate_results(self, device): results = {} @@ -88,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( @@ -98,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: