Skip to content
Snippets Groups Projects
conftest.py 3.03 KiB
import contextlib
import json
import os
import socket
import tempfile

import pytest


@pytest.fixture(scope="session")
def configuration_data() -> dict:
    with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
        s.bind(("", 0))
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        yield {
            "GENERAL": {"public_hostname": "https://gap.geant.org"},
            "RESOURCE_MANAGEMENT": {"todo": "todo"},
            "IPAM": {
                "INFOBLOX": {
                    "scheme": "https",
                    "wapi_version": "v2.12",
                    "host": "10.0.0.1",
                    "username": "robot-user",
                    "password": "robot-user-password",
                },
                "LO": {
                    "V4": {"containers": [], "networks": ["10.255.255.0/26"], "mask": 32},
                    "V6": {"containers": [], "networks": ["dead:beef::/80"], "mask": 128},
                    "domain_name": ".lo",
                    "dns_view": "default",
                },
                "TRUNK": {
                    "V4": {"containers": ["10.255.255.0/24", "10.255.254.0/24"], "networks": [], "mask": 31},
                    "V6": {"containers": ["dead:beef::/64", "dead:beee::/64"], "networks": [], "mask": 126},
                    "domain_name": ".trunk",
                    "dns_view": "default",
                },
                "GEANT_IP": {
                    "V4": {"containers": ["10.255.255.0/24", "10.255.254.0/24"], "networks": [], "mask": 31},
                    "V6": {"containers": ["dead:beef::/64", "dead:beee::/64"], "networks": [], "mask": 126},
                    "domain_name": ".geantip",
                    "dns_view": "default",
                },
                "SI": {
                    "V4": {"containers": ["10.255.253.128/25"], "networks": [], "mask": 31},
                    "V6": {"containers": [], "networks": [], "mask": 126},
                    "domain_name": ".geantip",
                    "dns_view": "default",
                },
                "LT_IAS": {
                    "V4": {"containers": ["10.255.255.0/24"], "networks": [], "mask": 31},
                    "V6": {"containers": ["dead:beef:cc::/48"], "networks": [], "mask": 126},
                    "domain_name": ".geantip",
                    "dns_view": "default",
                },
            },
            "PROVISIONING_PROXY": {
                "scheme": "https",
                "api_base": "localhost:44444",
                "auth": "Bearer <token>",
                "api_version": 1123,
            },
        }


@pytest.fixture(scope="session")
def data_config_filename(configuration_data) -> str:
    file_name = os.path.join(tempfile.gettempdir(), os.urandom(24).hex())
    open(file_name, "x").close()
    with open(file_name, "wb") as f:
        f.write(json.dumps(configuration_data).encode("utf-8"))
        f.flush()

        os.environ["OSS_PARAMS_FILENAME"] = f.name

        yield f.name