From 69089c84ae9bc65de0df88427d8f4a7d474465bd Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Tue, 14 May 2024 15:41:20 +0100 Subject: [PATCH 1/3] Reduce locations of Testrun version --- cmd/package | 12 +++++++++--- framework/python/src/common/testreport.py | 15 ++++++++++++--- framework/python/src/common/util.py | 2 -- framework/python/src/core/testrun.py | 3 ++- .../python/src/test_orc/test_orchestrator.py | 4 ++++ make/DEBIAN/control | 2 +- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/cmd/package b/cmd/package index cdc7cc8cf..a8c9e1c3b 100755 --- a/cmd/package +++ b/cmd/package @@ -17,7 +17,13 @@ # Creates a package for Testrun MAKE_SRC_DIR=make -TESTRUN_VER="1-2-2" +MAKE_CONTROL_DIR=make/DEBIAN/control + +# Edit the version in make/DEBIAN/control +version=$(grep -R "Version: " $MAKE_CONTROL_DIR | awk '{print $2}') + +# Replace invalid characters +version="${version//./_}" # Delete existing make files rm -rf $MAKE_SRC_DIR/usr @@ -60,7 +66,7 @@ cp -r {framework,modules} $MAKE_SRC_DIR/usr/local/testrun dpkg-deb --build --root-owner-group make # Rename the .deb file -mv make.deb testrun_${TESTRUN_VER}_amd64.deb +mv make.deb testrun_${version}_amd64.deb # Echo package version -echo Created installation package at testrun_${TESTRUN_VER}_amd64.deb +echo Created installation package at testrun_${version}_amd64.deb diff --git a/framework/python/src/common/testreport.py b/framework/python/src/common/testreport.py index 45687b866..96d0516bd 100644 --- a/framework/python/src/common/testreport.py +++ b/framework/python/src/common/testreport.py @@ -57,8 +57,7 @@ def __init__(self, self._module_reports = [] self._report_url = '' self._cur_page = 0 - # Placeholder until available in json report - self._version = 'v1.2.2' + self._version = None def get_mac_addr(self): return self._mac_addr @@ -90,13 +89,17 @@ 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['testrun'] = { + 'version': self._version + } + report_json['mac_addr'] = self._mac_addr report_json['device'] = self._device report_json['status'] = self._status @@ -125,6 +128,12 @@ def to_json(self): def from_json(self, json_file): + # Version added in v1.3-alpha + if 'testrun' in json_file and 'version' in json_file['testrun']: + self._version = json_file['testrun']['version'] + else: + self._version = '1.3-alpha' + self._device['mac_addr'] = json_file['device']['mac_addr'] self._device['manufacturer'] = json_file['device']['manufacturer'] self._device['model'] = json_file['device']['model'] diff --git a/framework/python/src/common/util.py b/framework/python/src/common/util.py index e588640ae..096aaf4df 100644 --- a/framework/python/src/common/util.py +++ b/framework/python/src/common/util.py @@ -43,10 +43,8 @@ def run_command(cmd, output=True): LOGGER.error('Error: ' + err_msg) else: success = True - LOGGER.debug('Command succeeded: ' + cmd) if output: out = stdout.strip().decode('utf-8') - LOGGER.debug('Command output: ' + out) return out, stderr else: return success diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 71070e2cc..38c79b910 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -60,7 +60,8 @@ DEVICE_TEST_MODULES = 'test_modules' MAX_DEVICE_REPORTS_KEY = 'max_device_reports' -VERSION = '1.2.2' +# Does not need to be updated all the time, just a fallback +VERSION = '1.3-alpha' class Testrun: # pylint: disable=too-few-public-methods """Test Run controller. diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index d7f94bcd7..32135254d 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -160,6 +160,10 @@ def _write_reports(self, test_report): def _generate_report(self): report = {} + report["testrun"] = { + "version": self.get_session().get_version() + } + 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( diff --git a/make/DEBIAN/control b/make/DEBIAN/control index dff4ce378..9ea73aaa1 100644 --- a/make/DEBIAN/control +++ b/make/DEBIAN/control @@ -1,5 +1,5 @@ Package: Testrun -Version: 1.2.2 +Version: 1.3-alpha Architecture: amd64 Maintainer: Google Homepage: https://github.com/google/testrun From 186042017dd226bdf1c63982d75e86aecb0d7932 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Tue, 21 May 2024 13:08:01 +0100 Subject: [PATCH 2/3] Update from comments --- framework/python/src/common/session.py | 11 ++++++----- framework/python/src/common/testreport.py | 11 +---------- framework/python/src/core/testrun.py | 8 ++------ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/framework/python/src/common/session.py b/framework/python/src/common/session.py index df7a1c3b2..7c865b75c 100644 --- a/framework/python/src/common/session.py +++ b/framework/python/src/common/session.py @@ -34,7 +34,7 @@ class TestrunSession(): """Represents the current session of Test Run.""" - def __init__(self, config_file, version): + def __init__(self, config_file): self._status = 'Idle' self._device = None self._started = None @@ -46,7 +46,7 @@ def __init__(self, config_file, version): self._total_tests = 0 self._report_url = None - self._load_version(default_version=version) + self._load_version() self._config_file = config_file self._config = self._get_default_config() @@ -140,7 +140,7 @@ def _load_config(self): LOGGER.debug(self._config) - def _load_version(self, default_version): + def _load_version(self): version_cmd = util.run_command( 'dpkg-query --showformat=\'${Version}\' --show testrun') # index 1 of response is the stderr byte stream so if @@ -149,9 +149,10 @@ def _load_version(self, default_version): if len(version_cmd[1]) == 0: version = version_cmd[0] self._version = version + LOGGER.info(f'Running Testrun version {self._version}') else: - self._version = default_version - LOGGER.info(f'Running Testrun version {self._version}') + self._version = '?' + LOGGER.error('An error occurred when resolving the version of Testrun') def get_version(self): return self._version diff --git a/framework/python/src/common/testreport.py b/framework/python/src/common/testreport.py index 84bf4980a..a2915a0df 100644 --- a/framework/python/src/common/testreport.py +++ b/framework/python/src/common/testreport.py @@ -61,9 +61,6 @@ def __init__(self, def get_mac_addr(self): return self._mac_addr - def get_mac_addr(self): - return self._mac_addr - def add_module_reports(self, module_reports): self._module_reports = module_reports @@ -95,12 +92,6 @@ def get_report_url(self): def set_mac_addr(self, mac_addr): self._mac_addr = mac_addr - def set_mac_addr(self, mac_addr): - self._mac_addr = mac_addr - - def set_mac_addr(self, mac_addr): - self._mac_addr = mac_addr - def to_json(self): report_json = {} @@ -140,7 +131,7 @@ def from_json(self, json_file): if 'testrun' in json_file and 'version' in json_file['testrun']: self._version = json_file['testrun']['version'] else: - self._version = '1.3-alpha' + self._version = 'Unknown' self._device['mac_addr'] = json_file['device']['mac_addr'] self._device['manufacturer'] = json_file['device']['manufacturer'] diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 2a9e1deaf..cf054568d 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -60,9 +60,6 @@ DEVICE_TEST_MODULES = 'test_modules' MAX_DEVICE_REPORTS_KEY = 'max_device_reports' -# Does not need to be updated all the time, just a fallback -VERSION = '1.3-alpha' - class Testrun: # pylint: disable=too-few-public-methods """Test Run controller. @@ -90,8 +87,7 @@ def __init__(self, self._register_exits() # Create session - self._session = TestrunSession(config_file=self._config_file, - version=self.get_version()) + self._session = TestrunSession(config_file=self._config_file) # Register runtime parameters if single_intf: @@ -136,7 +132,7 @@ def __init__(self, time.sleep(1) def get_version(self): - return VERSION + return self.get_session().get_version() def load_all_devices(self): self._session.clear_device_repository() From 382167b936d70a4df2e7380d538114f4a1f7c39e Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 30 May 2024 21:32:35 +0100 Subject: [PATCH 3/3] Resolve make control file --- framework/python/src/common/session.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/python/src/common/session.py b/framework/python/src/common/session.py index 61fb8b3f5..949bbe904 100644 --- a/framework/python/src/common/session.py +++ b/framework/python/src/common/session.py @@ -87,7 +87,7 @@ def __init__(self, root_dir): self._config = self._get_default_config() # Loading methods - self._load_version(default_version=version) + self._load_version() self._load_config() self._load_profiles() @@ -192,10 +192,15 @@ def _load_version(self): if len(version_cmd[1]) == 0: version = version_cmd[0] self._version = version - LOGGER.info(f'Running Testrun version {self._version}') else: - self._version = '?' - LOGGER.error('An error occurred when resolving the version of Testrun') + LOGGER.debug('Failed getting the version from dpkg-query') + # Try getting the version from the make control file + try: + version = util.run_command('$(grep -R "Version: " $MAKE_CONTROL_DIR | awk "{print $2}"') + except Exception as e: + LOGGER.debug('Failed getting the version from make control file') + LOGGER.error(e) + self._version = 'Unknown' def get_version(self): return self._version