| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | // This package runs the installer image in a VM provided with an empty block |
| 18 | // device. It then examines the installer console output and the blok device to |
| 19 | // determine whether the installation process completed without issue. |
| Mateusz Zalega | edffbb5 | 2022-01-11 15:27:22 +0100 | [diff] [blame] | 20 | package installer |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 21 | |
| 22 | import ( |
| Mateusz Zalega | 367f759 | 2021-12-20 18:13:31 +0100 | [diff] [blame] | 23 | "bytes" |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 24 | "context" |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 25 | "fmt" |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 26 | "log" |
| 27 | "os" |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 28 | "path/filepath" |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 29 | "syscall" |
| 30 | "testing" |
| Serge Bazanski | 05cf33d | 2023-03-16 20:50:59 +0100 | [diff] [blame] | 31 | "time" |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 32 | |
| Tim Windelschmidt | 2a1d1b2 | 2024-02-06 07:07:42 +0100 | [diff] [blame] | 33 | "github.com/bazelbuild/rules_go/go/runfiles" |
| 34 | "github.com/diskfs/go-diskfs" |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 35 | "github.com/diskfs/go-diskfs/disk" |
| 36 | "github.com/diskfs/go-diskfs/partition/gpt" |
| Lorenz Brun | 0b93c8d | 2021-11-09 03:58:40 +0100 | [diff] [blame] | 37 | |
| Tim Windelschmidt | 2a1d1b2 | 2024-02-06 07:07:42 +0100 | [diff] [blame] | 38 | "source.monogon.dev/metropolis/proto/api" |
| 39 | |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 40 | mctl "source.monogon.dev/metropolis/cli/metroctl/core" |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 41 | "source.monogon.dev/metropolis/node/build/mkimage/osimage" |
| Tim Windelschmidt | 9f21f53 | 2024-05-07 15:14:20 +0200 | [diff] [blame^] | 42 | "source.monogon.dev/osbase/cmd" |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 43 | ) |
| 44 | |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 45 | // Each variable in this block points to either a test dependency or a side |
| 46 | // effect. These variables are initialized in TestMain using Bazel. |
| 47 | var ( |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 48 | // installerImage is a filesystem path pointing at the installer image that |
| 49 | // is generated during the test, and is removed afterwards. |
| 50 | installerImage string |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 51 | ) |
| 52 | |
| Mateusz Zalega | f1234a9 | 2022-06-22 13:57:38 +0200 | [diff] [blame] | 53 | // runQemu starts a new QEMU process, expecting the given output to appear |
| 54 | // in any line printed. It returns true, if the expected string was found, |
| 55 | // and false otherwise. |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 56 | // |
| Mateusz Zalega | f1234a9 | 2022-06-22 13:57:38 +0200 | [diff] [blame] | 57 | // QEMU is killed shortly after the string is found, or when the context is |
| 58 | // cancelled. |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 59 | func runQemu(ctx context.Context, args []string, expectedOutput string) (bool, error) { |
| Tim Windelschmidt | 244b567 | 2024-02-06 10:18:56 +0100 | [diff] [blame] | 60 | ovmfVarsPath, err := runfiles.Rlocation("edk2/OVMF_VARS.fd") |
| 61 | if err != nil { |
| 62 | return false, err |
| 63 | } |
| 64 | ovmfCodePath, err := runfiles.Rlocation("edk2/OVMF_CODE.fd") |
| 65 | if err != nil { |
| 66 | return false, err |
| 67 | } |
| 68 | qemuPath, err := runfiles.Rlocation("qemu/qemu-x86_64-softmmu") |
| 69 | if err != nil { |
| 70 | return false, err |
| 71 | } |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 72 | defaultArgs := []string{ |
| 73 | "-machine", "q35", "-accel", "kvm", "-nographic", "-nodefaults", |
| 74 | "-m", "512", |
| 75 | "-smp", "2", |
| 76 | "-cpu", "host", |
| Tim Windelschmidt | 244b567 | 2024-02-06 10:18:56 +0100 | [diff] [blame] | 77 | "-drive", "if=pflash,format=raw,snapshot=on,file=" + ovmfCodePath, |
| 78 | "-drive", "if=pflash,format=raw,readonly=on,file=" + ovmfVarsPath, |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 79 | "-serial", "stdio", |
| 80 | "-no-reboot", |
| 81 | } |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 82 | qemuArgs := append(defaultArgs, args...) |
| Mateusz Zalega | b838e05 | 2022-08-12 18:08:10 +0200 | [diff] [blame] | 83 | pf := cmd.TerminateIfFound(expectedOutput, nil) |
| Tim Windelschmidt | 244b567 | 2024-02-06 10:18:56 +0100 | [diff] [blame] | 84 | return cmd.RunCommand(ctx, qemuPath, qemuArgs, pf) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 87 | // runQemuWithInstaller runs the Metropolis Installer in a qemu, performing the |
| 88 | // same search-through-std{out,err} as runQemu. |
| 89 | func runQemuWithInstaller(ctx context.Context, args []string, expectedOutput string) (bool, error) { |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 90 | args = append(args, "-drive", "if=virtio,format=raw,snapshot=on,cache=unsafe,file="+installerImage) |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 91 | return runQemu(ctx, args, expectedOutput) |
| Lorenz Brun | 0b93c8d | 2021-11-09 03:58:40 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 94 | // getStorage creates a sparse file, given a size expressed in mebibytes, and |
| 95 | // returns a path to that file. It may return an error. |
| 96 | func getStorage(size int64) (string, error) { |
| Serge Bazanski | 05cf33d | 2023-03-16 20:50:59 +0100 | [diff] [blame] | 97 | nodeStorageDir, err := os.MkdirTemp(os.Getenv("TEST_TMPDIR"), "storage") |
| 98 | if err != nil { |
| 99 | return "", err |
| 100 | } |
| 101 | nodeStorage := filepath.Join(nodeStorageDir, "stor.img") |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 102 | image, err := os.Create(nodeStorage) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 103 | if err != nil { |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 104 | return "", fmt.Errorf("couldn't create the block device image at %q: %w", nodeStorage, err) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 105 | } |
| 106 | if err := syscall.Ftruncate(int(image.Fd()), size*1024*1024); err != nil { |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 107 | return "", fmt.Errorf("couldn't resize the block device image at %q: %w", nodeStorage, err) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 108 | } |
| 109 | image.Close() |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 110 | return nodeStorage, nil |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | // qemuDriveParam returns QEMU parameters required to run it with a |
| 114 | // raw-format image at path. |
| 115 | func qemuDriveParam(path string) []string { |
| 116 | return []string{"-drive", "if=virtio,format=raw,snapshot=off,cache=unsafe,file=" + path} |
| 117 | } |
| 118 | |
| 119 | // checkEspContents verifies the presence of the EFI payload inside of image's |
| 120 | // first partition. It returns nil on success. |
| 121 | func checkEspContents(image *disk.Disk) error { |
| 122 | // Get the ESP. |
| 123 | fs, err := image.GetFilesystem(1) |
| 124 | if err != nil { |
| 125 | return fmt.Errorf("couldn't read the installer ESP: %w", err) |
| 126 | } |
| 127 | // Make sure the EFI payload exists by attempting to open it. |
| 128 | efiPayload, err := fs.OpenFile(osimage.EFIPayloadPath, os.O_RDONLY) |
| 129 | if err != nil { |
| 130 | return fmt.Errorf("couldn't open the installer's EFI Payload at %q: %w", osimage.EFIPayloadPath, err) |
| 131 | } |
| 132 | efiPayload.Close() |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | func TestMain(m *testing.M) { |
| Serge Bazanski | 9778322 | 2021-12-14 16:04:26 +0100 | [diff] [blame] | 137 | installerImage = filepath.Join(os.Getenv("TEST_TMPDIR"), "installer.img") |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 138 | |
| Tim Windelschmidt | 2a1d1b2 | 2024-02-06 07:07:42 +0100 | [diff] [blame] | 139 | installerPath, err := runfiles.Rlocation("_main/metropolis/installer/test/kernel.efi") |
| 140 | if err != nil { |
| 141 | log.Fatal(err) |
| 142 | } |
| 143 | installer, err := os.ReadFile(installerPath) |
| 144 | if err != nil { |
| 145 | log.Fatal(err) |
| 146 | } |
| 147 | |
| 148 | bundlePath, err := runfiles.Rlocation("_main/metropolis/installer/test/testos/testos_bundle.zip") |
| 149 | if err != nil { |
| 150 | log.Fatal(err) |
| 151 | } |
| 152 | bundle, err := os.ReadFile(bundlePath) |
| 153 | if err != nil { |
| 154 | log.Fatal(err) |
| 155 | } |
| 156 | |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 157 | iargs := mctl.MakeInstallerImageArgs{ |
| Lorenz Brun | ad13188 | 2023-06-28 16:42:20 +0200 | [diff] [blame] | 158 | Installer: bytes.NewReader(installer), |
| 159 | TargetPath: installerImage, |
| 160 | NodeParams: &api.NodeParameters{}, |
| 161 | Bundle: bytes.NewReader(bundle), |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 162 | } |
| 163 | if err := mctl.MakeInstallerImage(iargs); err != nil { |
| Mateusz Zalega | 8f72b5d | 2021-12-03 17:08:59 +0100 | [diff] [blame] | 164 | log.Fatalf("Couldn't create the installer image at %q: %v", installerImage, err) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 165 | } |
| 166 | // With common dependencies set up, run the tests. |
| 167 | code := m.Run() |
| 168 | // Clean up. |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 169 | os.Remove(installerImage) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 170 | os.Exit(code) |
| 171 | } |
| 172 | |
| 173 | func TestInstallerImage(t *testing.T) { |
| 174 | // This test examines the installer image, making sure that the GPT and the |
| 175 | // ESP contents are in order. |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 176 | image, err := diskfs.OpenWithMode(installerImage, diskfs.ReadOnly) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 177 | if err != nil { |
| Mateusz Zalega | 8cde8e7 | 2021-11-30 16:22:20 +0100 | [diff] [blame] | 178 | t.Errorf("Couldn't open the installer image at %q: %s", installerImage, err.Error()) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 179 | } |
| 180 | // Verify that GPT exists. |
| 181 | ti, err := image.GetPartitionTable() |
| Tim Windelschmidt | 33306eb | 2024-04-11 01:39:48 +0200 | [diff] [blame] | 182 | if err != nil { |
| 183 | t.Fatalf("Couldn't read the installer image partition table: %s", err) |
| 184 | } |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 185 | if ti.Type() != "gpt" { |
| 186 | t.Error("Couldn't verify that the installer image contains a GPT.") |
| 187 | } |
| 188 | // Check that the first partition is likely to be a valid ESP. |
| 189 | pi := ti.GetPartitions() |
| 190 | esp := (pi[0]).(*gpt.Partition) |
| 191 | if esp.Start == 0 || esp.End == 0 { |
| 192 | t.Error("The installer's ESP GPT entry looks off.") |
| 193 | } |
| 194 | // Verify that the image contains only one partition. |
| 195 | second := (pi[1]).(*gpt.Partition) |
| 196 | if second.Name != "" || second.Start != 0 || second.End != 0 { |
| 197 | t.Error("It appears the installer image contains more than one partition.") |
| 198 | } |
| 199 | // Verify the ESP contents. |
| 200 | if err := checkEspContents(image); err != nil { |
| 201 | t.Error(err.Error()) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func TestNoBlockDevices(t *testing.T) { |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 206 | ctx, ctxC := context.WithCancel(context.Background()) |
| 207 | defer ctxC() |
| 208 | |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 209 | // No block devices are passed to QEMU aside from the install medium. Expect |
| 210 | // the installer to fail at the device probe stage rather than attempting to |
| 211 | // use the medium as the target device. |
| Mateusz Zalega | cdcc739 | 2021-12-08 15:34:53 +0100 | [diff] [blame] | 212 | expectedOutput := "Couldn't find a suitable block device" |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 213 | result, err := runQemuWithInstaller(ctx, nil, expectedOutput) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 214 | if err != nil { |
| 215 | t.Error(err.Error()) |
| 216 | } |
| Tim Windelschmidt | 885668a | 2024-04-19 00:01:06 +0200 | [diff] [blame] | 217 | if !result { |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 218 | t.Errorf("QEMU didn't produce the expected output %q", expectedOutput) |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | func TestBlockDeviceTooSmall(t *testing.T) { |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 223 | ctx, ctxC := context.WithCancel(context.Background()) |
| 224 | defer ctxC() |
| 225 | |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 226 | // Prepare the block device the installer will install to. This time the |
| 227 | // target device is too small to host a Metropolis installation. |
| 228 | imagePath, err := getStorage(64) |
| 229 | defer os.Remove(imagePath) |
| 230 | if err != nil { |
| 231 | t.Errorf(err.Error()) |
| 232 | } |
| 233 | |
| 234 | // Run QEMU. Expect the installer to fail with a predefined error string. |
| Mateusz Zalega | cdcc739 | 2021-12-08 15:34:53 +0100 | [diff] [blame] | 235 | expectedOutput := "Couldn't find a suitable block device" |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 236 | result, err := runQemuWithInstaller(ctx, qemuDriveParam(imagePath), expectedOutput) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 237 | if err != nil { |
| 238 | t.Error(err.Error()) |
| 239 | } |
| Tim Windelschmidt | 885668a | 2024-04-19 00:01:06 +0200 | [diff] [blame] | 240 | if !result { |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 241 | t.Errorf("QEMU didn't produce the expected output %q", expectedOutput) |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | func TestInstall(t *testing.T) { |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 246 | ctx, ctxC := context.WithCancel(context.Background()) |
| 247 | defer ctxC() |
| 248 | |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 249 | // Prepare the block device image the installer will install to. |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 250 | // Needs enough storage for two 4096 MiB system partitions, a 384 MiB ESP |
| 251 | // and a 128 MiB data partition. In addition at the start and end we need |
| 252 | // 1MiB for GPT headers and alignment. |
| 253 | storagePath, err := getStorage(4096*2 + 384 + 128 + 2) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 254 | defer os.Remove(storagePath) |
| 255 | if err != nil { |
| 256 | t.Errorf(err.Error()) |
| 257 | } |
| 258 | |
| 259 | // Run QEMU. Expect the installer to succeed. |
| 260 | expectedOutput := "Installation completed" |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 261 | result, err := runQemuWithInstaller(ctx, qemuDriveParam(storagePath), expectedOutput) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 262 | if err != nil { |
| 263 | t.Error(err.Error()) |
| 264 | } |
| Tim Windelschmidt | 885668a | 2024-04-19 00:01:06 +0200 | [diff] [blame] | 265 | if !result { |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 266 | t.Errorf("QEMU didn't produce the expected output %q", expectedOutput) |
| 267 | } |
| 268 | |
| 269 | // Verify the resulting node image. Check whether the node GPT was created. |
| 270 | storage, err := diskfs.OpenWithMode(storagePath, diskfs.ReadOnly) |
| 271 | if err != nil { |
| 272 | t.Errorf("Couldn't open the resulting node image at %q: %s", storagePath, err.Error()) |
| 273 | } |
| 274 | // Verify that GPT exists. |
| 275 | ti, err := storage.GetPartitionTable() |
| Tim Windelschmidt | 096654a | 2024-04-18 23:10:19 +0200 | [diff] [blame] | 276 | if err != nil { |
| 277 | t.Fatalf("Couldn't read the installer image partition table: %s", err) |
| 278 | } |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 279 | if ti.Type() != "gpt" { |
| 280 | t.Error("Couldn't verify that the resulting node image contains a GPT.") |
| 281 | } |
| 282 | // Check that the first partition is likely to be a valid ESP. |
| 283 | pi := ti.GetPartitions() |
| 284 | esp := (pi[0]).(*gpt.Partition) |
| Lorenz Brun | ad13188 | 2023-06-28 16:42:20 +0200 | [diff] [blame] | 285 | if esp.Name != osimage.ESPLabel || esp.Start == 0 || esp.End == 0 { |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 286 | t.Error("The node's ESP GPT entry looks off.") |
| 287 | } |
| 288 | // Verify the system partition's GPT entry. |
| 289 | system := (pi[1]).(*gpt.Partition) |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 290 | if system.Name != osimage.SystemALabel || system.Start == 0 || system.End == 0 { |
| 291 | t.Error("The node's system partition GPT entry looks off.") |
| 292 | } |
| 293 | // Verify the system partition's GPT entry. |
| 294 | systemB := (pi[2]).(*gpt.Partition) |
| 295 | if systemB.Name != osimage.SystemBLabel || systemB.Start == 0 || systemB.End == 0 { |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 296 | t.Error("The node's system partition GPT entry looks off.") |
| 297 | } |
| 298 | // Verify the data partition's GPT entry. |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 299 | data := (pi[3]).(*gpt.Partition) |
| Lorenz Brun | ad13188 | 2023-06-28 16:42:20 +0200 | [diff] [blame] | 300 | if data.Name != osimage.DataLabel || data.Start == 0 || data.End == 0 { |
| 301 | t.Errorf("The node's data partition GPT entry looks off: %+v", data) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 302 | } |
| 303 | // Verify that there are no more partitions. |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 304 | fourth := (pi[4]).(*gpt.Partition) |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 305 | if fourth.Name != "" || fourth.Start != 0 || fourth.End != 0 { |
| 306 | t.Error("The resulting node image contains more partitions than expected.") |
| 307 | } |
| 308 | // Verify the ESP contents. |
| 309 | if err := checkEspContents(storage); err != nil { |
| 310 | t.Error(err.Error()) |
| 311 | } |
| Serge Bazanski | f9bdf31 | 2023-03-16 21:54:49 +0100 | [diff] [blame] | 312 | storage.File.Close() |
| Lorenz Brun | 0b93c8d | 2021-11-09 03:58:40 +0100 | [diff] [blame] | 313 | // Run QEMU again. Expect TestOS to launch successfully. |
| 314 | expectedOutput = "_TESTOS_LAUNCH_SUCCESS_" |
| Serge Bazanski | 05cf33d | 2023-03-16 20:50:59 +0100 | [diff] [blame] | 315 | time.Sleep(time.Second) |
| Serge Bazanski | e2e0371 | 2021-12-17 12:47:03 +0100 | [diff] [blame] | 316 | result, err = runQemu(ctx, qemuDriveParam(storagePath), expectedOutput) |
| Lorenz Brun | 0b93c8d | 2021-11-09 03:58:40 +0100 | [diff] [blame] | 317 | if err != nil { |
| 318 | t.Error(err.Error()) |
| 319 | } |
| Tim Windelschmidt | 885668a | 2024-04-19 00:01:06 +0200 | [diff] [blame] | 320 | if !result { |
| Lorenz Brun | 0b93c8d | 2021-11-09 03:58:40 +0100 | [diff] [blame] | 321 | t.Errorf("QEMU didn't produce the expected output %q", expectedOutput) |
| 322 | } |
| Mateusz Zalega | 43e2107 | 2021-10-08 18:05:29 +0200 | [diff] [blame] | 323 | } |