Skip to content

Commit

Permalink
kola: allow missing size in diskspec for primaryDisk
Browse files Browse the repository at this point in the history
When using the new `primaryDisk` key, allow the diskspec to omit the
size component, in which case we don't resize the boot disk.
  • Loading branch information
jlebon committed Jun 19, 2024
1 parent 015d3df commit 3e6d216
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docs/kola/external-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mantle/platform/api/gcloud/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion mantle/platform/machine/qemu/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ 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
serialOpt := []string{}
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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions mantle/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// <size>[:<opt1>,<opt2>,...], 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
Expand All @@ -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
}

0 comments on commit 3e6d216

Please sign in to comment.