Skip to content

Commit

Permalink
Send TERCC event if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
t-persson committed Aug 1, 2024
1 parent e983cad commit e4d821c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
23 changes: 21 additions & 2 deletions projects/etos_suite_runner/src/etos_suite_runner/esr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import threading
from uuid import uuid4

from eiffellib.events import EiffelActivityTriggeredEvent
from eiffellib.events import (
EiffelActivityTriggeredEvent, EiffelTestExecutionRecipeCollectionCreatedEvent,
)
from environment_provider.environment_provider import EnvironmentProvider
from environment_provider.environment import release_full_environment
from etos_lib import ETOS
Expand All @@ -33,6 +35,7 @@

from .lib.esr_parameters import ESRParameters
from .lib.exceptions import EnvironmentProviderException
from .lib.graphql import request_tercc
from .lib.runner import SuiteRunner
from .lib.otel_tracing import get_current_context, OpenTelemetryBase

Expand Down Expand Up @@ -193,6 +196,18 @@ def verify_input() -> None:
assert os.getenv("SOURCE_HOST"), "SOURCE_HOST environment variable not provided."
assert os.getenv("TERCC"), "TERCC environment variable not provided."

def _send_tercc(self, testrun_id: str, iut_id: str) -> None:
"""Send tercc will publish the TERCC event for this testrun."""
self.logger.info("Sending TERCC event")
event = EiffelTestExecutionRecipeCollectionCreatedEvent()
event.meta.event_id = testrun_id
links = {"CAUSE": iut_id}
data = {
"selectionStrategy": {"tracker": "Suite Builder", "id": str(uuid4())},
"batchesUri": os.getenv("SUITE_SOURCE", "Unknown"),
}
self.etos.events.send(event, links, data)

def run(self) -> list[str]:
"""Run the ESR main loop.
Expand All @@ -202,7 +217,11 @@ def run(self) -> list[str]:
try:
testrun_id = self.params.testrun_id
self.logger.info("ETOS suite runner is starting up", extra={"user_log": True})

if os.getenv("IDENTIFIER") is not None:
# We are probably running as a TestRun
if request_tercc(self.etos, testrun_id) is None:
self._send_tercc(testrun_id, self.params.iut_id)

activity_name = "ETOS testrun"
links = {
"CAUSE": [
Expand Down
21 changes: 21 additions & 0 deletions projects/etos_suite_runner/src/etos_suite_runner/lib/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ACTIVITY_FINISHED,
ENVIRONMENTS,
ARTIFACTS,
TERCC,
)


Expand Down Expand Up @@ -166,3 +167,23 @@ def request_environment_defined(etos, activity_id):
yield environment
return None # StopIteration
return None # StopIteration


def request_tercc(etos, tercc_id):
"""Request test execution recipe collection created from graphql.
:param etos: ETOS client instance.
:type etos: :obj:`etos_lib.etos.Etos`
:param tercc_id: ID of tercc
:type tercc_id: str
:return: Tercc graphql response
:rtype: dict
"""
for response in request(etos, TERCC % tercc_id):
if response:
try:
_, tercc = next(etos.graphql.search_for_nodes(response, "testExecutionRecipeCollectionCreated"))
except StopIteration:
return None
return tercc
return None
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,18 @@
}
}
"""


TERCC = """
{
testExecutionRecipeCollectionCreated(search: "{'meta.id': '%s'}") {
edges {
node {
meta {
id
}
}
}
}
}
"""

0 comments on commit e4d821c

Please sign in to comment.