Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ testing/unit/dns/output/
testing/unit/nmap/output/
testing/unit/ntp/output/
testing/unit/tls/output/
testing/unit/tls/tmp/
testing/unit/report/output/

*.deb
Expand Down
9 changes: 1 addition & 8 deletions cmd/package
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
# Creates a package for Testrun

MAKE_SRC_DIR=make
TESTRUN_VER="1-2-2"

# Delete existing make files
rm -rf $MAKE_SRC_DIR/usr

# Delete existing make files
rm -rf $MAKE_SRC_DIR/usr
Expand Down Expand Up @@ -60,7 +56,4 @@ 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

# Echo package version
echo Created installation package at testrun_${TESTRUN_VER}_amd64.deb
mv make.deb testrun_1-2-1_amd64.deb
5 changes: 1 addition & 4 deletions docs/get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,5 @@ If you encounter any issues or need assistance, consider the following:
- Check the configuration settings.
- Refer to the Testrun documentation or ask for assistance in the issues page: https://github.com/google/testrun/issues

# Reviewing
Once you have completed a test attempt, you may want to review the test report provided by Testrun. For more information about what Testrun looks for when testing, and what the output means, take a look at the testing documentation: [Testing](/docs/test/index.md).

# Uninstall
To uninstall Testrun, use the built-in dpkg uninstall command to remove Testrun correctly. For Testrun, this would be: ```sudo apt-get remove testrun```. Note that this
To uninstall Testrun, use the built-in dpkg uninstall command to remove Testrun correctly. For Testrun, this would be: ```sudo apt-get remove testrun```
5 changes: 0 additions & 5 deletions docs/test/index.md

This file was deleted.

32 changes: 0 additions & 32 deletions docs/test/statuses.md

This file was deleted.

48 changes: 9 additions & 39 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import os
import psutil
import requests
import signal
import threading
import uvicorn
from urllib.parse import urlparse
Expand All @@ -47,7 +46,7 @@ class Api:
def __init__(self, test_run):

self._test_run = test_run
self._name = "Testrun API"
self._name = "TestRun API"
self._router = APIRouter()

self._session = self._test_run.get_session()
Expand All @@ -67,9 +66,6 @@ def __init__(self, test_run):
methods=["POST"])
self._router.add_api_route("/system/status",
self.get_status)
self._router.add_api_route("/system/shutdown",
self.shutdown,
methods=["POST"])

self._router.add_api_route("/system/version",
self.get_version)
Expand Down Expand Up @@ -247,35 +243,8 @@ async def stop_test_run(self):
async def get_status(self):
return self._test_run.get_session().to_json()

def shutdown(self, response: Response):

LOGGER.debug("Received request to shutdown Testrun")

# Check that Testrun is not currently running
if (self._session.get_status() not in [
"Cancelled",
"Compliant",
"Non-Compliant",
"Idle"]):
LOGGER.debug("Unable to shutdown Testrun as Testrun is in progress")
response.status_code = 400
return self._generate_msg(
False,
"Unable to shutdown. A test is currently in progress."
)

self._test_run.shutdown()
os.kill(os.getpid(), signal.SIGTERM)

async def get_version(self, response: Response):

# Add defaults
json_response = {}
json_response["installed_version"] = "v" + self._test_run.get_version()
json_response["update_available"] = False
json_response["latest_version"] = None
json_response["latest_version_url"] = (
"https://github.com/google/testrun/releases")

# Obtain the current version
current_version = self._session.get_version()
Expand All @@ -295,9 +264,9 @@ async def get_version(self, response: Response):
# Check OK response was received
if version_check.status_code != 200:
response.status_code = 500
LOGGER.debug(version_check.content)
LOGGER.error("Failed to fetch latest version")
return json_response
LOGGER.error(version_check.content)
return self._generate_msg(False, "Failed to fetch latest version. " +
"Please, check the internet connection")

# Extract version number from response, removing the leading 'v'
latest_version_no = version_check.json()["name"].strip("v")
Expand All @@ -320,7 +289,8 @@ async def get_version(self, response: Response):
response.status_code = 500
LOGGER.error("Failed to fetch latest version")
LOGGER.debug(e)
return json_response
return self._generate_msg(False, "Failed to fetch latest version. " +
"Please, check the internet connection")

async def get_reports(self, request: Request):
LOGGER.debug("Received reports list request")
Expand All @@ -334,7 +304,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):
Expand Down Expand Up @@ -561,8 +531,8 @@ def _validate_device_json(self, json_obj):
return False

# Check length of strings
if len(json_obj.get(DEVICE_MANUFACTURER_KEY)) > 28 or len(
json_obj.get(DEVICE_MODEL_KEY)) > 28:
if len(json_obj.get(DEVICE_MANUFACTURER_KEY)) > 64 or len(
json_obj.get(DEVICE_MODEL_KEY)) > 64:
return False

disallowed_chars = ["/", "\\", "\'", "\"", ";"]
Expand Down
3 changes: 0 additions & 3 deletions framework/python/src/common/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ 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:
Expand Down
24 changes: 10 additions & 14 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

LOGGER = logger.get_logger('session')

class TestrunSession():
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
Expand All @@ -46,7 +46,8 @@ def __init__(self, config_file, version):
self._total_tests = 0
self._report_url = None

self._load_version(default_version=version)
self._version = None
self._load_version()

self._config_file = config_file
self._config = self._get_default_config()
Expand Down Expand Up @@ -89,7 +90,7 @@ def _get_default_config(self):
'log_level': 'INFO',
'startup_timeout': 60,
'monitor_period': 30,
'max_device_reports': 0,
'max_device_reports': 5,
'api_url': 'http://localhost',
'api_port': 8000
}
Expand Down Expand Up @@ -140,18 +141,14 @@ 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
# it has any data in it, there was an error and we
# did not resolve the version and we'll use the fallback
if len(version_cmd[1]) == 0:

if version_cmd:
version = version_cmd[0]
self._version = version
else:
self._version = default_version
LOGGER.info(f'Running Testrun version {self._version}')
LOGGER.info(f'Running Testrun version {version}')
self._version = version

def get_version(self):
return self._version
Expand Down Expand Up @@ -297,7 +294,6 @@ def reset(self):
self.set_target_device(None)
self._report_url = None
self._total_tests = 0
self._module_reports = []
self._results = []
self._started = None
self._finished = None
Expand Down
Loading