Skip to content

Commit

Permalink
Resolve timezone issue in connection modules (#169)
Browse files Browse the repository at this point in the history
* Resolve timezone issue in connection modules

* Remove error for hotfix

* Update baseline module

* Update baseline module

* Disable baseline module

* Remove ntp module from tester 2
  • Loading branch information
jboddey authored Nov 13, 2023
1 parent 516a0d0 commit ce312be
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 65 deletions.
5 changes: 3 additions & 2 deletions framework/python/src/common/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

"""Track device object information."""

from typing import Dict
from typing import Dict, List
from dataclasses import dataclass, field
from common.testreport import TestReport

@dataclass
class Device():
Expand All @@ -29,8 +30,8 @@ class Device():
ip_addr: str = None
firmware: str = None
device_folder: str = None
reports = []
max_device_reports: int = None
reports: List[TestReport] = field(default_factory=list)

def add_report(self, report):
self.reports.append(report)
Expand Down
2 changes: 1 addition & 1 deletion framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, config_file):
tz = util.run_command('cat /etc/timezone')
# TODO: Check if timezone is fetched successfully
self._timezone = tz[0]
LOGGER.info(f'System timezone is {self._timezone}')
LOGGER.debug(f'System timezone is {self._timezone}')

def start(self):
self.reset()
Expand Down
2 changes: 0 additions & 2 deletions framework/python/src/common/testreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ def from_json(self, json_file):
for test_result in json_file['tests']['results']:
self.add_test(test_result)

return self

# Create a pdf file in memory and return the bytes
def to_pdf(self):
# Resolve the data as html first
Expand Down
17 changes: 9 additions & 8 deletions framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,24 @@ def _load_devices(self, device_dir):
if 'max_device_reports' in device_config_json:
max_device_reports = device_config_json.get(MAX_DEVICE_REPORTS_KEY)

device = Device(folder_url=os.path.join(device_dir, device_folder),
folder_url = os.path.join(device_dir, device_folder)

device = Device(folder_url=folder_url,
manufacturer=device_manufacturer,
model=device_model,
mac_addr=mac_addr,
test_modules=test_modules,
max_device_reports=max_device_reports,
device_folder=device_folder)

# Load reports for this device
self._load_test_reports(device)

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

def _load_test_reports(self, device: Device):

LOGGER.debug(f'Loading test reports for device {device.model}')
def _load_test_reports(self, device):

# Locate reports folder
reports_folder = os.path.join(root_dir,
Expand All @@ -191,6 +190,8 @@ def _load_test_reports(self, device: Device):
if not os.path.exists(reports_folder):
return

LOGGER.info(f'Loading reports from {reports_folder}')

for report_folder in os.listdir(reports_folder):
report_json_file_path = os.path.join(
reports_folder,
Expand All @@ -204,7 +205,8 @@ def _load_test_reports(self, device: Device):

with open(report_json_file_path, encoding='utf-8') as report_json_file:
report_json = json.load(report_json_file)
test_report = TestReport().from_json(report_json)
test_report = TestReport()
test_report.from_json(report_json)
device.add_report(test_report)

def create_device(self, device: Device):
Expand Down Expand Up @@ -275,10 +277,9 @@ def start(self):
[NetworkEvent.DEVICE_STABLE]
)

self._set_status('Waiting for Device')

self.get_net_orc().start_listener()
LOGGER.info('Waiting for devices on the network...')
self._set_status('Waiting for Device')

# Keep application running until stopped
while True:
Expand Down
8 changes: 5 additions & 3 deletions framework/python/src/test_orc/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def run_test_modules(self):

self._session.stop()

report = TestReport().from_json(self._generate_report())
report = TestReport()
report.from_json(self._generate_report())
device.add_report(report)

self._write_reports(report)
Expand Down Expand Up @@ -164,7 +165,7 @@ def _calculate_result(self):
f"test {test_result['name']}")
continue
if (test_case.required_result.lower() == "required"
and test_result["result"].lower() == "non-compliant"):
and test_result["result"].lower() != "compliant"):
result = "Non-Compliant"
return result

Expand Down Expand Up @@ -211,7 +212,8 @@ def _find_oldest_test(self, completed_tests_dir):
oldest_timestamp = timestamp
oldest_directory = completed_test
if oldest_directory:
return oldest_timestamp, os.path.join(completed_tests_dir, oldest_directory)
return oldest_timestamp, os.path.join(completed_tests_dir,
oldest_directory)
else:
return None

Expand Down
5 changes: 5 additions & 0 deletions modules/test/base/python/src/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,23 @@ def run_tests(self):
LOGGER.debug(f'Test {test["name"]} is disabled')

if result is not None:
# Compliant or non-compliant
if isinstance(result, bool):
test['result'] = 'Compliant' if result else 'Non-Compliant'
test['description'] = 'No description was provided for this test'
else:
if result[0] is None:
test['result'] = 'Skipped'
if len(result) > 1:
test['description'] = result[1]
else:
test['description'] = 'An error occured whilst running this test'
else:
test['result'] = 'Compliant' if result[0] else 'Non-Compliant'
test['description'] = result[1]
else:
test['result'] = 'Skipped'
test['description'] = 'An error occured whilst running this test'

test['end'] = datetime.now().isoformat()
duration = datetime.fromisoformat(test['end']) - datetime.fromisoformat(
Expand Down
1 change: 1 addition & 0 deletions modules/test/baseline/conf/module_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"config": {
"enabled": false,
"meta": {
"name": "baseline",
"display_name": "Baseline",
Expand Down
2 changes: 1 addition & 1 deletion modules/test/baseline/python/src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from baseline_module import BaselineModule

LOGGER = logger.get_logger('test_module')
LOGGER = logger.get_logger('test_baseline')
RUNTIME = 1500


Expand Down
Loading

0 comments on commit ce312be

Please sign in to comment.