Skip to content

Commit 5f996b5

Browse files
authored
Expand downgrade test by upgrading back to origin after downgrading (#2224)
* Expand downgrade test by upgrading back to origin after downgrading Signed-off-by: David Cassany <[email protected]> * Adapt github worflow to handle cache for downgrade tests and import the container images Signed-off-by: David Cassany <[email protected]> --------- Signed-off-by: David Cassany <[email protected]>
1 parent 1960635 commit 5f996b5

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-19
lines changed

.github/workflows/build_and_test_x86.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ jobs:
201201
go-version-file: go.mod
202202
- run: |
203203
git fetch --prune --unshallow
204-
- if: ${{ matrix.test == 'test-upgrade' }}
204+
- if: ${{ matrix.test == 'test-upgrade' || matrix.test == 'test-downgrade' }}
205205
name: Pull images
206206
uses: ./.github/actions/fetchimages
207207
with:

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ RUN ARCH=$(uname -m); \
5757
gptfdisk \
5858
patterns-microos-selinux \
5959
btrfsprogs \
60+
snapper \
6061
lvm2 && \
6162
zypper cc -a
6263

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ISO?=$(shell ls $(ROOT_DIR)/build/elemental*.iso 2> /dev/null)
77
FLAVOR?=green
88
ARCH?=$(shell uname -m)
99
UPGRADE_DISK_URL?=https://github.com/rancher/elemental-toolkit/releases/download/v1.1.4/elemental-$(FLAVOR)-v1.1.4.$(ARCH).qcow2
10-
UPGRADE_DISK?=upgrade-test-elemental-disk.qcow2
10+
UPGRADE_DISK?=upgrade-test-elemental-disk-$(FLAVOR).qcow2
1111
UPGRADE_DISK_CHECK?=$(shell ls $(ROOT_DIR)/build/$(UPGRADE_DISK) 2> /dev/null)
1212
PLATFORM?=linux/$(ARCH)
1313
IMAGE_SIZE?=20G

make/Makefile.test

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ endif
1010
@scripts/run_vm.sh start $(DISK)
1111
@echo "VM started from $(DISK)"
1212

13+
.PHONY: prepare-local-registry
14+
prepare-local-registry:
15+
@scripts/run_registry.sh start
16+
@scripts/run_registry.sh push "$(TOOLKIT_REPO):$(VERSION)" "$(REPO):$(VERSION)"
17+
1318
.PHONY: prepare-upgrade-test
1419
prepare-upgrade-test:
1520
ifeq ("$(UPGRADE_DISK_CHECK)","")
1621
mkdir -p $(ROOT_DIR)/build
1722
@echo "Downloading disk from $(UPGRADE_DISK_URL) ..."
1823
@wget -q --tries=3 $(UPGRADE_DISK_URL) -O $(ROOT_DIR)/build/$(UPGRADE_DISK)
1924
endif
20-
@scripts/run_registry.sh start
2125
@scripts/run_vm.sh start $(ROOT_DIR)/build/$(UPGRADE_DISK)
22-
@scripts/run_registry.sh push "$(TOOLKIT_REPO):$(VERSION)" "$(REPO):$(VERSION)"
2326
@echo "VM started from $(ROOT_DIR)/build/$(UPGRADE_DISK)"
2427

2528
.PHONY: test-active
@@ -70,12 +73,12 @@ test-fsck: test-active
7073
VM_PID=$$(scripts/run_vm.sh vmpid) go run $(GINKGO) $(GINKGO_ARGS) ./tests/fsck
7174

7275
.PHONY: test-downgrade
73-
test-downgrade: test-active
74-
VM_PID=$$(scripts/run_vm.sh vmpid) go run $(GINKGO) $(GINKGO_ARGS) ./tests/downgrade -- $(UPGRADE_ARGS)
76+
test-downgrade: prepare-test prepare-local-registry
77+
@scripts/run_upgradetest.sh start $(GINKGO) "$(GINKGO_ARGS)" "./tests/downgrade" "$(TOOLKIT_REPO):$(VERSION)" "$(REPO):$(VERSION)"
7578

7679
.PHONY: test-upgrade
77-
test-upgrade: prepare-upgrade-test
78-
@scripts/run_upgradetest.sh start $(GINKGO) "$(GINKGO_ARGS)" "$(TOOLKIT_REPO):$(VERSION)" "$(REPO):$(VERSION)"
80+
test-upgrade: prepare-upgrade-test prepare-local-registry
81+
@scripts/run_upgradetest.sh start $(GINKGO) "$(GINKGO_ARGS)" "./tests/upgrade" "$(TOOLKIT_REPO):$(VERSION)" "$(REPO):$(VERSION)"
7982

8083
.PHONY: test-cli
8184
test-cli:

scripts/run_upgradetest.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function _abort {
1515
function start {
1616
local ginkgo="$1"
1717
local ginkgo_args="$2"
18-
local toolkit_img="$3"
19-
local upgrade_img="$4"
18+
local suite_folder="$3"
19+
local toolkit_img="$4"
20+
local upgrade_img="$5"
2021
local reg_url
2122

2223
export VM_PID=$(${SCRIPTS_PATH}/run_vm.sh vmpid)
@@ -26,7 +27,7 @@ function start {
2627

2728
pushd "${ROOT_PATH}" > /dev/null
2829
go run ${ginkgo} ${ginkgo_args} ./tests/wait-active
29-
go run ${ginkgo} ${ginkgo_args} ./tests/upgrade -- \
30+
go run ${ginkgo} ${ginkgo_args} ${suite_folder} -- \
3031
--toolkit-image=docker://${reg_url}/${toolkit_img} --upgrade-image=docker://${reg_url}/${upgrade_img}
3132
popd > /dev/null
3233
}
@@ -36,10 +37,10 @@ cmd=$1
3637
case $cmd in
3738
start)
3839
shift
39-
if [[ $# -ne 4 ]]; then
40+
if [[ $# -ne 5 ]]; then
4041
_abort "Wrong number of arguments"
4142
fi
42-
start "$1" "$2" "$3" "$4"
43+
start "$1" "$2" "$3" "$4" "$5"
4344
;;
4445
*)
4546
_abort "Unknown command: ${cmd}"

tests/assets/hacks_for_tests.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Hacks for testing environment"
2+
stages:
3+
initramfs:
4+
# This is needed in case some unit service have been
5+
# refactored across distro releases.
6+
# Fixes downgrade test (Nov 2024)
7+
- name: "Remove broken unit links"
8+
commands:
9+
- |
10+
find /etc/systemd/system/ -type l -print0 | while IFS= read -r -d $'\0' file; do
11+
[ -e ${file} ] && continue
12+
echo "Removing broken link ${file}"
13+
rm -f "${file}"
14+
done

tests/downgrade/downgrade_test.go

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ var _ = Describe("Elemental Feature tests", func() {
4242
})
4343

4444
Context("After install", func() {
45-
It("downgrades to an older image including upgrade and reset hooks", func() {
45+
It("downgrades to an older image to then upgrade again to current including upgrade and reset hooks", func() {
4646
By("setting /oem/chroot_hooks.yaml")
47-
err := s.SendFile("../assets/chroot_hooks.yaml", "/oem/chroot_hooks.yaml", "0770")
48-
Expect(err).ToNot(HaveOccurred())
47+
Expect(s.SendFile("../assets/chroot_hooks.yaml", "/oem/chroot_hooks.yaml", "0770")).To(Succeed())
48+
Expect(s.SendFile("../assets/hacks_for_tests.yaml", "/oem/hacks_for_tests.yaml", "0770")).To(Succeed())
49+
4950
originalVersion := s.GetOSRelease("TIMESTAMP")
5051

5152
By(fmt.Sprintf("upgrading to %s", comm.DefaultUpgradeImage))
@@ -56,8 +57,8 @@ var _ = Describe("Elemental Feature tests", func() {
5657

5758
s.Reboot()
5859
s.EventuallyBootedFrom(sut.Active)
59-
currentVersion := s.GetOSRelease("TIMESTAMP")
60-
Expect(currentVersion).NotTo(Equal(originalVersion))
60+
downgradedVersion := s.GetOSRelease("TIMESTAMP")
61+
Expect(downgradedVersion).NotTo(Equal(originalVersion))
6162

6263
_, err = s.Command("cat /after-upgrade-chroot")
6364
Expect(err).ToNot(HaveOccurred())
@@ -70,8 +71,10 @@ var _ = Describe("Elemental Feature tests", func() {
7071
s.Reboot()
7172
s.EventuallyBootedFrom(sut.Passive)
7273
passiveVersion := s.GetOSRelease("TIMESTAMP")
73-
Expect(currentVersion).NotTo(Equal(passiveVersion))
74+
Expect(downgradedVersion).NotTo(Equal(passiveVersion))
75+
Expect(originalVersion).To(Equal(passiveVersion))
7476

77+
// Tests we can upgrade active from passive
7578
By(fmt.Sprintf("Upgrading again from passive to %s", comm.UpgradeImage()))
7679
out, err = s.Command(s.ElementalCmd("upgrade", "--system", comm.UpgradeImage()))
7780
Expect(err).ToNot(HaveOccurred())
@@ -80,6 +83,34 @@ var _ = Describe("Elemental Feature tests", func() {
8083
By("Rebooting to active")
8184
s.Reboot()
8285
s.EventuallyBootedFrom(sut.Active)
86+
activeVersion := s.GetOSRelease("TIMESTAMP")
87+
Expect(downgradedVersion).NotTo(Equal(activeVersion))
88+
Expect(originalVersion).To(Equal(activeVersion))
89+
90+
By("Rebooting to passive")
91+
s.ChangeBootOnce(sut.Passive)
92+
s.Reboot()
93+
s.EventuallyBootedFrom(sut.Passive)
94+
passiveVersion = s.GetOSRelease("TIMESTAMP")
95+
Expect(downgradedVersion).To(Equal(passiveVersion))
96+
Expect(originalVersion).NotTo(Equal(passiveVersion))
97+
98+
// Test we can upgrade from the downgraded version back to original
99+
By(fmt.Sprintf("Upgrading again from passive to %s", comm.UpgradeImage()))
100+
upgradeCmd := s.ElementalCmd("upgrade", "--tls-verify=false", "--bootloader", "--system", comm.UpgradeImage())
101+
out, err = s.NewPodmanRunCommand(comm.ToolkitImage(), fmt.Sprintf("-c \"mount --rbind /host/run /run && %s\"", upgradeCmd)).
102+
Privileged().
103+
NoTLSVerify().
104+
WithMount("/", "/host").
105+
Run()
106+
Expect(err).ToNot(HaveOccurred())
107+
Expect(out).Should(ContainSubstring("Upgrade completed"))
108+
By("Rebooting to active")
109+
s.Reboot()
110+
s.EventuallyBootedFrom(sut.Active)
111+
activeVersion = s.GetOSRelease("TIMESTAMP")
112+
Expect(downgradedVersion).NotTo(Equal(activeVersion))
113+
Expect(originalVersion).To(Equal(activeVersion))
83114
})
84115
})
85116
})

0 commit comments

Comments
 (0)