Skip to content

Commit

Permalink
Test that after-reset is run when in UKI mode (#2331)
Browse files Browse the repository at this point in the history
* Test that after-reset is run when in UKI mode

Depends on this: kairos-io/kairos-agent#245

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Select recovery boot entry correctly

and add "debug" and "strict" to the uki-install config yaml

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Rename db.* uki keys so that latest enki finds them

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Print debug output (because test fails only in CI)

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Use the correct config for uki tests

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Remove debug output (found the issue)

Signed-off-by: Dimitris Karakasilis <[email protected]>

---------

Signed-off-by: Dimitris Karakasilis <[email protected]>
  • Loading branch information
jimmykarily authored Mar 27, 2024
1 parent 3cc8bbb commit 19919bc
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/uki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
earthly +uki-iso --BASE_IMAGE=ttl.sh/ubuntu-2310-${{ github.head_ref || github.ref }}:24h
- name: Create datasource iso 🔧
run: |
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/autoinstall.yaml
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/uki-install.yaml
- name: Run tests 🔧
env:
USE_QEMU: true
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
--BASE_IMAGE=ttl.sh/fedora-38-${{ github.head_ref || github.ref }}:24h
- name: Create datasource iso 🔧
run: |
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/autoinstall.yaml
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/uki-install.yaml
- name: Run tests 🔧
env:
USE_QEMU: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/uki_branches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
earthly +uki-iso --BASE_IMAGE=ttl.sh/ubuntu-2310-${{ github.sha }}:24h
- name: Create datasource iso 🔧
run: |
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/autoinstall.yaml
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/uki-install.yaml
- name: Run tests 🔧
env:
USE_QEMU: true
Expand Down
36 changes: 36 additions & 0 deletions tests/assets/uki-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#cloud-config

install:
auto: true
reboot: true
device: /dev/vda
grub_options:
extra_cmdline: "rd.immucore.debug foobarzz"

debug: true
strict: true

stages:
initramfs:
- name: "Set user and password"
users:
kairos:
passwd: "kairos"
hostname: kairos-{{ trunc 4 .Random }}
after-reset:
- commands:
- |
/bin/bash <<'EOF'
#!/bin/bash
set -e
echo "Creating a file in COS_PERSISTENT"
umount /oem || true
# Close all encrypted partitions
for p in $(ls /dev/mapper/vda*); do cryptsetup close $p; done
/usr/lib/systemd/systemd-cryptsetup attach persistent $(findfs PARTLABEL=persistent) - tpm2-device=auto
mount /dev/mapper/persistent /usr/local
touch /usr/local/after-reset-file
umount /dev/mapper/persistent
cryptsetup close /dev/mapper/persistent
EOF
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions tests/uki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,22 @@ var _ = Describe("kairos UKI test", Label("uki"), Ordered, func() {
stateContains(vm, "system.os.name", "alpine", "opensuse", "ubuntu", "debian", "fedora")
stateContains(vm, "kairos.flavor", "alpine", "opensuse", "ubuntu", "debian", "fedora")
})

By("rebooting to recovery")
out, err := vm.Sudo("kairos-agent bootentry --select recovery")
Expect(err).ToNot(HaveOccurred(), out)
vm.Reboot()
vm.EventuallyConnects(1200)

By("resetting")
out, err = vm.Sudo("kairos-agent --debug reset --unattended")
Expect(err).ToNot(HaveOccurred(), out)
vm.Reboot()
vm.EventuallyConnects(1200)

By("checking if after-reset was run")
out, err = vm.Sudo("ls /usr/local/after-reset-file")
Expect(err).ToNot(HaveOccurred(), out)
Expect(out).ToNot(MatchRegexp("No such file or directory"))
})
})

0 comments on commit 19919bc

Please sign in to comment.