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
2 changes: 2 additions & 0 deletions framework/python/src/common/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ class Device():
model: str = None
test_modules: str = None
ip_addr: str = None
device_folder: str = None
max_device_reports: int = None
10 changes: 9 additions & 1 deletion framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
MONITOR_PERIOD_KEY = 'monitor_period'
STARTUP_TIMEOUT_KEY = 'startup_timeout'
LOG_LEVEL_KEY = 'log_level'
MAX_DEVICE_REPORTS_KEY = 'max_device_reports'

class TestRunSession():
"""Represents the current session of Test Run."""
Expand Down Expand Up @@ -62,7 +63,8 @@ def _get_default_config(self):
'log_level': 'INFO',
'startup_timeout': 60,
'monitor_period': 30,
'runtime': 120
'runtime': 120,
'max_device_reports': 5
}

def get_config(self):
Expand Down Expand Up @@ -95,6 +97,9 @@ def _load_config(self):
if LOG_LEVEL_KEY in config_file_json:
self._config[LOG_LEVEL_KEY] = config_file_json.get(LOG_LEVEL_KEY)

if MAX_DEVICE_REPORTS_KEY in config_file_json:
self._config[MAX_DEVICE_REPORTS_KEY] = config_file_json.get(MAX_DEVICE_REPORTS_KEY)

def _save_config(self):
with open(self._config_file, 'w', encoding='utf-8') as f:
f.write(json.dumps(self._config, indent=2))
Expand All @@ -116,6 +121,9 @@ def get_monitor_period(self):

def get_startup_timeout(self):
return self._config.get(STARTUP_TIMEOUT_KEY)

def get_max_device_reports(self):
return self._config.get(MAX_DEVICE_REPORTS_KEY)

def set_config(self, config_json):
self._config = config_json
Expand Down
20 changes: 18 additions & 2 deletions framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
DEVICE_MODEL = 'model'
DEVICE_MAC_ADDR = 'mac_addr'
DEVICE_TEST_MODULES = 'test_modules'
MAX_DEVICE_REPORTS_KEY = 'max_device_reports'

class TestRun: # pylint: disable=too-few-public-methods
"""Test Run controller.
Expand Down Expand Up @@ -112,19 +113,34 @@ def _load_devices(self, device_dir):
util.run_command(f'chown -R {util.get_host_user()} {device_dir}')

for device_folder in os.listdir(device_dir):
with open(os.path.join(device_dir, device_folder, DEVICE_CONFIG),

device_config_file_path = os.path.join(device_dir,
device_folder,
DEVICE_CONFIG)
if not os.path.exists(device_config_file_path):
LOGGER.error(f'Device configuration file missing from device {device_folder}')
continue

with open(device_config_file_path,
encoding='utf-8') as device_config_file:
device_config_json = json.load(device_config_file)

device_manufacturer = device_config_json.get(DEVICE_MANUFACTURER)
device_model = device_config_json.get(DEVICE_MODEL)
mac_addr = device_config_json.get(DEVICE_MAC_ADDR)
test_modules = device_config_json.get(DEVICE_TEST_MODULES)
max_device_reports = None
if 'max_device_reports' in device_config_json:
max_device_reports = device_config_json.get(MAX_DEVICE_REPORTS_KEY)

device = Device(manufacturer=device_manufacturer,
model=device_model,
mac_addr=mac_addr,
test_modules=test_modules)
test_modules=test_modules,
max_device_reports=max_device_reports,
device_folder=device_folder)
self.get_session().add_device(device)

self.get_session().add_device(device)
LOGGER.debug(f'Loaded device {device.manufacturer} {device.model} with MAC address {device.mac_addr}')

Expand Down
33 changes: 25 additions & 8 deletions framework/python/src/net_orc/network_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,25 @@ def _device_discovered(self, mac_addr):
# Ignore device if not registered
return

device_runtime_dir = os.path.join(RUNTIME_DIR, TEST_DIR,
mac_addr.replace(':', ''))
os.makedirs(device_runtime_dir)
device_runtime_dir = os.path.join(RUNTIME_DIR,
TEST_DIR,
mac_addr.replace(':', '')
)

# Cleanup any old current test files
shutil.rmtree(device_runtime_dir, ignore_errors=True)
os.makedirs(device_runtime_dir, exist_ok=True)

util.run_command(f'chown -R {self._host_user} {device_runtime_dir}')

packet_capture = sniff(iface=self._session.get_device_interface(),
timeout=self._session.get_startup_timeout(),
stop_filter=self._device_has_ip)
wrpcap(
os.path.join(RUNTIME_DIR, TEST_DIR, mac_addr.replace(':', ''),
'startup.pcap'), packet_capture)
os.path.join(device_runtime_dir,
'startup.pcap'
),
packet_capture)

if device.ip_addr is None:
LOGGER.info(
Expand Down Expand Up @@ -201,14 +209,23 @@ def _start_device_monitor(self, device):
callback the steady state method for this device."""
LOGGER.info(f'Monitoring device with mac addr {device.mac_addr} '
f'for {str(self._session.get_monitor_period())} seconds')

device_runtime_dir = os.path.join(RUNTIME_DIR,
TEST_DIR,
device.mac_addr.replace(':', '')
)

packet_capture = sniff(iface=self._session.get_device_interface(), timeout=self._session.get_monitor_period())
wrpcap(
os.path.join(RUNTIME_DIR, TEST_DIR, device.mac_addr.replace(':', ''),
'monitor.pcap'), packet_capture)
os.path.join(device_runtime_dir,
'monitor.pcap'
),
packet_capture)

self._monitor_in_progress = False
self.get_listener().call_callback(NetworkEvent.DEVICE_STABLE, device.mac_addr)
self.get_listener().call_callback(
NetworkEvent.DEVICE_STABLE,
device.mac_addr)

def _check_network_services(self):
LOGGER.debug('Checking network modules...')
Expand Down
Loading