Skip to content

Commit

Permalink
Make sub suite and main suite IDs available on upload (#50)
Browse files Browse the repository at this point in the history
* Make sub suite and main suite IDs available on upload

We also get the sub suite ID from the environment provider instead
of generating our own. This is so that the sub suite ID can be
available before starting up the ETR, such as in the new log area
API.
  • Loading branch information
t-persson authored Jun 20, 2024
1 parent 0a4083d commit d8996d5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
30 changes: 21 additions & 9 deletions src/etos_test_runner/lib/log_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ def upload_logs(self, logs):
:param logs: Logs to upload.
:type logs: list
"""
log_area_folder = (
f"{self.etos.config.get('main_suite_id')}/{self.etos.config.get('sub_suite_id')}"
)
for log in logs:
log["uri"] = self.__upload(
self.etos.config.get("context"),
log["file"],
log["name"],
log_area_folder,
self.etos.config.get("main_suite_id"),
self.etos.config.get("sub_suite_id"),
)
self.logs.append(log)
log["file"].unlink()
Expand Down Expand Up @@ -202,7 +200,8 @@ def upload_artifacts(self, artifacts):
self.etos.config.get("context"),
artifact["file"],
artifact["name"],
log_area_folder,
self.etos.config.get("main_suite_id"),
self.etos.config.get("sub_suite_id"),
)
self.artifacts.append(artifact)
artifact["file"].unlink()
Expand All @@ -211,12 +210,16 @@ def upload_artifacts(self, artifacts):
data = {
"context": self.etos.config.get("context"),
"folder": log_area_folder,
"sub_suite_id": self.etos.config.get("sub_suite_id"),
"main_suite_id": self.etos.config.get("main_suite_id"),
"name": "",
}
published_url = upload["url"].format(**data)
self._artifact_published(artifact_created, published_url)

def __upload(self, context, log, name, folder):
def __upload(
self, context, log, name, main_suite_id, sub_suite_id
): # pylint:disable=too-many-arguments
"""Upload log to a storage location.
:param context: Context for the http request.
Expand All @@ -225,13 +228,22 @@ def __upload(self, context, log, name, folder):
:type log: str
:param name: Name of file to upload.
:type name: str
:param folder: Folder to upload to.
:type folder: str
:param main_suite_id: Main suite ID for folder creation.
:type main_suite_id: str
:param sub_suite_id: Sub suite ID for folder creation.
:type sub_suite_id: str
:return: URI where log was uploaded to.
:rtype: str
"""
upload = deepcopy(self.log_area.get("upload"))
data = {"context": context, "name": name, "folder": folder}
folder = f"{main_suite_id}/{sub_suite_id}"
data = {
"context": context,
"name": name,
"sub_suite_id": sub_suite_id,
"main_suite_id": main_suite_id,
"folder": folder,
}

# ETOS Library, for some reason, uses the key 'verb' instead of 'method'
# for HTTP method.
Expand Down
24 changes: 14 additions & 10 deletions src/etos_test_runner/lib/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
from pprint import pprint

from eiffellib.events import EiffelTestSuiteStartedEvent
from etos_test_runner.lib.iut_monitoring import IutMonitoring
from etos_test_runner.lib.executor import Executor
from etos_test_runner.lib.workspace import Workspace
Expand Down Expand Up @@ -59,17 +60,20 @@ def test_suite_started(self):
categories.append(self.iut.identity.name)
livelogs = self.config.get("log_area", {}).get("livelogs")

test_suite_started = EiffelTestSuiteStartedEvent()
data = {
"name": suite_name,
"categories": categories,
"types": ["FUNCTIONAL"],
"liveLogs": [{"name": "console", "uri": livelogs}],
}
# TODO: Remove CONTEXT link here.
return self.etos.events.send_test_suite_started(
suite_name,
links={
"CONTEXT": self.etos.config.get("context"),
"CAUSE": self.etos.config.get("main_suite_id"),
},
categories=categories,
types=["FUNCTIONAL"],
liveLogs=[{"name": "console", "uri": livelogs}],
)
links = {
"CONTEXT": self.etos.config.get("context"),
"CAUSE": self.etos.config.get("main_suite_id"),
}
test_suite_started.meta.event_id = self.config.get("sub_suite_id")
return self.etos.events.send(test_suite_started, links, data)

def environment(self, context):
"""Send out which environment we're executing within.
Expand Down
1 change: 1 addition & 0 deletions tests/scenarios/test_full_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"name": "Test ETOS API scenario",
"priority": 1,
"test_suite_started_id": "577381ad-8356-4939-ab77-02e7abe06699",
"sub_suite_id": "677381ad-8356-4939-ab77-02e7abe06688",
"recipes": [
{
"constraints": [
Expand Down
1 change: 1 addition & 0 deletions tests/scenarios/test_log_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"name": "Test ETOS API scenario",
"priority": 1,
"test_suite_started_id": "577381ad-8356-4939-ab77-02e7abe06699",
"sub_suite_id": "677381ad-8356-4939-ab77-02e7abe06688",
"recipes": [
{
"constraints": [
Expand Down
1 change: 1 addition & 0 deletions tests/scenarios/test_no_detected_test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"name": "Test ETOS API scenario undetected test name",
"priority": 1,
"test_suite_started_id": "577381ad-8356-4939-ab77-02e7abe06699",
"sub_suite_id": "677381ad-8356-4939-ab77-02e7abe06688",
"recipes": [
{
"constraints": [
Expand Down

0 comments on commit d8996d5

Please sign in to comment.