Skip to content

Commit

Permalink
Remove provider registration and configuration (#95)
Browse files Browse the repository at this point in the history
* Remove provider registration and configuration

* more unused code removed

* more unused code removed
  • Loading branch information
andmat900 authored Mar 28, 2024
1 parent 1ac47aa commit 037a9b7
Show file tree
Hide file tree
Showing 25 changed files with 8 additions and 2,968 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ celery~=5.3
cryptography>=42.0.4,<43.0.0
gevent~=23.7
gunicorn~=19.9
falcon~=3.1
jsontas~=1.3
packageurl-python~=0.11
etcd3gw~=2.3
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ install_requires =
cryptography>=42.0.4,<43.0.0
gevent~=23.7
gunicorn~=19.9
falcon~=3.1
jsontas~=1.3
packageurl-python~=0.11
etcd3gw~=2.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
import traceback
from typing import Optional, Union

from celery import Celery
from etos_lib import ETOS
from falcon import Request
from jsontas.jsontas import JsonTas

from environment_provider.environment_provider import get_environment
from environment_provider.lib.database import ETCDPath
from environment_provider.lib.registry import ProviderRegistry
from execution_space_provider import ExecutionSpaceProvider
Expand All @@ -34,33 +31,6 @@
from log_area_provider.log_area import LogArea


def get_environment_id(request: Request) -> Optional[str]:
"""Get the environment ID from request.
:param request: The falcon request object.
:return: The ID of the environment.
"""
return request.get_param("id")


def get_release_id(request: Request) -> Optional[str]:
"""Get the task ID to release, from request.
:param request: The falcon request object.
:return: The ID of the environment to release.
"""
return request.get_param("release")


def get_single_release_id(request: Request) -> Optional[str]:
"""Get the environment ID to release, from request.
:param request: The falcon request object.
:return: The ID of the environment to release.
"""
return request.get_param("single_release")


def checkin_provider(
item: dict, provider: Union[IutProvider, ExecutionSpaceProvider, LogAreaProvider]
) -> tuple[bool, Optional[Exception]]:
Expand Down Expand Up @@ -134,10 +104,11 @@ def release_full_environment(etos: ETOS, jsontas: JsonTas, suite_id: str) -> tup
registry = ProviderRegistry(etos, jsontas, suite_id)
for suite, metadata in registry.testrun.join("suite").read_all():
suite = json.loads(suite)
try:
failure = release_environment(etos, jsontas, registry, suite)
except json.JSONDecodeError as exception:
failure = exception
for sub_suite in suite.get("sub_suites", []):
try:
failure = release_environment(etos, jsontas, registry, sub_suite)
except json.JSONDecodeError as exception:
failure = exception
ETCDPath(metadata.get("key")).delete()
registry.testrun.delete_all()

Expand All @@ -147,33 +118,3 @@ def release_full_environment(etos: ETOS, jsontas: JsonTas, suite_id: str) -> tup
traceback.format_exception(failure, value=failure, tb=failure.__traceback__)
)
return True, ""


def check_environment_status(celery_worker: Celery, environment_id: str) -> dict:
"""Check the status of the environment that is being requested.
:param celery_worker: The worker holding the task results.
:param environment_id: The environment ID to check status on.
:return: A dictionary of status and and result.
"""
task_result = celery_worker.AsyncResult(environment_id)
result = task_result.result
status = task_result.status
if isinstance(result, Exception):
status = "FAILURE"
result = str(result)
elif result and result.get("error") is not None:
status = "FAILURE"
if result:
task_result.get()
return {"status": status, "result": result}


def request_environment(suite_id: str, suite_runner_ids: list[str]) -> str:
"""Request an environment for a test suite ID.
:param suite_id: Suite ID to request an environment for.
:param suite_runner_ids: Suite runner correlation IDs.
:return: The task ID for the request.
"""
return get_environment.delay(suite_id, suite_runner_ids).id
68 changes: 3 additions & 65 deletions src/environment_provider/lib/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from etos_lib.etos import ETOS
from jsontas.jsontas import JsonTas

from execution_space_provider import ExecutionSpaceProvider, execution_space_provider_schema
from iut_provider import IutProvider, iut_provider_schema
from log_area_provider import LogAreaProvider, log_area_provider_schema
from execution_space_provider import ExecutionSpaceProvider
from iut_provider import IutProvider
from log_area_provider import LogAreaProvider

from .database import ETCDPath

Expand Down Expand Up @@ -128,35 +128,6 @@ def get_execution_space_provider_by_id(self, provider_id: str) -> Optional[dict]
return json.loads(provider, object_pairs_hook=OrderedDict)
return None

def register_log_area_provider(self, ruleset: dict) -> None:
"""Register a new log area provider.
:param ruleset: Log area JSON definition to register.
"""
data = self.validate(ruleset, log_area_provider_schema(ruleset))
self.logger.info("Registering %r", data["log"]["id"])
self.providers.join(f"log-area/{data['log']['id']}").write(json.dumps(data))

def register_iut_provider(self, ruleset: dict) -> None:
"""Register a new IUT provider.
:param ruleset: IUT provider JSON definition to register.
"""
data = self.validate(ruleset, iut_provider_schema(ruleset))
self.logger.info("Registering %r", data["iut"]["id"])
self.providers.join(f"iut/{data['iut']['id']}").write(json.dumps(data))

def register_execution_space_provider(self, ruleset: dict) -> None:
"""Register a new execution space provider.
:param ruleset: Execution space provider JSON definition to register.
"""
data = self.validate(ruleset, execution_space_provider_schema(ruleset))
self.logger.info("Registering %r", data["execution_space"]["id"])
self.providers.join(f"execution-space/{data['execution_space']['id']}").write(
json.dumps(data)
)

def execution_space_provider(self) -> Optional[ExecutionSpaceProvider]:
"""Get the execution space provider configured to suite ID.
Expand Down Expand Up @@ -214,36 +185,3 @@ def dataset(self) -> Optional[dict]:
if dataset:
return json.loads(dataset)
return None

# pylint:disable=too-many-arguments
def configure_environment_provider_for_suite(
self,
iut_provider: dict,
log_area_provider: dict,
execution_space_provider: dict,
dataset: dict,
) -> None:
"""Configure environment provider for a suite ID with providers and dataset.
:param iut_provider: IUT provider definition to configure for suite ID.
:param log_area_provider: Log area provider definition to configure for suite ID.
:param execution_space_provider: Execution space provider definition to configure
for suite ID.
:param dataset: Dataset to configure for suite ID.
"""
self.logger.info("Configuring environment provider.")
self.logger.info("Dataset: %r", dataset)
self.logger.info("IUT provider: %r", iut_provider.get("iut", {}).get("id"))
self.logger.info(
"Execution space provider: %r",
execution_space_provider.get("execution_space", {}).get("id"),
)
self.logger.info("Log area provider: %r", log_area_provider.get("log", {}).get("id"))
self.logger.info("Expire: 3600")

self.testrun.join("provider/dataset").write(json.dumps(dataset), expire=3600)
self.testrun.join("provider/iut").write(json.dumps(iut_provider), expire=3600)
self.testrun.join("provider/log-area").write(json.dumps(log_area_provider), expire=3600)
self.testrun.join("provider/execution-space").write(
json.dumps(execution_space_provider), expire=3600
)
41 changes: 0 additions & 41 deletions src/environment_provider_api/.gitignore

This file was deleted.

31 changes: 0 additions & 31 deletions src/environment_provider_api/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions src/environment_provider_api/backend/__init__.py

This file was deleted.

49 changes: 0 additions & 49 deletions src/environment_provider_api/backend/common.py

This file was deleted.

Loading

0 comments on commit 037a9b7

Please sign in to comment.