Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions framework/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
34 changes: 21 additions & 13 deletions net_orc/python/src/network_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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."""
Expand Down
6 changes: 3 additions & 3 deletions net_orc/python/src/network_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Expand Down
6 changes: 3 additions & 3 deletions net_orc/python/src/ovs_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions test_orc/python/src/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))))
Expand All @@ -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()

Expand All @@ -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 = {}
Expand All @@ -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(
Expand All @@ -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:
Expand Down