Skip to content

Commit 74d0126

Browse files
committed
kola: allow missing size in diskspec for primaryDisk
When using the new `primaryDisk` key, allow the diskspec to omit the size component, in which case we don't resize the boot disk.
1 parent 40707f4 commit 74d0126

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

docs/kola/external-tests.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ In the example above, the test would only run if `--tag special` was provided.
231231

232232
The `additionalDisks` key has the same semantics as the `--add-disk` argument
233233
to `qemuexec`. It is currently only supported on `qemu`. The `primaryDisk` key
234-
also supports the same syntax and controls the primary boot disk.
234+
also supports the same syntax and controls the primary boot disk. Only for the
235+
`primaryDisk` key, the size can be omitted (e.g. `:mpath`), in which case the
236+
qcow2 will not be resized.
235237

236238
The `injectContainer` boolean if set will cause the framework to inject
237239
the ostree base image container into the target system; the path can be

mantle/platform/api/gcloud/compute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (a *API) vmname() string {
3838
func ParseDisk(spec string, zone string) (*compute.AttachedDisk, error) {
3939
var diskInterface string
4040

41-
size, diskmap, err := util.ParseDiskSpec(spec)
41+
size, diskmap, err := util.ParseDiskSpec(spec, false)
4242
if err != nil {
4343
return nil, fmt.Errorf("failed to parse disk spec %q: %w", spec, err)
4444
}

mantle/platform/machine/qemu/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl
143143
var primaryDisk platform.Disk
144144
if options.PrimaryDisk != "" {
145145
var diskp *platform.Disk
146-
if diskp, err = platform.ParseDisk(options.PrimaryDisk); err != nil {
146+
if diskp, err = platform.ParseDisk(options.PrimaryDisk, true); err != nil {
147147
return nil, errors.Wrapf(err, "parsing primary disk spec '%s'", options.PrimaryDisk)
148148
}
149149
primaryDisk = *diskp

mantle/platform/qemu.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ type Disk struct {
106106
nbdServCmd exec.Cmd // command to serve the disk
107107
}
108108

109-
func ParseDisk(spec string) (*Disk, error) {
109+
func ParseDisk(spec string, allowNoSize bool) (*Disk, error) {
110110
var channel string
111111
sectorSize := 0
112112
logicalSectorSize := 0
113113
serialOpt := []string{}
114114
multipathed := false
115115
var wwn uint64
116116

117-
size, diskmap, err := util.ParseDiskSpec(spec)
117+
size, diskmap, err := util.ParseDiskSpec(spec, allowNoSize)
118118
if err != nil {
119119
return nil, fmt.Errorf("failed to parse disk spec %q: %w", spec, err)
120120
}
@@ -143,8 +143,12 @@ func ParseDisk(spec string) (*Disk, error) {
143143
}
144144
}
145145

146+
sizeStr := ""
147+
if size > 0 {
148+
sizeStr = fmt.Sprintf("%dG", size)
149+
}
146150
return &Disk{
147-
Size: fmt.Sprintf("%dG", size),
151+
Size: sizeStr,
148152
Channel: channel,
149153
DeviceOpts: serialOpt,
150154
SectorSize: sectorSize,
@@ -1302,7 +1306,7 @@ func (builder *QemuBuilder) AddDisk(disk *Disk) error {
13021306
// AddDisksFromSpecs adds multiple secondary disks from their specs.
13031307
func (builder *QemuBuilder) AddDisksFromSpecs(specs []string) error {
13041308
for _, spec := range specs {
1305-
if disk, err := ParseDisk(spec); err != nil {
1309+
if disk, err := ParseDisk(spec, false); err != nil {
13061310
return errors.Wrapf(err, "parsing additional disk spec '%s'", spec)
13071311
} else if err = builder.AddDisk(disk); err != nil {
13081312
return errors.Wrapf(err, "adding additional disk '%s'", spec)

mantle/util/common.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ func RunCmdTimeout(timeout time.Duration, cmd string, args ...string) error {
125125

126126
// ParseDiskSpec converts a disk specification into a Disk. The format is:
127127
// <size>[:<opt1>,<opt2>,...], like ["5G:channel=nvme"]
128-
func ParseDiskSpec(spec string) (int64, map[string]string, error) {
128+
func ParseDiskSpec(spec string, allowNoSize bool) (int64, map[string]string, error) {
129129
diskmap := map[string]string{}
130130
split := strings.Split(spec, ":")
131-
if split[0] == "" || (!strings.HasSuffix(split[0], "G")) {
131+
if split[0] == "" {
132+
if !allowNoSize {
133+
return 0, nil, fmt.Errorf("no size provided in '%s'", spec)
134+
}
135+
} else if !strings.HasSuffix(split[0], "G") {
132136
return 0, nil, fmt.Errorf("invalid size opt %s", spec)
133137
}
134138
var disksize string
@@ -149,10 +153,14 @@ func ParseDiskSpec(spec string) (int64, map[string]string, error) {
149153
} else {
150154
return 0, nil, fmt.Errorf("invalid disk spec %s", spec)
151155
}
152-
disksize = strings.TrimSuffix(disksize, "G")
153-
size, err := strconv.ParseInt(disksize, 10, 32)
154-
if err != nil {
155-
return 0, nil, fmt.Errorf("failed to convert %q to int64: %w", disksize, err)
156+
var size int64 = 0
157+
if disksize != "" {
158+
disksize = strings.TrimSuffix(disksize, "G")
159+
var err error
160+
size, err = strconv.ParseInt(disksize, 10, 32)
161+
if err != nil {
162+
return 0, nil, fmt.Errorf("failed to convert %q to int64: %w", disksize, err)
163+
}
156164
}
157165
return size, diskmap, nil
158166
}

0 commit comments

Comments
 (0)