diff --git a/projects/etos_suite_runner/src/etos_suite_runner/__init__.py b/projects/etos_suite_runner/src/etos_suite_runner/__init__.py index dfe8232..75d468b 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/__init__.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/__init__.py @@ -50,7 +50,11 @@ if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"): PROVIDER = TracerProvider( resource=Resource.create( - {SERVICE_NAME: "etos-suite-runner", SERVICE_VERSION: VERSION, SERVICE_NAMESPACE: ENVIRONMENT} + { + SERVICE_NAME: "etos-suite-runner", + SERVICE_VERSION: VERSION, + SERVICE_NAMESPACE: ENVIRONMENT, + } ) ) EXPORTER = OTLPSpanExporter() @@ -58,4 +62,4 @@ PROVIDER.add_span_processor(PROCESSOR) trace.set_tracer_provider(PROVIDER) else: - LOGGER.info("Suite runner OTEL_EXPORTER_OTLP_TRACES_ENDPOINT not set!") \ No newline at end of file + LOGGER.info("Suite runner OTEL_EXPORTER_OTLP_TRACES_ENDPOINT not set!") diff --git a/projects/etos_suite_runner/src/etos_suite_runner/__main__.py b/projects/etos_suite_runner/src/etos_suite_runner/__main__.py index 42478c5..5c4e7b7 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/__main__.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/__main__.py @@ -39,9 +39,11 @@ def main(): esr.etos.publisher.stop() LOGGER.info("ESR Finished Executing.", extra={"user_log": True}) + def run(): """Entry point for console_scripts.""" main() + if __name__ == "__main__": run() diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index 611278f..1e348d3 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -41,6 +41,7 @@ SUBSUITE_CONTEXT = None + class ESR: # pylint:disable=too-many-instance-attributes """Suite runner for ETOS main program. @@ -78,7 +79,7 @@ def _request_environment(self, ids: list[str]) -> None: try: provider = EnvironmentProvider(self.params.tercc.meta.event_id, ids, copy=False) result = provider.run() - except Exception as exc: + except Exception: self.params.set_status("FAILURE", "Failed to run environment provider") self.logger.error( "Environment provider has failed in creating an environment for test.", @@ -107,7 +108,7 @@ def _release_environment(self) -> None: jsontas = JsonTas() span_name = "release_full_environment" suite_context = get_current_context() - with self.otel_tracer.start_as_current_span(span_name, context=suite_context) as span: + with self.otel_tracer.start_as_current_span(span_name, context=suite_context): status, message = release_full_environment( etos=self.etos, jsontas=jsontas, suite_id=self.params.tercc.meta.event_id ) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/executor.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/executor.py index 3cfdc0e..e0dc87b 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/executor.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/executor.py @@ -26,7 +26,6 @@ from requests.exceptions import ConnectionError as RequestsConnectionError from requests.exceptions import HTTPError -from ..otel_tracing import get_current_context class TestStartException(Exception): """Exception when starting tests.""" @@ -94,7 +93,7 @@ def run_tests(self, test_suite: dict) -> None: method = getattr(self.etos.http, request.pop("method").lower()) span_name = "start_execution_space" with self.tracer.start_as_current_span(span_name) as span: - span.set_attribute("executor_id", executor['id']) + span.set_attribute("executor_id", executor["id"]) span.set_attribute("request", dumps(request, indent=4)) try: response = method(**request) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py index 3093bd5..ac4767f 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py @@ -67,7 +67,8 @@ def start_suites_and_wait(self): """Get environments and start all test suites.""" try: test_suites = [ - TestSuite(self.etos, self.params, suite, otel_context=self.otel_suite_context) for suite in self.params.test_suite + TestSuite(self.etos, self.params, suite, otel_context=self.otel_suite_context) + for suite in self.params.test_suite ] with ThreadPool() as pool: pool.map(self.run, test_suites) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index 8d9b468..342ece9 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -39,7 +39,6 @@ request_test_suite_started, ) from .log_filter import DuplicateFilter -from ..otel_tracing import get_current_context class SubSuite: # pylint:disable=too-many-instance-attributes @@ -149,7 +148,10 @@ def release(self, testrun_id) -> None: span_name = "release_environment" with self.otel_tracer.start_as_current_span(span_name) as span: failure = release_environment( - etos=self.etos, jsontas=jsontas, provider_registry=registry, sub_suite=self.environment + etos=self.etos, + jsontas=jsontas, + provider_registry=registry, + sub_suite=self.environment, ) span.set_attribute("testrun_id", testrun_id) span.set_attribute("failure", str(failure)) @@ -172,7 +174,12 @@ class TestSuite: # pylint:disable=too-many-instance-attributes __activity_triggered = None __activity_finished = None - def __init__(self, etos: ETOS, params: ESRParameters, suite: dict, otel_context: opentelemetry.context.context.Context = None) -> None: + def __init__(self, + etos: ETOS, + params: ESRParameters, + suite: dict, + otel_context: opentelemetry.context.context.Context = None + ) -> None: """Initialize a TestSuite instance.""" self.etos = etos self.params = params @@ -340,7 +347,8 @@ def start(self) -> None: ) self.sub_suites.append(sub_suite) thread = threading.Thread( - target=sub_suite.start, args=(self.params.tercc.meta.event_id, self.otel_context) + target=sub_suite.start, + args=(self.params.tercc.meta.event_id, self.otel_context), ) threads.append(thread) thread.start() diff --git a/projects/etos_suite_runner/src/etos_suite_runner/otel_tracing.py b/projects/etos_suite_runner/src/etos_suite_runner/otel_tracing.py index 4c0cbd2..c42b3cf 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/otel_tracing.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/otel_tracing.py @@ -21,6 +21,7 @@ LOGGER = logging.getLogger(__name__) + def get_current_context() -> opentelemetry.context.context.Context: """Get current context (propagated via environment variable OTEL_CONTEXT).""" carrier = {}