Skip to content
Merged
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
34 changes: 34 additions & 0 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def __init__(self, test_run):
self.edit_device,
methods=["POST"])

# Load modules
self._router.add_api_route("/system/modules",
self.get_test_modules)

self._router.add_api_route("/system/config/certs",
self.get_certs)
self._router.add_api_route("/system/config/certs",
Expand All @@ -112,6 +116,10 @@ def __init__(self, test_run):
self.delete_cert,
methods=["DELETE"])

# Profiles
self._router.add_api_route("/profiles/format",
self._get_profiles_format)

# Allow all origins to access the API
origins = ["*"]

Expand Down Expand Up @@ -143,6 +151,9 @@ def _start(self):
def stop(self):
LOGGER.info("Stopping API")

def get_session(self):
return self._session

async def get_sys_interfaces(self):
addrs = psutil.net_if_addrs()
ifaces = {}
Expand Down Expand Up @@ -597,6 +608,22 @@ def _validate_device_json(self, json_obj):

return True

def _get_test_run(self):
return self._test_run

# Profiles
def _get_profiles_format(self, response: Response):

# Check if Testrun was able to load the format originally
if self.get_session().get_profiles_format() is None:
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
return self._generate_msg(
False,
"Testrun could not load the risk assessment format")

return self.get_session().get_profiles_format()

# Certificates
def get_certs(self):
LOGGER.debug("Received certs list request")

Expand Down Expand Up @@ -687,3 +714,10 @@ async def delete_cert(self, request: Request, response: Response):
except Exception as e:
LOGGER.error("An error occurred whilst deleting a certificate")
LOGGER.debug(e)

def get_test_modules(self):
modules = []
for module in self._test_run.get_test_orc().get_test_modules():
if module.enabled and module.enable_container:
modules.append(module.display_name)
return modules
11 changes: 7 additions & 4 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
PROFILE_FORMAT_PATH = 'resources/risk_assessment.json'
PROFILES_DIR = 'local/profiles'

PROFILE_FORMAT_PATH = 'resources/risk_assessment.json'
PROFILES_DIR = 'local/profiles'

LOGGER = logger.get_logger('session')

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 @@ -83,7 +86,7 @@ def __init__(self, root_dir, version):
self._config = self._get_default_config()

# Loading methods
self._load_version(default_version=version)
self._load_version()
self._load_config()
self._load_profiles()

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 @@ -189,7 +192,7 @@ def _load_version(self, default_version):
version = version_cmd[0]
self._version = version
else:
self._version = default_version
self._version = 'Unknown'
LOGGER.info(f'Running Testrun version {self._version}')

def get_version(self):
Expand Down
3 changes: 1 addition & 2 deletions framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,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
4 changes: 2 additions & 2 deletions resources/risk_assessment.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
},
{
"question": "How will this device be used at Google?",
"type": "text",
"type": "text-long",
"validation": {
"max": "128",
"required": true
}
},
{
"question": "What is the email of the device owner(s)?",
"type": "text",
"type": "email-multiple",
"validation": {
"required": true,
"max": "128"
Expand Down