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