Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce locations of Testrun version #453

Merged
merged 9 commits into from
May 30, 2024
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-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
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
12 changes: 8 additions & 4 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class TestrunSession():
"""Represents the current session of Test Run."""

def __init__(self, root_dir, version):
def __init__(self, root_dir):
self._root_dir = root_dir

self._status = 'Idle'
Expand Down Expand Up @@ -74,6 +74,9 @@ def __init__(self, root_dir, version):
# 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 @@ -179,7 +182,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
Expand All @@ -188,9 +191,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
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
7 changes: 2 additions & 5 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 @@ -89,8 +87,7 @@ def __init__(self,
self._register_exits()

# Create session
self._session = TestrunSession(root_dir=root_dir,
version=self.get_version())
self._session = TestrunSession(root_dir=root_dir)

# Register runtime parameters
if single_intf:
Expand Down Expand Up @@ -135,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
2 changes: 1 addition & 1 deletion make/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Testrun
Version: 1.2.2
Version: 1.3-alpha
Architecture: amd64
Maintainer: Google <boddey@google.com>
Homepage: /~https://github.com/google/testrun
Expand Down
Loading