From 05f70d4853e991cf68b76bd36edf6b5df807639b Mon Sep 17 00:00:00 2001 From: Mohammad Torkashvand <mohammad.torkashvand@geant.org> Date: Fri, 19 Jul 2024 16:43:39 +0200 Subject: [PATCH] remove proccess api --- gso/__init__.py | 2 +- gso/api/v1/processes.py | 40 ------------------------------ gso/services/infoblox.py | 2 +- gso/worker.py | 2 +- test/api/test_processes.py | 51 -------------------------------------- 5 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 gso/api/v1/processes.py delete mode 100644 test/api/test_processes.py diff --git a/gso/__init__.py b/gso/__init__.py index 38607bf1..c5dbc6b0 100644 --- a/gso/__init__.py +++ b/gso/__init__.py @@ -34,7 +34,7 @@ def init_worker_app() -> OrchestratorCore: def init_cli_app() -> typer.Typer: """Initialise :term:`GSO` as a CLI application.""" - from gso.cli import imports, netbox + from gso.cli import imports, netbox # noqa: PLC0415 cli_app.add_typer(imports.app, name="import-cli") cli_app.add_typer(netbox.app, name="netbox-cli") diff --git a/gso/api/v1/processes.py b/gso/api/v1/processes.py deleted file mode 100644 index f4977ed4..00000000 --- a/gso/api/v1/processes.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Process related endpoints.""" - -from typing import Any -from uuid import UUID - -from fastapi import APIRouter, Depends, HTTPException, status -from orchestrator.db import ProcessStepTable -from orchestrator.schemas.base import OrchestratorBaseModel -from orchestrator.security import authorize - -router = APIRouter(prefix="/processes", tags=["Processes"], dependencies=[Depends(authorize)]) - - -class CallBackResultsBaseModel(OrchestratorBaseModel): - """Base model for callback results.""" - - callback_results: dict - - -@router.get( - "/steps/{step_id}/callback-results", status_code=status.HTTP_200_OK, response_model=CallBackResultsBaseModel -) -def callback_results(step_id: UUID) -> dict[str, Any]: - """Retrieve callback results for a specific process step. - - :param step_id: The unique identifier of the process step. - :type step_id: UUID - - :return: Dictionary containing callback results. - :rtype: dict[str, Any] - - :raises HTTPException: 404 status code if the specified step_id is not found or if the 'callback_result' key - is not present in the state. - """ - step = ProcessStepTable.query.filter(ProcessStepTable.step_id == step_id).first() - - if not (step and step.state.get("callback_result", None)): - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Callback result not found.") - - return {"callback_results": step.state["callback_result"]} diff --git a/gso/services/infoblox.py b/gso/services/infoblox.py index 9fc668cd..d340ce97 100644 --- a/gso/services/infoblox.py +++ b/gso/services/infoblox.py @@ -37,7 +37,7 @@ def _setup_connection() -> tuple[connector.Connector, IPAMParams]: return connector.Connector(options), oss -def _allocate_network( +def _allocate_network( # noqa: PLR0917 conn: connector.Connector, dns_view: str, network_view: str, diff --git a/gso/worker.py b/gso/worker.py index b1a3db2c..b2abfe6f 100644 --- a/gso/worker.py +++ b/gso/worker.py @@ -9,7 +9,7 @@ from gso.settings import load_oss_params class OrchestratorCelery(Celery): """A :term:`GSO` instance that functions as a Celery worker.""" - def on_init(self) -> None: + def on_init(self) -> None: # noqa: PLR6301 """Initialise a new Celery worker.""" init_worker_app() diff --git a/test/api/test_processes.py b/test/api/test_processes.py deleted file mode 100644 index f56fe526..00000000 --- a/test/api/test_processes.py +++ /dev/null @@ -1,51 +0,0 @@ -from uuid import uuid4 - -import pytest -from orchestrator.db import ( - ProcessStepTable, - ProcessSubscriptionTable, - ProcessTable, - db, -) -from orchestrator.workflow import ProcessStatus - - -@pytest.fixture() -def create_process(test_workflow, nokia_router_subscription_factory): - process_id = uuid4() - process = ProcessTable( - process_id=process_id, workflow_id=test_workflow.workflow_id, last_status=ProcessStatus.SUSPENDED - ) - subscription = nokia_router_subscription_factory() - process_subscription = ProcessSubscriptionTable(process_id=process_id, subscription_id=subscription) - - db.session.add(process) - db.session.add(process_subscription) - db.session.commit() - - return process_id - - -def test_callback_results_endpoint(test_client, create_process, faker): - expected_result = {"id": 1, "output": faker.sentence()} - - step = ProcessStepTable( - process_id=create_process, - name="Modify", - status="suspend", - state={"subscription_id": uuid4(), "callback_result": expected_result}, - ) - db.session.add(step) - db.session.commit() - - response = test_client.get(f"/api/v1/processes/steps/{step.step_id}/callback-results") - - assert response.status_code == 200 - assert response.json() == {"callback_results": expected_result} - - -def test_callback_results_endpoint_with_wrong_step_id(test_client): - response = test_client.get(f"/api/v1/processes/steps/{uuid4()}/callback-results") - - assert response.status_code == 404 - assert response.json() == {"detail": "Callback result not found."} -- GitLab