diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index a0bd9b37b..758da6656 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -334,7 +334,7 @@ async def get_reports(self, request: Request): for report in reports: # report URL is currently hard coded as localhost so we can # replace that to fix the IP dynamically from the requester - report["report"] = report["report"].replace("localhost",server_ip) + report["report"] = report["report"].replace("localhost", server_ip) return reports async def delete_report(self, request: Request, response: Response): diff --git a/framework/python/src/common/device.py b/framework/python/src/common/device.py index 51d68dfc6..c6a289d2c 100644 --- a/framework/python/src/common/device.py +++ b/framework/python/src/common/device.py @@ -41,6 +41,9 @@ def add_report(self, report): def get_reports(self): return self.reports + def clear_reports(self): + self.reports = [] + def remove_report(self, timestamp: datetime): for report in self.reports: if report.get_started().strftime('%Y-%m-%dT%H:%M:%S') == timestamp: diff --git a/framework/python/src/common/testreport.py b/framework/python/src/common/testreport.py index 63a3f3d68..890c32a21 100644 --- a/framework/python/src/common/testreport.py +++ b/framework/python/src/common/testreport.py @@ -48,6 +48,7 @@ def __init__(self, finished=None, total_tests=0): self._device = {} + self._mac_addr = None self._status: str = status self._started = started self._finished = finished @@ -59,6 +60,9 @@ def __init__(self, # Placeholder until available in json report self._version = 'v1.2.2-alpha' + def get_mac_addr(self): + return self._mac_addr + def add_module_reports(self, module_reports): self._module_reports = module_reports @@ -86,9 +90,14 @@ def set_report_url(self, url): def get_report_url(self): return self._report_url + + def set_mac_addr(self, mac_addr): + self._mac_addr = mac_addr def to_json(self): report_json = {} + + report_json['mac_addr'] = self._mac_addr report_json['device'] = self._device report_json['status'] = self._status report_json['started'] = self._started.strftime(DATE_TIME_FORMAT) @@ -115,6 +124,7 @@ def from_json(self, json_file): self._device['manufacturer'] = json_file['device']['manufacturer'] self._device['model'] = json_file['device']['model'] + # Firmware is not specified for non-UI devices if 'firmware' in json_file['device']: self._device['firmware'] = json_file['device']['firmware'] diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 1658ee6b8..2174256ea 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -193,6 +193,9 @@ def _load_test_reports(self, device): LOGGER.debug(f'Loading test reports for device {device.model}') + # Remove the existing reports in memory + device.clear_reports() + # Locate reports folder reports_folder = os.path.join(root_dir, LOCAL_DEVICES_DIR, @@ -219,6 +222,7 @@ def _load_test_reports(self, device): report_json = json.load(report_json_file) test_report = TestReport() test_report.from_json(report_json) + test_report.set_mac_addr(device.mac_addr) device.add_report(test_report) def delete_report(self, device: Device, timestamp): @@ -288,6 +292,9 @@ def save_device(self, device: Device, device_json): with open(config_file_path, 'w+', encoding='utf-8') as config_file: config_file.writelines(json.dumps(device.to_config_json(), indent=4)) + # Reload device reports + self._load_test_reports(device) + return device.to_config_json() def delete_device(self, device: Device): diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index 2b9d427cf..9674ff51f 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -160,6 +160,7 @@ def _write_reports(self, test_report): def _generate_report(self): report = {} + report["mac_addr"] = self.get_session().get_target_device().mac_addr report["device"] = self.get_session().get_target_device().to_dict() report["started"] = self.get_session().get_started().strftime( "%Y-%m-%d %H:%M:%S") @@ -198,7 +199,7 @@ def _cleanup_old_test_results(self, device): completed_tests = os.listdir(completed_results_dir) cur_test_count = len(completed_tests) if cur_test_count > max_device_reports: - LOGGER.debug("Current device has more than max tests results allowed: " + + LOGGER.debug("Current device has more than max results allowed: " + str(cur_test_count) + ">" + str(max_device_reports)) # Find and delete the oldest test