diff --git a/gso/api/v1/__init__.py b/gso/api/v1/__init__.py index 8772f54efc9ece49a95f43b3df3cdde92269b58f..e2493364c7349d5223c01585999967de6d6d59d3 100644 --- a/gso/api/v1/__init__.py +++ b/gso/api/v1/__init__.py @@ -4,8 +4,10 @@ from fastapi import APIRouter from gso.api.v1.network import router as network_router from gso.api.v1.subscriptions import router as subscriptions_router +from gso.api.v1.version import router as version_router router = APIRouter() router.include_router(subscriptions_router) router.include_router(network_router) +router.include_router(version_router) diff --git a/gso/api/v1/version.py b/gso/api/v1/version.py new file mode 100644 index 0000000000000000000000000000000000000000..96cc37f83d6465213c7e2a9803bec66df6e5cbc8 --- /dev/null +++ b/gso/api/v1/version.py @@ -0,0 +1,20 @@ +"""API for getting the version of the orchestrator.""" + +from fastapi import APIRouter, Depends +from orchestrator.graphql.resolvers.version import VERSIONS +from orchestrator.security import authorize +from starlette import status + +router = APIRouter(prefix="/version", tags=["Network"], dependencies=[Depends(authorize)]) + + +@router.get("/", status_code=status.HTTP_200_OK) +def version() -> dict[str, str]: + """Get the version of deployed services.""" + version_dict = {} + for item in VERSIONS: + if ":" in item: + key, value = item.split(":", 1) + version_dict[key.strip()] = value.strip() + + return version_dict diff --git a/test/__init__.py b/test/__init__.py index d9001c9314bacef63647c108731562e2f4194f99..433e89b0fcb66b0730237cc78cded4048140751c 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,4 +1,3 @@ -import os from uuid import uuid4 LSO_RESULT_SUCCESS = { @@ -20,5 +19,3 @@ LSO_RESULT_FAILURE = { } USER_CONFIRM_EMPTY_FORM = [{}] - -os.environ["TESTING"] = "true" diff --git a/test/api/test_version.py b/test/api/test_version.py new file mode 100644 index 0000000000000000000000000000000000000000..ffcf7acb118fccdf06e4a06430496d435a0ae494 --- /dev/null +++ b/test/api/test_version.py @@ -0,0 +1,21 @@ +from importlib import metadata + + +def test_version_endpoint(test_client, monkeypatch): + """ + Test that the /version endpoint returns the correct versions: + """ + response = test_client.get("api/v1/version") + + assert response.status_code == 200 + + data = response.json() + + assert data == { + "GAP Ansible collection": "Unknown", + "GÉANT Service Orchestrator": metadata.version("geant-service-orchestrator"), + "GÉANT Service Orchestrator GUI": "Unknown", + "LSO": "Unknown", + "Moodi Ansible collection": "Unknown", + "orchestrator-core": "3.1.1", + } diff --git a/test/conftest.py b/test/conftest.py index 2c015bd1b54c0467322e716daa6fb3dbf53c8c5e..926cd183b0b50593f65b390d8a357eb73e337fd6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -54,13 +54,16 @@ class UseJuniperSide(strEnum): def pytest_configure(config): """Set an environment variable before loading any test modules.""" - config_filename = "gso/oss-params-example.json" - os.environ["OSS_PARAMS_FILENAME"] = config_filename + # Set environment variables for the test session + os.environ["OSS_PARAMS_FILENAME"] = "gso/oss-params-example.json" + os.environ["TESTING"] = "true" + # Register finalizers to clean up after tests are done + def cleanup() -> None: + del os.environ["OSS_PARAMS_FILENAME"] + del os.environ["TESTING"] -def pytest_unconfigure(config): - """Clean up the environment variable after all tests.""" - os.environ.pop("OSS_PARAMS_FILENAME", None) + pytest.session_cleanup = cleanup class FakerProvider(BaseProvider):