From 8661feb4d188ba4fc8795f4b8d4a87a518278a92 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Wed, 21 Aug 2024 09:19:37 +0100 Subject: [PATCH 1/2] Flag outdated devices --- framework/python/src/api/api.py | 5 ++++- framework/python/src/common/device.py | 12 ++++++++++++ framework/python/src/core/testrun.py | 22 +++++++++++++++++++++- make/DEBIAN/control | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index 719710694..be14b726d 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -179,7 +179,10 @@ async def get_sys_config(self): return self._session.get_config() async def get_devices(self): - return self._session.get_device_repository() + devices = [] + for device in self._session.get_device_repository(): + devices.append(device.to_dict()) + return devices async def start_test_run(self, request: Request, response: Response): diff --git a/framework/python/src/common/device.py b/framework/python/src/common/device.py index c6a289d2c..55f0c5b66 100644 --- a/framework/python/src/common/device.py +++ b/framework/python/src/common/device.py @@ -23,10 +23,14 @@ class Device(): """Represents a physical device and it's configuration.""" + status: str = 'Valid' folder_url: str = None mac_addr: str = None manufacturer: str = None model: str = None + type: str = None + technology: str = None + test_pack: str = 'Device Qualification' test_modules: Dict = field(default_factory=dict) ip_addr: str = None firmware: str = None @@ -54,9 +58,13 @@ def to_dict(self): """Returns the device as a python dictionary. This is used for the system status API endpoint and in the report.""" device_json = {} + device_json['status'] = self.status device_json['mac_addr'] = self.mac_addr device_json['manufacturer'] = self.manufacturer device_json['model'] = self.model + device_json['type'] = self.type + device_json['technology'] = self.technology + device_json['test_pack'] = self.test_pack if self.firmware is not None: device_json['firmware'] = self.firmware device_json['test_modules'] = self.test_modules @@ -66,8 +74,12 @@ def to_config_json(self): """Returns the device as a python dictionary. Fields relevant to the device config json file are exported.""" device_json = {} + device_json['status'] = self.status device_json['mac_addr'] = self.mac_addr device_json['manufacturer'] = self.manufacturer device_json['model'] = self.model + device_json['type'] = self.type + device_json['technology'] = self.technology + device_json['test_pack'] = self.test_pack device_json['test_modules'] = self.test_modules return device_json diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 95011c58b..de6ef98c1 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -58,6 +58,10 @@ DEVICE_MODEL = 'model' DEVICE_MAC_ADDR = 'mac_addr' DEVICE_TEST_MODULES = 'test_modules' +DEVICE_TYPE_KEY = 'type' +DEVICE_TECHNOLOGY_KEY = 'technology' +DEVICE_TEST_PACK_KEY = 'test_pack' + MAX_DEVICE_REPORTS_KEY = 'max_device_reports' class Testrun: # pylint: disable=too-few-public-methods @@ -165,7 +169,7 @@ def _load_devices(self, device_dir): # Check if device config file exists before loading if not os.path.exists(device_config_file_path): LOGGER.error('Device configuration file missing ' + - f'from device {device_folder}') + f'for device {device_folder}') continue # Open device config file @@ -177,6 +181,8 @@ def _load_devices(self, device_dir): 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) + + # Load max device reports max_device_reports = None if 'max_device_reports' in device_config_json: max_device_reports = device_config_json.get(MAX_DEVICE_REPORTS_KEY) @@ -191,6 +197,20 @@ def _load_devices(self, device_dir): max_device_reports=max_device_reports, device_folder=device_folder) + # Load in the additional fields + if DEVICE_TYPE_KEY in device_config_json: + device.type = device_config_json.get(DEVICE_TYPE_KEY) + + if DEVICE_TECHNOLOGY_KEY in device_config_json: + device.technology = device_config_json.get(DEVICE_TECHNOLOGY_KEY) + + if DEVICE_TEST_PACK_KEY in device_config_json: + device.test_pack = device_config_json.get(DEVICE_TEST_PACK_KEY) + + if None in [device.type, device.technology, device.test_pack]: + LOGGER.warning('Device is outdated and requires further configuration') + device.status = 'Invalid' + self._load_test_reports(device) # Add device to device repository diff --git a/make/DEBIAN/control b/make/DEBIAN/control index 488f69458..707bcab41 100644 --- a/make/DEBIAN/control +++ b/make/DEBIAN/control @@ -1,5 +1,5 @@ Package: Testrun -Version: 1.3.1 +Version: 2.0-a Architecture: amd64 Maintainer: Google Homepage: https://github.com/google/testrun From 4256d205b3b800af951475a1d6b7480ab140f8c3 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Wed, 21 Aug 2024 13:57:07 +0100 Subject: [PATCH 2/2] Fix pylint issue --- framework/python/src/core/testrun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index de6ef98c1..5399df863 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -208,7 +208,8 @@ def _load_devices(self, device_dir): device.test_pack = device_config_json.get(DEVICE_TEST_PACK_KEY) if None in [device.type, device.technology, device.test_pack]: - LOGGER.warning('Device is outdated and requires further configuration') + LOGGER.warning( + 'Device is outdated and requires further configuration') device.status = 'Invalid' self._load_test_reports(device)