Commit a187432c authored by Georgios P. Katsikas's avatar Georgios P. Katsikas
Browse files

fix: script every stage and condense under single job

parent 77a4fa79
Loading
Loading
Loading
Loading
+30 −52
Changes for src/tests/p4-end-to-end/.gitlab-ci.yml: 30 added lines, 52 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

variables:
  TEST_NAME: 'p4-end-to-end'
  TFS_K8S_NAMESPACE: "tfs"     # has to be identical with the namespace in deploy_specs.sh
  TEST_NAME: "p4-end-to-end"
  TFS_K8S_NAMESPACE: "tfs" # Must match the namespace in deploy_specs.sh
  TFS_DEPLOY_TIMEOUT: "300s"

  MININET_TESTING_DIR: "${CI_PROJECT_DIR}/mininet-testing"
  MININET_TESTING_BRANCH: develop
  REQ_COMPONENTS_FILE: "requested-components.txt"
  MININET_TESTING_URL: "https://labs.etsi.org/rep/tfs/mdg-dataplane-emulation/mininet/mininet-testing.git"
  MININET_TESTING_REF: "develop"
  REQ_COMPONENTS_FILE: "${CI_PROJECT_DIR}/requested-components.txt"

clone_mininet_testing:
p4_end2end_test:
  stage: end2end_test

  script:
    - git clone --quiet https://labs.etsi.org/rep/tfs/mdg-dataplane-emulation/mininet/mininet-testing.git "${MININET_TESTING_DIR}"
    - cd "${MININET_TESTING_DIR}"
    - git checkout --quiet "${MININET_TESTING_BRANCH}"
    - bash "${MININET_TESTING_DIR}/common/ci/collect-tfs-components.sh" > "${REQ_COMPONENTS_FILE}"
    - cat "${REQ_COMPONENTS_FILE}"
    - bash src/tests/p4-end-to-end/scripts/1-tests-clone.sh
    - bash src/tests/p4-end-to-end/scripts/2-tfs-deploy.sh
    - bash src/tests/p4-end-to-end/scripts/3-tests-run.sh
  after_script:
    - bash src/tests/p4-end-to-end/scripts/4-cleanup.sh
  artifacts:
    when: always
    reports:
      junit: src/tests/${TEST_NAME}/report_*.xml
    paths:
      - mininet-testing/
      - ${REQ_COMPONENTS_FILE}
      - requested-components.txt
      - src/tests/${TEST_NAME}/logs/
    expire_in: 1 hour
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'

deploy_tfs_once:
  stage: end2end_test
  needs: ["clone_mininet_testing"]
  script:
    - export REQUESTED_COMPONENTS="$(cat ${REQ_COMPONENTS_FILE})"
    - source src/tests/${TEST_NAME}/deploy_specs.sh
    - bash scripts/ci_prepare_microk8s_storage_registry.sh
    - source scripts/ci_apply_deploy_specs_overrides.sh
    - ./deploy/crdb.sh
    - ./deploy/nats.sh
    - ./deploy/kafka.sh
    - ./deploy/tfs.sh
    - ./deploy/show.sh
    - kubectl --namespace "$TFS_K8S_NAMESPACE" wait --for=condition=Ready pods --all --timeout=300s
  
  rules:
      - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'

run_all_tests:
  stage: end2end_test
  needs: ["deploy_tfs_once"]
  script:
    - echo "Test invoked"

cleanup:
  stage: end2end_test
  when: always
  script:
    - kubectl delete namespaces ${TFS_K8S_NAMESPACE} || true
    - bash scripts/ci_cleanup_gitlab_runner.sh

  rules:
      - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
  artifacts:
      when: always
      reports:
        junit: ./src/tests/${TEST_NAME}/report_*.xml
      paths:
        - ./src/tests/${TEST_NAME}/logs/*
+49 −0
Changes for src/tests/p4-end-to-end/scripts/1-tests-clone.sh: 49 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

: "${CI_PROJECT_DIR:?CI_PROJECT_DIR must be set by GitLab CI}"

TFS_REPO_URL="https://labs.etsi.org/rep/tfs"
TFS_CTRL_REPO_URL=${TFS_REPO_URL}"/controller"
TFS_DP_MDG_REPO_URL=${TFS_REPO_URL}"/mdg-dataplane-emulation/mininet"


MININET_TESTING_URL="${MININET_TESTING_URL:-${TFS_DP_MDG_REPO_URL}/mininet-testing.git}"
MININET_TESTING_REF="${MININET_TESTING_REF:-${MININET_TESTING_BRANCH:-develop}}"
MININET_TESTING_DIR="${MININET_TESTING_DIR:-${CI_PROJECT_DIR}/mininet-testing}"
REQ_COMPONENTS_FILE="${REQ_COMPONENTS_FILE:-${CI_PROJECT_DIR}/requested-components.txt}"

fail() { printf '$0: ERROR: %s\n' "$*" >&2; exit 1; }

[[ -n "$MININET_TESTING_URL" ]] || fail 'MININET_TESTING_URL must not be empty'
[[ -n "$MININET_TESTING_REF" ]] || fail 'MININET_TESTING_REF must not be empty'
[[ "$MININET_TESTING_DIR" == /* ]] || MININET_TESTING_DIR="${CI_PROJECT_DIR}/${MININET_TESTING_DIR}"
[[ "$REQ_COMPONENTS_FILE" == /* ]] || REQ_COMPONENTS_FILE="${CI_PROJECT_DIR}/${REQ_COMPONENTS_FILE}"

if [[ -e "$MININET_TESTING_DIR" ]]; then
  fail "destination already exists: $MININET_TESTING_DIR"
fi

mkdir -p "$(dirname "$MININET_TESTING_DIR")" "$(dirname "$REQ_COMPONENTS_FILE")"
printf 'Cloning Mininet test suite\n'
printf '\tRepository: %s\n' "$MININET_TESTING_URL"
printf '\t       Ref: %s\n' "$MININET_TESTING_REF"
printf '\t Directory: %s\n' "$MININET_TESTING_DIR"

git clone --quiet --no-checkout "$MININET_TESTING_URL" "$MININET_TESTING_DIR" || \
  fail "could not clone $MININET_TESTING_URL"
git -C "$MININET_TESTING_DIR" fetch --quiet origin "$MININET_TESTING_REF" || \
  fail "could not fetch ref '$MININET_TESTING_REF' from $MININET_TESTING_URL"
# git -C "$MININET_TESTING_DIR" checkout --quiet --detach FETCH_HEAD || \
#   fail "could not check out ref '$MININET_TESTING_REF'"

# commit="$(git -C "$MININET_TESTING_DIR" rev-parse HEAD)" || fail 'could not read checked-out commit'
# printf 'Selected ref: %s\nResulting commit: %s\n' "$MININET_TESTING_REF" "$commit"

collector="${MININET_TESTING_DIR}/common/ci/collect-tfs-components.sh"
[[ -f "$collector" ]] || fail "component collector not found: $collector"
(cd "$MININET_TESTING_DIR" && bash "$collector") > "$REQ_COMPONENTS_FILE" || fail 'component collection failed'
printf 'Requested components saved to: %s\n' "$REQ_COMPONENTS_FILE"
cat "$REQ_COMPONENTS_FILE"

exit 0
+34 −0
Changes for src/tests/p4-end-to-end/scripts/2-tfs-deploy.sh: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

: "${CI_PROJECT_DIR:?CI_PROJECT_DIR must be set by GitLab CI}"
: "${TEST_NAME:?TEST_NAME must identify a controller test under src/tests}"

# TEST_NAME="${TEST_NAME:-"p4-end-to-end"}"
TFS_K8S_NAMESPACE="${TFS_K8S_NAMESPACE:-tfs}"
TFS_DEPLOY_TIMEOUT="${TFS_DEPLOY_TIMEOUT:-300s}"
REQ_COMPONENTS_FILE="${REQ_COMPONENTS_FILE:-${CI_PROJECT_DIR}/requested-components.txt}"
[[ "$REQ_COMPONENTS_FILE" == /* ]] || REQ_COMPONENTS_FILE="${CI_PROJECT_DIR}/${REQ_COMPONENTS_FILE}"

fail() { printf '$0: ERROR: %s\n' "$*" >&2; exit 1; }

[[ -f "$REQ_COMPONENTS_FILE" ]] || fail "requested components file not found: $REQ_COMPONENTS_FILE"

cd "$CI_PROJECT_DIR"
[[ -f "src/tests/${TEST_NAME}/deploy_specs.sh" ]] || fail "deploy specs not found: src/tests/${TEST_NAME}/deploy_specs.sh"

# Pass the clone stage's output into this process explicitly via the workspace file.
REQUESTED_COMPONENTS="$(<"$REQ_COMPONENTS_FILE")"
export REQUESTED_COMPONENTS TFS_K8S_NAMESPACE TFS_DEPLOY_TIMEOUT

source "src/tests/${TEST_NAME}/deploy_specs.sh"
bash scripts/ci_prepare_microk8s_storage_registry.sh
source scripts/ci_apply_deploy_specs_overrides.sh
./deploy/crdb.sh
./deploy/nats.sh
./deploy/kafka.sh
./deploy/tfs.sh
./deploy/show.sh
kubectl --namespace "$TFS_K8S_NAMESPACE" wait --for=condition=Ready pods --all --timeout="$TFS_DEPLOY_TIMEOUT"

exit 0
+27 −0
Changes for src/tests/p4-end-to-end/scripts/3-tests-run.sh: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

: "${CI_PROJECT_DIR:?CI_PROJECT_DIR must be set by GitLab CI}"

MININET_TESTING_DIR="${MININET_TESTING_DIR:-${CI_PROJECT_DIR}/mininet-testing}"
[[ "$MININET_TESTING_DIR" == /* ]] || MININET_TESTING_DIR="${CI_PROJECT_DIR}/${MININET_TESTING_DIR}"
TESTS_DIR="${MININET_TESTING_DIR}/tests"

fail() { printf '$0: ERROR: %s\n' "$*" >&2; exit 1; }

[[ -d "$TESTS_DIR" ]] || fail "test suite directory not found: $TESTS_DIR"

shopt -s nullglob
scenarios=("$TESTS_DIR"/*)
shopt -u nullglob
((${#scenarios[@]} > 0)) || fail "no test scenarios found under $TESTS_DIR"

for scenario in "${scenarios[@]}"; do
  [[ -d "$scenario" ]] || continue
  test_script="${scenario}/test.sh"
  [[ -f "$test_script" ]] || fail "scenario is missing test.sh: $scenario"
  printf '\n===== Running scenario: %s =====\n' "$(basename "$scenario")"
  bash "$test_script"
done

exit 0
+19 −0
Changes for src/tests/p4-end-to-end/scripts/4-cleanup.sh: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

TFS_K8S_NAMESPACE="${TFS_K8S_NAMESPACE:-tfs}"

printf 'Cleaning up namespace: %s\n' "$TFS_K8S_NAMESPACE"
if command -v kubectl >/dev/null 2>&1; then
  kubectl delete namespace "$TFS_K8S_NAMESPACE" --wait=false || true
else
  printf '$0: kubectl is unavailable; skipping namespace deletion\n' >&2
fi

if [[ -n "${CI_PROJECT_DIR:-}" && -f "${CI_PROJECT_DIR}/scripts/ci_cleanup_gitlab_runner.sh" ]]; then
  bash "${CI_PROJECT_DIR}/scripts/ci_cleanup_gitlab_runner.sh"
else
  printf '$0: controller runner cleanup script not found; skipping it\n' >&2
fi

exit 0
Loading