Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder: don't enable iothread for all scsi #249

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/proxmox/common/step_start_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func generateProxmoxDisks(disks []diskConfig) proxmox.QemuDevices {
setDeviceParamIfDefined(devs[idx], "cache", disks[idx].CacheMode)
setDeviceParamIfDefined(devs[idx], "format", disks[idx].DiskFormat)

if devs[idx]["type"] == "scsi" || devs[idx]["type"] == "virtio" &&
if (devs[idx]["type"] == "scsi" || devs[idx]["type"] == "virtio") &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 on the parenthesis

disks[idx].IOThread {
devs[idx]["iothread"] = "true"
}
Expand Down
97 changes: 97 additions & 0 deletions builder/proxmox/common/step_start_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/Telmate/proxmox-api-go/proxmox"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/packer-plugin-sdk/common"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
Expand Down Expand Up @@ -498,3 +499,99 @@ func TestStartVM_AssertInitialQuemuConfig(t *testing.T) {
})
}
}

func TestGenerateProxmoxDisks(t *testing.T) {
tests := []struct {
name string
disks []diskConfig
expectOutput proxmox.QemuDevices
}{
{
"plain config, no special option set",
[]diskConfig{
{
Type: "scsi",
StoragePool: "local-lvm",
Size: "10G",
CacheMode: "none",
DiskFormat: "qcow2",
IOThread: false,
Discard: false,
SSD: false,
},
},
proxmox.QemuDevices{
0: proxmox.QemuDevice{
"type": "scsi",
"discard": "ignore",
"size": "10G",
"storage": "local-lvm",
"cache": "none",
"format": "qcow2",
},
},
},
{
"scsi + iothread, iothread should be true",
[]diskConfig{
{
Type: "scsi",
StoragePool: "local-lvm",
Size: "10G",
CacheMode: "none",
DiskFormat: "qcow2",
IOThread: true,
Discard: false,
SSD: false,
},
},
proxmox.QemuDevices{
0: proxmox.QemuDevice{
"type": "scsi",
"discard": "ignore",
"size": "10G",
"storage": "local-lvm",
"cache": "none",
"format": "qcow2",
"iothread": "true",
},
},
},
{
"virtio + iothread, iothread should be true",
[]diskConfig{
{
Type: "virtio",
StoragePool: "local-lvm",
Size: "10G",
CacheMode: "none",
DiskFormat: "qcow2",
IOThread: true,
Discard: false,
SSD: false,
},
},
proxmox.QemuDevices{
0: proxmox.QemuDevice{
"type": "virtio",
"discard": "ignore",
"size": "10G",
"storage": "local-lvm",
"cache": "none",
"format": "qcow2",
"iothread": "true",
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
devs := generateProxmoxDisks(tt.disks)
diff := cmp.Diff(devs, tt.expectOutput)
if diff != "" {
t.Errorf("mismatch in produced qemu disks specs: %s", diff)
}
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian/v3 v3.2.1 h1:d8MncMlErDFTwQGBK1xhv026j9kqhvw1Qv9IbWT1VLQ=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down