From ceb4b2fa7def5ecfb9cc5c7e16c663ba6641cb74 Mon Sep 17 00:00:00 2001
From: Max Gautier <mg@max.gautier.name>
Date: Fri, 18 Oct 2024 12:11:41 +0200
Subject: [PATCH] CI: use current tests/ directory for upgrade testing

We should not rollback our test setup during upgrade test.
The only reason to do that would be for incompatible changes in the test
inventory, and we already checkout master for those (${CI_JOB_NAME}.yml)

Also do some cleanup by removing unnecessary intermediary variables
---
 .gitlab-ci.yml                                       |  4 ----
 tests/Makefile                                       |  2 +-
 tests/cloud_playbooks/create-packet.yml              |  3 ---
 tests/common/_kubespray_test_settings.yml            |  5 -----
 ...ocker_hub_registry_mirror.yml => common_vars.yml} | 10 ++++++----
 tests/scripts/testcases_run.sh                       | 12 +++++-------
 6 files changed, 12 insertions(+), 24 deletions(-)
 delete mode 100644 tests/common/_kubespray_test_settings.yml
 rename tests/{common/_docker_hub_registry_mirror.yml => common_vars.yml} (95%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c1cd83bb5..2eaa8f046 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,10 +11,6 @@ variables:
   GITLAB_REPOSITORY: 'kargo-ci/kubernetes-sigs-kubespray'
   ANSIBLE_FORCE_COLOR: "true"
   MAGIC: "ci check this"
-  TEST_ID: "$CI_PIPELINE_ID-$CI_JOB_ID"
-  CI_TEST_VARS: "./tests/files/${CI_JOB_NAME}.yml"
-  CI_TEST_REGISTRY_MIRROR: "./tests/common/_docker_hub_registry_mirror.yml"
-  CI_TEST_SETTING: "./tests/common/_kubespray_test_settings.yml"
   GS_ACCESS_KEY_ID: $GS_KEY
   GS_SECRET_ACCESS_KEY: $GS_SECRET
   CONTAINER_ENGINE: docker
diff --git a/tests/Makefile b/tests/Makefile
index 50256b197..33e0e9dcb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -13,7 +13,7 @@ create-packet: init-packet
 	ansible-playbook cloud_playbooks/create-packet.yml -c local \
 	$(ANSIBLE_LOG_LEVEL) \
 	-e @"files/${CI_JOB_NAME}.yml" \
-	-e test_id=$(TEST_ID) \
+	-e test_name="$(subst .,-,$(CI_PIPELINE_ID)-$(CI_JOB_ID))" \
 	-e branch="$(CI_COMMIT_BRANCH)" \
 	-e pipeline_id="$(CI_PIPELINE_ID)" \
 	-e inventory_path=$(INVENTORY_DIR)
diff --git a/tests/cloud_playbooks/create-packet.yml b/tests/cloud_playbooks/create-packet.yml
index 2cd08b54d..26c39217f 100644
--- a/tests/cloud_playbooks/create-packet.yml
+++ b/tests/cloud_playbooks/create-packet.yml
@@ -4,8 +4,5 @@
   hosts: localhost
   gather_facts: false
   become: true
-  vars:
-    ci_job_name: "{{ lookup('env', 'CI_JOB_NAME') }}"
-    test_name: "{{ test_id | regex_replace('\\.', '-') }}"
   roles:
     - { role: packet-ci, vm_cleanup: false }
diff --git a/tests/common/_kubespray_test_settings.yml b/tests/common/_kubespray_test_settings.yml
deleted file mode 100644
index 67da05c50..000000000
--- a/tests/common/_kubespray_test_settings.yml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-# Kubespray settings for tests
-deploy_netchecker: true
-dns_min_replicas: 1
-unsafe_show_logs: true
diff --git a/tests/common/_docker_hub_registry_mirror.yml b/tests/common_vars.yml
similarity index 95%
rename from tests/common/_docker_hub_registry_mirror.yml
rename to tests/common_vars.yml
index 8875d2173..a8645ba26 100644
--- a/tests/common/_docker_hub_registry_mirror.yml
+++ b/tests/common_vars.yml
@@ -1,4 +1,10 @@
 ---
+# Kubespray settings for tests
+deploy_netchecker: true
+dns_min_replicas: 1
+unsafe_show_logs: true
+
+# Registry mirrors settings
 docker_registry_mirrors:
   - "https://mirror.gcr.io"
 
@@ -34,7 +40,3 @@ nginx_image_repo: "{{ quay_image_repo }}/kubespray/nginx"
 
 flannel_image_repo: "{{ quay_image_repo }}/kubespray/flannel"
 flannel_init_image_repo: "{{ quay_image_repo }}/kubespray/flannel-cni-plugin"
-
-# Kubespray settings for tests
-deploy_netchecker: true
-dns_min_replicas: 1
diff --git a/tests/scripts/testcases_run.sh b/tests/scripts/testcases_run.sh
index 6235d2ed3..81632eeee 100755
--- a/tests/scripts/testcases_run.sh
+++ b/tests/scripts/testcases_run.sh
@@ -18,10 +18,9 @@ fi
 # Check out latest tag if testing upgrade
 if [ "${UPGRADE_TEST}" != "false" ]; then
   git fetch --all && git checkout "$KUBESPRAY_VERSION"
-  # Checkout the CI vars file so it is available
-  git checkout "${CI_COMMIT_SHA}" tests/files/${CI_JOB_NAME}.yml
-  git checkout "${CI_COMMIT_SHA}" ${CI_TEST_REGISTRY_MIRROR}
-  git checkout "${CI_COMMIT_SHA}" ${CI_TEST_SETTING}
+  # Checkout the current tests/ directory ; even when testing old version,
+  # we want the up-to-date test setup/provisionning
+  git checkout "${CI_COMMIT_SHA}" -- tests/
 fi
 
 # needed for ara not to complain
@@ -57,9 +56,8 @@ shift
 # We can set --limit here and still pass it as supplemental args because `--limit`  is a 'last one wins' option
 ansible-playbook \
      $ANSIBLE_LOG_LEVEL \
-    -e @${CI_TEST_SETTING} \
-    -e @${CI_TEST_REGISTRY_MIRROR} \
-    -e @${CI_TEST_VARS} \
+    -e @tests/common_vars.yml \
+    -e @tests/files/${CI_JOB_NAME}.yml \
     -e local_release_dir=${PWD}/downloads \
     "$@" \
     ${playbook}
-- 
GitLab