Commit 3e392d9b authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

OFC25 test:

- Fixed discovery of GitLab Runner IP address so that it can be used for onboarding IP and optical controllers
parent cea4f014
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -260,8 +260,13 @@ end2end_test ofc25:

    # ===== Run End-to-End tests ========================================================
    - if docker ps -a | grep ${TEST_NAME}; then docker rm -f ${TEST_NAME}; fi
    - export TFS_RUNNER_IP=$(ip -4 route get 1.1.1.1 | awk '{for (i=1; i<=NF; ++i) if ($i == "src") {print $(i+1); exit}}')
    - if [ -z "${TFS_RUNNER_IP}" ]; then export TFS_RUNNER_IP=$(hostname -I | awk '{print $1}'); fi
    - if [ -z "${TFS_RUNNER_IP}" ]; then echo "Unable to determine TFS_RUNNER_IP on GitLab runner host"; exit 1; fi
    - echo "Using GitLab runner host IP ${TFS_RUNNER_IP} for OFC25 E2E descriptor materialization"
    - >
      docker run -t --rm --name ${TEST_NAME} --network=host 
      --env TFS_RUNNER_IP="${TFS_RUNNER_IP}"
      --volume "$PWD/tfs_runtime_env_vars_opt.sh:/var/teraflow/tfs_runtime_env_vars_opt.sh"
      --volume "$PWD/tfs_runtime_env_vars_ip.sh:/var/teraflow/tfs_runtime_env_vars_ip.sh"
      --volume "$PWD/tfs_runtime_env_vars_e2e.sh:/var/teraflow/tfs_runtime_env_vars_e2e.sh"
+6 −0
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@ The test expects these runtime files (generated by `deploy/tfs.sh`) in `/var/ter

These are parsed by fixtures in `tests/Fixtures.py` to build gRPC clients for all three TFS instances.

For `topology_e2e.json`, the test also requires `TFS_RUNNER_IP`:
- this must be the GitLab runner host IP address, not the Docker container IP,
- the test rewrites the E2E descriptor at runtime so `_connect/address` points to that host.

## Test Flow
`run_test.sh all` runs:
1. Bootstrap `opt` (parameterized bootstrap test with `topology_opt.json`)
@@ -97,3 +101,5 @@ PYTHONPATH=src python -m pytest -v src/tests/ofc25/tests/test_functional_cleanup

## CI / Docker
The OFC25 Docker test image (`src/tests/ofc25/Dockerfile`) executes the same sequence via `/var/teraflow/run_tests.sh`, writing JUnit reports under `/opt/results`.

In GitLab CI, `src/tests/ofc25/.gitlab-ci.yml` discovers the runner host IP before `docker run` and passes it as `TFS_RUNNER_IP` into the test container. This is required because detecting the address from inside the container would return the container/network namespace address instead of the host address that `e2e` must reach.
+39 −0
Original line number Diff line number Diff line
@@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import os
import tempfile
from pathlib import Path

import pytest
@@ -22,6 +25,8 @@ from .Fixtures import (
    RUNTIME_ENV_DIR, tfs_clients, tfs_profiles
)

E2E_TOPOLOGY_DESCRIPTOR = 'topology_e2e.json'


def pytest_addoption(parser):
    parser.addoption(
@@ -52,6 +57,36 @@ def _require_option(request: pytest.FixtureRequest, option_name: str) -> str:
    return value


def _require_runner_ip() -> str:
    runner_ip = os.environ.get('TFS_RUNNER_IP')
    if runner_ip:
        return runner_ip
    raise RuntimeError(
        'Missing TFS_RUNNER_IP environment variable required to materialize the OFC25 E2E topology descriptor'
    )


def _materialize_e2e_descriptor(descriptor_path: Path) -> str:
    runner_ip = _require_runner_ip()
    descriptor_data = json.loads(descriptor_path.read_text(encoding='utf-8'))

    for device in descriptor_data.get('devices', []):
        config_rules = device.get('device_config', {}).get('config_rules', [])
        for config_rule in config_rules:
            custom = config_rule.get('custom', {})
            if custom.get('resource_key') == '_connect/address':
                custom['resource_value'] = runner_ip

    tmp_file = tempfile.NamedTemporaryFile(
        mode='w', suffix='-ofc25-topology-e2e.json', prefix='codex-', delete=False, encoding='utf-8'
    )
    with tmp_file:
        json.dump(descriptor_data, tmp_file, indent=4)
        tmp_file.write('\n')

    return tmp_file.name


@pytest.fixture(scope='session')
def selected_tfs_profile(request: pytest.FixtureRequest) -> str:
    return _require_option(request, 'tfs_profile')
@@ -78,6 +113,10 @@ def selected_topology_descriptor(request: pytest.FixtureRequest) -> str:
        descriptor_path = Path(__file__).resolve().parent.parent / 'descriptors' / descriptor
    if not descriptor_path.exists():
        raise FileNotFoundError('Topology descriptor not found: {:s}'.format(str(descriptor_path)))

    if descriptor_path.name == E2E_TOPOLOGY_DESCRIPTOR:
        return _materialize_e2e_descriptor(descriptor_path)

    return str(descriptor_path)