From d75b0f38000413db00acf270399ee675349e2fcf Mon Sep 17 00:00:00 2001 From: samugi Date: Mon, 5 Feb 2024 15:37:42 +0100 Subject: [PATCH] feat(ci): run upgrade tests for multiple "old" versions Currently only 2.8.0 is used to run migration tests, all the way up to the "new" (current) version. This means that only features that are shared across all versions from "old" to "new" can be tested, e.g. a plugin that is not available in `2.8.0` cannot be configured and used in migration tests. This commit introduces a list of "old_versions" and repeats the tests for each. Tests can use the `OLD_KONG_VERSION` environment variable to determine whether they should execute for the current version. --- scripts/upgrade-tests/source-versions | 6 +++ scripts/upgrade-tests/test-upgrade-path.sh | 51 +++++++++++-------- .../migrations/001_280_to_300_spec.lua | 5 +- .../migrations/001_280_to_300_spec.lua | 7 ++- .../migrations/001_280_to_300_spec.lua | 5 +- 5 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 scripts/upgrade-tests/source-versions diff --git a/scripts/upgrade-tests/source-versions b/scripts/upgrade-tests/source-versions new file mode 100644 index 00000000000..19c8d54b369 --- /dev/null +++ b/scripts/upgrade-tests/source-versions @@ -0,0 +1,6 @@ +2.8.0 +3.1.0 +3.2.2 +3.3.0 +3.4.0 +3.5.0 diff --git a/scripts/upgrade-tests/test-upgrade-path.sh b/scripts/upgrade-tests/test-upgrade-path.sh index 9f8638d110c..8144fd9513f 100755 --- a/scripts/upgrade-tests/test-upgrade-path.sh +++ b/scripts/upgrade-tests/test-upgrade-path.sh @@ -23,19 +23,6 @@ set -e trap "echo exiting because of error" 0 -function get_current_version() { - local image_tag=$1 - local version_from_rockspec=$(perl -ne 'print "$1\n" if (/^\s*tag = "(.*)"/)' kong*.rockspec) - if docker pull $image_tag:$version_from_rockspec >/dev/null 2>/dev/null - then - echo $version_from_rockspec-ubuntu - else - echo master-ubuntu - fi -} - -export OLD_KONG_VERSION=2.8.0 -export OLD_KONG_IMAGE=kong:$OLD_KONG_VERSION-ubuntu export KONG_PG_HOST=localhost export KONG_TEST_PG_HOST=localhost @@ -91,13 +78,19 @@ function prepare_container() { } function build_containers() { + # Kong version >= 3.3 moved non Bazel-built dev setup to make dev-legacy + if (( $(echo "$OLD_KONG_VERSION" | sed 's/\.//g') >= 330 )); then + old_make_target="dev-legacy" + else + old_make_target="dev" + fi + echo "Building containers" [ -d worktree/$OLD_KONG_VERSION ] || git worktree add worktree/$OLD_KONG_VERSION $OLD_KONG_VERSION $COMPOSE up --wait prepare_container $OLD_CONTAINER - docker exec -w /kong $OLD_CONTAINER make dev CRYPTO_DIR=/usr/local/kong - # Kong version >= 3.3 moved non Bazel-built dev setup to make dev-legacy + docker exec -w /kong $OLD_CONTAINER make $old_make_target CRYPTO_DIR=/usr/local/kong make dev-legacy CRYPTO_DIR=/usr/local/kong } @@ -155,7 +148,7 @@ function initialize_test_list() { function run_tests() { # Run the tests - BUSTED_ENV="env KONG_DATABASE=$1 KONG_DNS_RESOLVER= KONG_TEST_PG_DATABASE=kong" + BUSTED_ENV="env KONG_DATABASE=$1 KONG_DNS_RESOLVER= KONG_TEST_PG_DATABASE=kong OLD_KONG_VERSION=$OLD_KONG_VERSION" shift @@ -186,15 +179,29 @@ function run_tests() { } function cleanup() { - git worktree remove worktree/$OLD_KONG_VERSION --force + sudo git worktree remove worktree/$OLD_KONG_VERSION --force $COMPOSE down - deactivate } + source $venv_script -build_containers -initialize_test_list -run_tests postgres -[ -z "$UPGRADE_ENV_PREFIX" ] && cleanup + +# Load supported "old" versions to run migration tests against +old_versions=() +mapfile -t old_versions < "scripts/upgrade-tests/source-versions" + +for old_version in "${old_versions[@]}"; do + export OLD_KONG_VERSION=$old_version + export OLD_KONG_IMAGE=kong:$OLD_KONG_VERSION-ubuntu + + echo "Running tests using $OLD_KONG_VERSION as \"old version\" of Kong" + + build_containers + initialize_test_list + run_tests postgres + [ -z "$UPGRADE_ENV_PREFIX" ] && cleanup +done + +deactivate trap "" 0 diff --git a/spec/05-migration/plugins/http-log/migrations/001_280_to_300_spec.lua b/spec/05-migration/plugins/http-log/migrations/001_280_to_300_spec.lua index 320b15096fc..1264a2c8f10 100644 --- a/spec/05-migration/plugins/http-log/migrations/001_280_to_300_spec.lua +++ b/spec/05-migration/plugins/http-log/migrations/001_280_to_300_spec.lua @@ -8,7 +8,10 @@ local uh = require "spec.upgrade_helpers" -- to test the migration process. do not change it to use dynamic port. local HTTP_PORT = 29100 -describe("http-log plugin migration", function() +local OLD_KONG_VERSION = os.getenv("OLD_KONG_VERSION") +local handler = OLD_KONG_VERSION:sub(1,3) == "2.8" and describe or pending + +handler("http-log plugin migration", function() local mock lazy_setup(function() assert(uh.start_kong()) diff --git a/spec/05-migration/plugins/post-function/migrations/001_280_to_300_spec.lua b/spec/05-migration/plugins/post-function/migrations/001_280_to_300_spec.lua index dab5fa5583a..ed3fdfb8f92 100644 --- a/spec/05-migration/plugins/post-function/migrations/001_280_to_300_spec.lua +++ b/spec/05-migration/plugins/post-function/migrations/001_280_to_300_spec.lua @@ -1,7 +1,12 @@ local uh = require "spec/upgrade_helpers" -describe("post-function plugin migration", function() + +local OLD_KONG_VERSION = os.getenv("OLD_KONG_VERSION") +local handler = OLD_KONG_VERSION:sub(1,3) == "2.8" and describe or pending + + +handler("post-function plugin migration", function() lazy_setup(function() assert(uh.start_kong()) diff --git a/spec/05-migration/plugins/pre-function/migrations/001_280_to_300_spec.lua b/spec/05-migration/plugins/pre-function/migrations/001_280_to_300_spec.lua index 5b77e3339e9..d4a43838082 100644 --- a/spec/05-migration/plugins/pre-function/migrations/001_280_to_300_spec.lua +++ b/spec/05-migration/plugins/pre-function/migrations/001_280_to_300_spec.lua @@ -1,7 +1,10 @@ local uh = require "spec/upgrade_helpers" -describe("pre-function plugin migration", function() +local OLD_KONG_VERSION = os.getenv("OLD_KONG_VERSION") +local handler = OLD_KONG_VERSION:sub(1,3) == "2.8" and describe or pending + +handler("pre-function plugin migration", function() lazy_setup(function() assert(uh.start_kong())