From d84a7c8b29b3ffef3406e8befa999632964a5f46 Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Fri, 30 Jun 2023 08:22:35 -0300 Subject: [PATCH] fix script to run tests from local dir (#1148) * fix script to run tests from local dir * fix getopts for local * fix script * fix script * fix script * allow default ns to connect zombie namespaces * refactor ci yml * refactor ci yml * refactor ci yml --- .gitlab-ci.yml | 125 +++++++----------- .../namespace-network-policy.yaml | 1 + scripts/ci/run-test-local-env-manager.sh | 35 +++-- 3 files changed, 72 insertions(+), 89 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 235fc4d40..6e83a42f0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ stages: - test - check - publish - - deploy + - zombienet variables: @@ -179,62 +179,62 @@ publish-docker-image-description: script: - cd / && sh entrypoint.sh -zombienet-smoke: - stage: deploy - <<: *kubernetes-env - <<: *test-refs - image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - - variables: - GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests/smoke" +.zombienet-common: before_script: - - echo "Zombienet Smoke Tests" - - echo "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" + - echo "Zombienet Tests Config" + - echo "${ZOMBIENET_IMAGE}" - echo "${GH_DIR}" - - export DEBUG=zombie* + - echo "${LOCAL_DIR}" + - export DEBUG=zombie - export ZOMBIENET_INTEGRATION_TEST_IMAGE="docker.io/paritypr/polkadot-debug:master" - export COL_IMAGE="docker.io/paritypr/colander:master" + - echo "relay_image ${ZOMBIENET_INTEGRATION_TEST_IMAGE}" + - echo "col_image ${COL_IMAGE}" + stage: zombienet + image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" + needs: + - job: publish-docker-pr + extends: + - .kubernetes-env + - .test-refs + variables: + LOCAL_DIR: "/builds/parity/mirrors/zombienet/tests" + FF_DISABLE_UMASK_FOR_DOCKER_EXECUTOR: 1 + artifacts: + name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}" + when: always + expire_in: 2 days + paths: + - ./zombienet-logs + after_script: + - mkdir -p ./zombienet-logs + - cp /tmp/zombie*/logs/* ./zombienet-logs/ + retry: 2 + tags: + - zombienet-polkadot-integration-test +zombienet-smoke: + extends: + - .zombienet-common script: - /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh + --local-dir="${LOCAL_DIR}" --test="0001-smoke.zndsl" - allow_failure: false - retry: 2 - tags: - - zombienet-polkadot-integration-test zombienet-scale-net-config: - stage: deploy - <<: *kubernetes-env - <<: *test-refs - image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - + extends: + - .zombienet-common variables: - GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests/scale-net" - - before_script: - - echo "Zombienet Tests Scale Net" - - echo "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - - echo "${GH_DIR}" - - export DEBUG=zombie* - - export ZOMBIENET_INTEGRATION_TEST_IMAGE="docker.io/paritypr/polkadot-debug:master" - - export COL_IMAGE="docker.io/paritypr/colander:master" - + LOCAL_DIR: "/builds/parity/mirrors/zombienet/tests/scale-net" script: - /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh + --local-dir="${LOCAL_DIR}" --test="0001-scale-net.zndsl" - allow_failure: true - retry: 2 - tags: - - zombienet-polkadot-integration-test zombienet-upgrade-node: - stage: deploy - <<: *kubernetes-env - <<: *test-refs - image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - + extends: + - .zombienet-common variables: GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests/k8s" @@ -245,21 +245,16 @@ zombienet-upgrade-node: - export DEBUG=zombie* - export ZOMBIENET_INTEGRATION_TEST_IMAGE="docker.io/paritypr/polkadot-debug:master" - export COL_IMAGE="docker.io/paritypr/colander:4519" - + - echo "relay_image ${ZOMBIENET_INTEGRATION_TEST_IMAGE}" + - echo "col_image ${COL_IMAGE}" script: - /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh + --local-dir="${LOCAL_DIR}" --test="0001-upgrade-node.zndsl" - allow_failure: true - retry: 2 - tags: - - zombienet-polkadot-integration-test paras: - stage: deploy - <<: *kubernetes-env - <<: *test-refs - image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - + extends: + - .zombienet-common variables: GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests/paras" @@ -275,33 +270,13 @@ paras: script: - /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh + --local-dir="${LOCAL_DIR}" --test="paras.zndsl" - allow_failure: true - retry: 2 - tags: - - zombienet-polkadot-integration-test db-snapshot: - stage: deploy - <<: *kubernetes-env - <<: *test-refs - image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - - variables: - GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests" - - before_script: - - echo "Zombienet Db Snapshot" - - echo "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" - - echo "${GH_DIR}" - - export DEBUG=zombie* - - export ZOMBIENET_INTEGRATION_TEST_IMAGE="docker.io/paritypr/polkadot-debug:master" - - export COL_IMAGE="docker.io/paritypr/colander:master" - + extends: + - .zombienet-common script: - /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh - --test="0013-db-snapshot.zndsl" - allow_failure: true - retry: 2 - tags: - - zombienet-polkadot-integration-test + --local-dir="${LOCAL_DIR}" + --test="0013-db-snapshot.zndsl" \ No newline at end of file diff --git a/javascript/packages/orchestrator/static-configs/namespace-network-policy.yaml b/javascript/packages/orchestrator/static-configs/namespace-network-policy.yaml index a7b096d89..a2e043178 100644 --- a/javascript/packages/orchestrator/static-configs/namespace-network-policy.yaml +++ b/javascript/packages/orchestrator/static-configs/namespace-network-policy.yaml @@ -17,5 +17,6 @@ spec: - tempo - monitoring - parachain-exporter + - default policyTypes: - Ingress \ No newline at end of file diff --git a/scripts/ci/run-test-local-env-manager.sh b/scripts/ci/run-test-local-env-manager.sh index 4840887fd..d3fd513ff 100755 --- a/scripts/ci/run-test-local-env-manager.sh +++ b/scripts/ci/run-test-local-env-manager.sh @@ -17,17 +17,20 @@ gcloud components install kubectl Usage: ${SCRIPT_NAME} OPTION OPTION - -t, --test OPTIONAL Test file to run + -t, --test OPTIONAL Test file to run If omitted "all" test in the tests directory will be used. + -l, --local-dir Directory where the test/config files lives, can be absolute or + relatives to ${SCRIPT_PATH} + -c, --concurrency OPTIONAL concurrency for spawn nodes -h, --help OPTIONAL Print this help message -o, --output-dir OPTIONAL - Path to dir where to save contens of --github-remote-dir + Path to dir where to save contens of --local-dir Defaults to ${SCRIPT_PATH} specified, it will be ifered from there. EXAMPLES Run tests -${SCRIPT_NAME} -g https://github.com/paritytech/polkadot/tree/master/zombienet_tests +${SCRIPT_NAME} -l https://github.com/paritytech/polkadot/tree/master/zombienet_tests EOF } @@ -61,8 +64,9 @@ function set_defaults_for_globals { cd "${SCRIPT_PATH}" EXIT_STATUS=0 - GH_REMOTE_DIR="" + LOCAL_DIR="" TEST_TO_RUN="" + CONCURRENCY=2 LAUNCH_ARGUMENTS="" @@ -78,14 +82,13 @@ function parse_args { } function check_args { - if [[ -n "${GH_REMOTE_DIR}" && - ! "${GH_REMOTE_DIR}" =~ https:\/\/github.com\/ ]] ; then - log DIE "Not a github URL" + if [[ ! -n "${LOCAL_DIR}" ]] ; then + log DIE "Not LOCAL_DIR Set" fi } # shellcheck disable=SC2214 - while getopts i:t:g:h:uo:-: OPT; do + while getopts i:t:l:h:uo:-: OPT; do # support long options: https://stackoverflow.com/a/28466267/519360 if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG OPT="${OPTARG%%=*}" # extract long option name @@ -94,7 +97,8 @@ function parse_args { fi case "$OPT" in t | test) needs_arg ; TEST_TO_RUN="${OPTARG}" ;; - g | github-remote-dir) needs_arg ; GH_REMOTE_DIR="${OPTARG}" ;; + c | concurrency) needs_arg ; CONCURRENCY="${OPTARG}" ;; + l | local-dir) needs_arg ; LOCAL_DIR="${OPTARG}" ;; h | help ) usage ; exit 0 ;; o | output-dir) needs_arg ; OUTPUT_DIR="${OPTARG}" ;; ??* ) log DIE "Illegal option --${OPT}" ;; @@ -108,9 +112,7 @@ function parse_args { function copy_to_isolated { cd "${SCRIPT_PATH}" echo $(pwd) - echo $(ls) - echo $(ls ../..) - cp -r ../../tests/* "${OUTPUT_DIR}" + cp -r "${LOCAL_DIR}"/* "${OUTPUT_DIR}" } function run_test { # RUN_IN_CONTAINER is env var that is set in the dockerfile @@ -121,11 +123,16 @@ function run_test { cd "${OUTPUT_DIR}" set -x set +e + if [[ ! -z $CONCURRENCY ]]; then + C=2 + else + C=$CONCURRENCY + fi; if [[ ! -z $TEST_TO_RUN ]]; then TEST_FOUND=0 for i in $(find ${OUTPUT_DIR} -name "${TEST_TO_RUN}"| head -1); do TEST_FOUND=1 - zombie test $i + zombie -c $CONCURRENCY test $i EXIT_STATUS=$? done; if [[ $TEST_FOUND -lt 1 ]]; then @@ -134,7 +141,7 @@ function run_test { else for i in $(find ${OUTPUT_DIR} -name *.zndsl | sort); do echo "running test: ${i}" - zombie test $i + zombie -c $CONCURRENCY test $i TEST_EXIT_STATUS=$? EXIT_STATUS=$((EXIT_STATUS+TEST_EXIT_STATUS)) done;