diff --git a/docs/kola/external-tests.md b/docs/kola/external-tests.md index ac61dba8aa..8d2b82d250 100644 --- a/docs/kola/external-tests.md +++ b/docs/kola/external-tests.md @@ -231,7 +231,9 @@ In the example above, the test would only run if `--tag special` was provided. The `additionalDisks` key has the same semantics as the `--add-disk` argument to `qemuexec`. It is currently only supported on `qemu`. The `primaryDisk` key -also supports the same syntax and controls the primary boot disk. +also supports the same syntax and controls the primary boot disk. Only for the +`primaryDisk` key, the size can be omitted (e.g. `:mpath`), in which case the +qcow2 will not be resized. The `injectContainer` boolean if set will cause the framework to inject the ostree base image container into the target system; the path can be diff --git a/mantle/platform/api/gcloud/compute.go b/mantle/platform/api/gcloud/compute.go index 68a3b5b705..9e8e16434f 100644 --- a/mantle/platform/api/gcloud/compute.go +++ b/mantle/platform/api/gcloud/compute.go @@ -38,7 +38,7 @@ func (a *API) vmname() string { func ParseDisk(spec string, zone string) (*compute.AttachedDisk, error) { var diskInterface string - size, diskmap, err := util.ParseDiskSpec(spec) + size, diskmap, err := util.ParseDiskSpec(spec, false) if err != nil { return nil, fmt.Errorf("failed to parse disk spec %q: %w", spec, err) } diff --git a/mantle/platform/machine/qemu/cluster.go b/mantle/platform/machine/qemu/cluster.go index 114daaf054..a16275a968 100644 --- a/mantle/platform/machine/qemu/cluster.go +++ b/mantle/platform/machine/qemu/cluster.go @@ -143,7 +143,7 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl var primaryDisk platform.Disk if options.PrimaryDisk != "" { var diskp *platform.Disk - if diskp, err = platform.ParseDisk(options.PrimaryDisk); err != nil { + if diskp, err = platform.ParseDisk(options.PrimaryDisk, true); err != nil { return nil, errors.Wrapf(err, "parsing primary disk spec '%s'", options.PrimaryDisk) } primaryDisk = *diskp diff --git a/mantle/platform/qemu.go b/mantle/platform/qemu.go index 751bde03e6..6fe76da9fc 100644 --- a/mantle/platform/qemu.go +++ b/mantle/platform/qemu.go @@ -106,7 +106,7 @@ type Disk struct { nbdServCmd exec.Cmd // command to serve the disk } -func ParseDisk(spec string) (*Disk, error) { +func ParseDisk(spec string, allowNoSize bool) (*Disk, error) { var channel string sectorSize := 0 logicalSectorSize := 0 @@ -114,7 +114,7 @@ func ParseDisk(spec string) (*Disk, error) { multipathed := false var wwn uint64 - size, diskmap, err := util.ParseDiskSpec(spec) + size, diskmap, err := util.ParseDiskSpec(spec, allowNoSize) if err != nil { return nil, fmt.Errorf("failed to parse disk spec %q: %w", spec, err) } @@ -143,8 +143,12 @@ func ParseDisk(spec string) (*Disk, error) { } } + sizeStr := "" + if size > 0 { + sizeStr = fmt.Sprintf("%dG", size) + } return &Disk{ - Size: fmt.Sprintf("%dG", size), + Size: sizeStr, Channel: channel, DeviceOpts: serialOpt, SectorSize: sectorSize, @@ -1302,7 +1306,7 @@ func (builder *QemuBuilder) AddDisk(disk *Disk) error { // AddDisksFromSpecs adds multiple secondary disks from their specs. func (builder *QemuBuilder) AddDisksFromSpecs(specs []string) error { for _, spec := range specs { - if disk, err := ParseDisk(spec); err != nil { + if disk, err := ParseDisk(spec, false); err != nil { return errors.Wrapf(err, "parsing additional disk spec '%s'", spec) } else if err = builder.AddDisk(disk); err != nil { return errors.Wrapf(err, "adding additional disk '%s'", spec) diff --git a/mantle/util/common.go b/mantle/util/common.go index 94acfac6b9..f5d7ea1477 100644 --- a/mantle/util/common.go +++ b/mantle/util/common.go @@ -125,10 +125,14 @@ func RunCmdTimeout(timeout time.Duration, cmd string, args ...string) error { // ParseDiskSpec converts a disk specification into a Disk. The format is: // [:,,...], like ["5G:channel=nvme"] -func ParseDiskSpec(spec string) (int64, map[string]string, error) { +func ParseDiskSpec(spec string, allowNoSize bool) (int64, map[string]string, error) { diskmap := map[string]string{} split := strings.Split(spec, ":") - if split[0] == "" || (!strings.HasSuffix(split[0], "G")) { + if split[0] == "" { + if !allowNoSize { + return 0, nil, fmt.Errorf("no size provided in '%s'", spec) + } + } else if !strings.HasSuffix(split[0], "G") { return 0, nil, fmt.Errorf("invalid size opt %s", spec) } var disksize string @@ -149,10 +153,14 @@ func ParseDiskSpec(spec string) (int64, map[string]string, error) { } else { return 0, nil, fmt.Errorf("invalid disk spec %s", spec) } - disksize = strings.TrimSuffix(disksize, "G") - size, err := strconv.ParseInt(disksize, 10, 32) - if err != nil { - return 0, nil, fmt.Errorf("failed to convert %q to int64: %w", disksize, err) + var size int64 = 0 + if disksize != "" { + disksize = strings.TrimSuffix(disksize, "G") + var err error + size, err = strconv.ParseInt(disksize, 10, 32) + if err != nil { + return 0, nil, fmt.Errorf("failed to convert %q to int64: %w", disksize, err) + } } return size, diskmap, nil }