-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for custom partioning (#2291)
* Add test for custom partioning not currently passing because the fix is not there (TDD) Signed-off-by: Dimitris Karakasilis <[email protected]> * Add sanity check and fix config Signed-off-by: Dimitris Karakasilis <[email protected]> * Remove "replace" for peg in go.mod (now merged) Signed-off-by: Dimitris Karakasilis <[email protected]> * [TMP] Run tests using a branch Signed-off-by: Dimitris Karakasilis <[email protected]> * Add custom partitioning test in the pipelines Signed-off-by: Dimitris Karakasilis <[email protected]> * Use core artifact Signed-off-by: Dimitris Karakasilis <[email protected]> * Change flavor to one that we actually build Signed-off-by: Dimitris Karakasilis <[email protected]> * Fix test Signed-off-by: Dimitris Karakasilis <[email protected]> * Bump kairos-agent through framework and remove tmp hack Signed-off-by: Dimitris Karakasilis <[email protected]> * Apply suggestions from code review Signed-off-by: Dimitris Karakasilis <[email protected]> * Use setup for legacy bios Locally I had a forgotten "FIRMWARE" env variable set (from previous runs) and that make my tests pass with efi partitions. In CI it boot in legacy bios mode. Signed-off-by: Dimitris Karakasilis <[email protected]> --------- Signed-off-by: Dimitris Karakasilis <[email protected]>
- Loading branch information
1 parent
c319d9f
commit 9688c74
Showing
7 changed files
with
396 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Reusable workflow that runs the custom partitioning tests | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
flavor: | ||
required: true | ||
type: string | ||
flavor_release: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
test: | ||
runs-on: fast | ||
permissions: | ||
id-token: write # OIDC support | ||
contents: write | ||
actions: read | ||
security-events: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: tests/go.mod | ||
cache-dependency-path: tests/go.sum | ||
- name: Block all traffic to metadata ip # For cloud runners, the metadata ip can interact with our test machines | ||
run: | | ||
sudo iptables -I INPUT -s 169.254.169.254 -j DROP | ||
sudo iptables -I OUTPUT -d 169.254.169.254 -j DROP | ||
- name: Enable KVM group perms | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils qemu qemu-system-x86 qemu-system-x86 qemu-utils qemu-kvm acl udev | ||
sudo setfacl -m u:runner:rwx /dev/kvm | ||
- name: Install earthly | ||
uses: Luet-lab/[email protected] | ||
with: | ||
repository: quay.io/kairos/packages | ||
packages: utils/earthly | ||
- name: Download artifacts | ||
uses: actions/[email protected] | ||
with: | ||
name: kairos-${{ inputs.flavor }}-${{ inputs.flavor_release}}.iso.zip | ||
- name: Run tests | ||
env: | ||
USE_QEMU: true | ||
KVM: true | ||
MEMORY: 4000 | ||
CPUS: 2 | ||
CONTAINER_IMAGE: ttl.sh/kairos-${{ inputs.flavor }}-${{ inputs.flavor_release }}-${{ github.sha }}:24h | ||
run: | | ||
ls *.iso | ||
export ISO=$PWD/$(ls *.iso) | ||
echo "ISO is: $ISO" | ||
cp tests/go.* . | ||
go run github.com/onsi/ginkgo/v2/ginkgo -v --label-filter "custom-partitioning" --fail-fast -r ./tests/ | ||
- uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: ${{ inputs.flavor }}-${{ inputs.flavor_release }}-${{ inputs.label }}-test.logs.zip | ||
path: tests/**/logs/* | ||
if-no-files-found: warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// nolint | ||
package mos_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "github.com/spectrocloud/peg/matcher" | ||
"github.com/spectrocloud/peg/pkg/machine" | ||
"github.com/spectrocloud/peg/pkg/machine/types" | ||
) | ||
|
||
var _ = Describe("kairos custom partitioning install", Label("custom-partitioning"), func() { | ||
var vm VM | ||
|
||
BeforeEach(func() { | ||
stateDir, err := os.MkdirTemp("", "") | ||
Expect(err).ToNot(HaveOccurred()) | ||
fmt.Printf("State dir: %s\n", stateDir) | ||
|
||
opts := defaultVMOptsNoDrives(stateDir) | ||
opts = append(opts, types.WithDriveSize("40000")) | ||
opts = append(opts, types.WithDriveSize("30000")) | ||
|
||
m, err := machine.New(opts...) | ||
Expect(err).ToNot(HaveOccurred()) | ||
vm = NewVM(m, stateDir) | ||
_, err = vm.Start(context.Background()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
DeferCleanup(func() { | ||
vm.Destroy(nil) | ||
}) | ||
|
||
By("waiting for VM to be up for the first time") | ||
vm.EventuallyConnects(1200) | ||
|
||
By("creating a configuration for custom partitioning") | ||
configFile, err := os.CreateTemp("", "") | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer os.Remove(configFile.Name()) | ||
|
||
err = os.WriteFile(configFile.Name(), []byte(customPartitionConfig()), 0744) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("copying the configuration to the vm") | ||
err = vm.Scp(configFile.Name(), "/tmp/config.yaml", "0744") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("manually installing") | ||
installationOutput, installError = vm.Sudo("kairos-agent --strict-validation --debug manual-install /tmp/config.yaml") | ||
}) | ||
|
||
AfterEach(func() { | ||
if CurrentSpecReport().Failed() { | ||
gatherLogs(vm) | ||
serial, _ := os.ReadFile(filepath.Join(vm.StateDir, "serial.log")) | ||
_ = os.MkdirAll("logs", os.ModePerm|os.ModeDir) | ||
_ = os.WriteFile(filepath.Join("logs", "serial.log"), serial, os.ModePerm) | ||
fmt.Println(string(serial)) | ||
} | ||
}) | ||
|
||
It("installs on the pre-configured disks", func() { | ||
Expect(installError).ToNot(HaveOccurred(), installationOutput) | ||
By("Rebooting into live CD again") | ||
// In qemu it's tricky to boot the second disk. In multiple disk scenarios, | ||
// setting "-boot=cd" will make qemu try to boot from the first disk and | ||
// then from the cdrom. | ||
// We want to make sure that kairos-agent selected the second disk so we | ||
// simply let it boot from the cdrom again. Hopefully if the installation | ||
// failed, we would see the error from the manual-install command. | ||
vm.Reboot() | ||
vm.EventuallyConnects(1200) | ||
|
||
By("Checking the partition") | ||
out, err := vm.Sudo("blkid") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
Expect(out).To(MatchRegexp("/dev/vdb2.*LABEL=\"COS_OEM\""), out) | ||
Expect(out).To(MatchRegexp("/dev/vdb3.*LABEL=\"COS_RECOVERY\""), out) | ||
Expect(out).To(MatchRegexp("/dev/vdb4.*LABEL=\"COS_STATE\""), out) | ||
Expect(out).To(MatchRegexp("/dev/vdb5.*LABEL=\"COS_PERSISTENT\""), out) | ||
|
||
// Sanity check that the default disk is not touched | ||
Expect(out).ToNot(MatchRegexp("/dev/vda.*LABEL=\"COS_PERSISTENT\""), out) | ||
}) | ||
}) | ||
|
||
func customPartitionConfig() string { | ||
return `#cloud-config | ||
strict: true | ||
debug: true | ||
install: | ||
no-format: true | ||
auto: false | ||
poweroff: false | ||
reboot: false | ||
grub_options: | ||
extra_cmdline: "rd.immucore.debug" | ||
users: | ||
- name: "kairos" | ||
passwd: "kairos" | ||
stages: | ||
kairos-install.pre.before: | ||
- if: '[ -e "/dev/vdb" ]' | ||
name: "Create partitions" | ||
commands: | ||
- | | ||
parted --script --machine -- "/dev/vdb" mklabel gpt | ||
# Legacy bios | ||
sgdisk --new=1:2048:+1M --change-name=1:'bios' --typecode=1:EF02 /dev/vdb | ||
layout: | ||
device: | ||
path: "/dev/vdb" | ||
add_partitions: | ||
# For efi (comment out the legacy bios partition above) | ||
#- fsLabel: COS_GRUB | ||
# size: 64 | ||
# pLabel: efi | ||
# filesystem: "fat" | ||
- fsLabel: COS_OEM | ||
size: 64 | ||
pLabel: oem | ||
- fsLabel: COS_RECOVERY | ||
size: 8500 | ||
pLabel: recovery | ||
- fsLabel: COS_STATE | ||
size: 18000 | ||
pLabel: state | ||
- fsLabel: COS_PERSISTENT | ||
pLabel: persistent | ||
size: 0 | ||
filesystem: "ext4" | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.