Skip to content

Commit

Permalink
Reduce locations of Testrun version (#453)
Browse files Browse the repository at this point in the history
* Reduce locations of Testrun version

* Update from comments

* Resolve make control file

---------

Signed-off-by: J Boddey <boddey@google.com>
  • Loading branch information
jboddey authored May 30, 2024
1 parent 8a14893 commit 7c20ac9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
12 changes: 9 additions & 3 deletions cmd/package
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
# Creates a package for Testrun

MAKE_SRC_DIR=make
TESTRUN_VER="1-3-alpha"
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
Expand Down Expand Up @@ -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
13 changes: 11 additions & 2 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def __init__(self, root_dir):
# Direct url for PDF report
self._report_url = None

# Version
self._load_version()

# Profiles
self._profiles = []
self._profile_format_json = None
Expand Down Expand Up @@ -193,8 +196,14 @@ def _load_version(self):
version = version_cmd[0]
self._version = version
else:
self._version = 'Unknown'
LOGGER.info(f'Running Testrun version {self._version}')
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
Expand Down
15 changes: 10 additions & 5 deletions framework/python/src/common/testreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ def __init__(self,
self._module_reports = []
self._report_url = ''
self._cur_page = 0
# Placeholder until available in json report
self._version = 'v1.3-alpha'

def get_mac_addr(self):
return self._mac_addr

def add_module_reports(self, module_reports):
self._module_reports = module_reports
Expand Down Expand Up @@ -97,6 +92,10 @@ def set_mac_addr(self, 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
Expand Down Expand Up @@ -125,6 +124,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 = 'Unknown'

self._device['mac_addr'] = json_file['device']['mac_addr']
self._device['manufacturer'] = json_file['device']['manufacturer']
self._device['model'] = json_file['device']['model']
Expand Down
1 change: 0 additions & 1 deletion framework/python/src/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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')
if out is not None and len(out) != 0:
Expand Down
4 changes: 1 addition & 3 deletions framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
DEVICE_TEST_MODULES = 'test_modules'
MAX_DEVICE_REPORTS_KEY = 'max_device_reports'

VERSION = '1.3'

class Testrun: # pylint: disable=too-few-public-methods
"""Test Run controller.
Expand Down Expand Up @@ -134,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()
Expand Down
4 changes: 4 additions & 0 deletions framework/python/src/test_orc/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7c20ac9

Please sign in to comment.