Skip to content

Commit 9886708

Browse files
builder: don't enable iothread for all scsi
When a SCSI disk is specified for a configuration, the iothread argument should only be set if requested, and not all the time. Because of a priority problem though, all the SCSI disks ended-up with iothread set, even if it was not requested. This commit fixes that, and ensures it is fixed by adding some tests for it.
1 parent f0aca8b commit 9886708

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

builder/proxmox/common/step_start_vm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func generateProxmoxDisks(disks []diskConfig) proxmox.QemuDevices {
287287
setDeviceParamIfDefined(devs[idx], "cache", disks[idx].CacheMode)
288288
setDeviceParamIfDefined(devs[idx], "format", disks[idx].DiskFormat)
289289

290-
if devs[idx]["type"] == "scsi" || devs[idx]["type"] == "virtio" &&
290+
if (devs[idx]["type"] == "scsi" || devs[idx]["type"] == "virtio") &&
291291
disks[idx].IOThread {
292292
devs[idx]["iothread"] = "true"
293293
}

builder/proxmox/common/step_start_vm_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/Telmate/proxmox-api-go/proxmox"
12+
"github.com/google/go-cmp/cmp"
1213
"github.com/hashicorp/packer-plugin-sdk/common"
1314
"github.com/hashicorp/packer-plugin-sdk/multistep"
1415
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
@@ -498,3 +499,99 @@ func TestStartVM_AssertInitialQuemuConfig(t *testing.T) {
498499
})
499500
}
500501
}
502+
503+
func TestGenerateProxmoxDisks(t *testing.T) {
504+
tests := []struct {
505+
name string
506+
disks []diskConfig
507+
expectOutput proxmox.QemuDevices
508+
}{
509+
{
510+
"plain config, no special option set",
511+
[]diskConfig{
512+
{
513+
Type: "scsi",
514+
StoragePool: "local-lvm",
515+
Size: "10G",
516+
CacheMode: "none",
517+
DiskFormat: "qcow2",
518+
IOThread: false,
519+
Discard: false,
520+
SSD: false,
521+
},
522+
},
523+
proxmox.QemuDevices{
524+
0: proxmox.QemuDevice{
525+
"type": "scsi",
526+
"discard": "ignore",
527+
"size": "10G",
528+
"storage": "local-lvm",
529+
"cache": "none",
530+
"format": "qcow2",
531+
},
532+
},
533+
},
534+
{
535+
"scsi + iothread, iothread should be true",
536+
[]diskConfig{
537+
{
538+
Type: "scsi",
539+
StoragePool: "local-lvm",
540+
Size: "10G",
541+
CacheMode: "none",
542+
DiskFormat: "qcow2",
543+
IOThread: true,
544+
Discard: false,
545+
SSD: false,
546+
},
547+
},
548+
proxmox.QemuDevices{
549+
0: proxmox.QemuDevice{
550+
"type": "scsi",
551+
"discard": "ignore",
552+
"size": "10G",
553+
"storage": "local-lvm",
554+
"cache": "none",
555+
"format": "qcow2",
556+
"iothread": "true",
557+
},
558+
},
559+
},
560+
{
561+
"virtio + iothread, iothread should be true",
562+
[]diskConfig{
563+
{
564+
Type: "virtio",
565+
StoragePool: "local-lvm",
566+
Size: "10G",
567+
CacheMode: "none",
568+
DiskFormat: "qcow2",
569+
IOThread: true,
570+
Discard: false,
571+
SSD: false,
572+
},
573+
},
574+
proxmox.QemuDevices{
575+
0: proxmox.QemuDevice{
576+
"type": "virtio",
577+
"discard": "ignore",
578+
"size": "10G",
579+
"storage": "local-lvm",
580+
"cache": "none",
581+
"format": "qcow2",
582+
"iothread": "true",
583+
},
584+
},
585+
},
586+
}
587+
588+
for _, tt := range tests {
589+
t.Run(tt.name, func(t *testing.T) {
590+
devs := generateProxmoxDisks(tt.disks)
591+
diff := cmp.Diff(devs, tt.expectOutput)
592+
if diff != "" {
593+
t.Errorf("mismatch in produced qemu disks specs: %s", diff)
594+
}
595+
})
596+
}
597+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/gofrs/uuid v4.0.0+incompatible // indirect
3636
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3737
github.com/golang/protobuf v1.5.2 // indirect
38-
github.com/google/go-cmp v0.5.9 // indirect
38+
github.com/google/go-cmp v0.6.0 // indirect
3939
github.com/google/uuid v1.3.0 // indirect
4040
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
4141
github.com/googleapis/gax-go/v2 v2.6.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
115115
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
116116
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
117117
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
118+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
119+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
118120
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
119121
github.com/google/martian/v3 v3.2.1 h1:d8MncMlErDFTwQGBK1xhv026j9kqhvw1Qv9IbWT1VLQ=
120122
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

0 commit comments

Comments
 (0)