Skip to content

Commit caea80f

Browse files
committed
fix: detect efi image type to make hhfab upgrade testing work
Signed-off-by: Sergei Lukianov <[email protected]>
1 parent 4726c18 commit caea80f

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

pkg/hhfab/vlabrunner.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,11 @@ func (c *Config) VLABRun(ctx context.Context, vlab *VLAB, opts VLABRunOpts) erro
373373
"-global", "ICH9-LPC.disable_s3=1",
374374
}
375375

376-
efiFormat := "qcow2"
377-
if vm.Type == VMTypeSwitch {
378-
efiFormat = "raw"
376+
efiFormat, err := getImageFormat(filepath.Join(vmDir, VLABEFICodeFile))
377+
if err != nil {
378+
return fmt.Errorf("getting EFI image type for VM %s: %w", vm.Name, err)
379379
}
380+
380381
args = append(args,
381382
"-drive", "if=pflash,file="+VLABEFICodeFile+",format="+efiFormat+",readonly=on",
382383
"-drive", "if=pflash,file="+VLABEFIVarsFile+",format="+efiFormat,
@@ -1121,3 +1122,24 @@ func sshReadMarker(sftp *sftp.Client) (string, error) {
11211122

11221123
return strings.TrimSpace(string(rawMarker)), nil
11231124
}
1125+
1126+
func getImageFormat(filePath string) (string, error) {
1127+
f, err := os.Open(filePath)
1128+
if err != nil {
1129+
return "", fmt.Errorf("opening file: %w", err)
1130+
}
1131+
defer f.Close()
1132+
1133+
header := make([]byte, 4)
1134+
_, err = f.Read(header)
1135+
if err != nil {
1136+
return "", fmt.Errorf("reading file: %w", err)
1137+
}
1138+
1139+
// qcow2 magic string: https://github.com/qemu/qemu/blob/master/docs/interop/qcow2.txt
1140+
if string(header) == "QFI\xfb" {
1141+
return "qcow2", nil
1142+
}
1143+
1144+
return "raw", nil
1145+
}

0 commit comments

Comments
 (0)