Skip to content

Commit 3f7a153

Browse files
mpywelllbajolet-hashicorp
authored andcommitted
Improve tests, update doc
- Added test for overallocation of storage - Added additional tests for ISO `device` field conversion - Added missing default bus detail to `device` field documentation
1 parent e1a726d commit 3f7a153

File tree

7 files changed

+140
-16
lines changed

7 files changed

+140
-16
lines changed

.web-docs/components/builder/clone/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ In HCL2:
676676
`sataX` or `scsiX`.
677677
For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
678678
`scsi` from 0 to 30.
679-
Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic assignment (next available bus index after hard disks are allocated)
679+
Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic ide assignment (next available ide bus index after hard disks are allocated)
680680

681681
- `type` (string) - Bus type that the ISO will be mounted on. Can be `ide`, `sata` or `scsi`. Defaults to `ide`.
682682

.web-docs/components/builder/iso/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ HCL2 example:
354354
`sataX` or `scsiX`.
355355
For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
356356
`scsi` from 0 to 30.
357-
Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic assignment (next available bus index after hard disks are allocated)
357+
Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic ide assignment (next available ide bus index after hard disks are allocated)
358358

359359
- `type` (string) - Bus type that the ISO will be mounted on. Can be `ide`, `sata` or `scsi`. Defaults to `ide`.
360360

builder/proxmox/clone/step_map_source_disks.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func (s *StepMapSourceDisks) Run(ctx context.Context, state multistep.StateBag)
9191
// store discovered disks in common config
9292
d := state.Get("config").(*proxmox.Config)
9393
d.CloneSourceDisks = sourceDisks
94-
state.Put("config", d)
9594

9695
return multistep.ActionContinue
9796
}

builder/proxmox/common/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ type ISOsConfig struct {
242242
// `sataX` or `scsiX`.
243243
// For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
244244
// `scsi` from 0 to 30.
245-
// Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic assignment (next available bus index after hard disks are allocated)
245+
// Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic ide assignment (next available ide bus index after hard disks are allocated)
246246
Device string `mapstructure:"device"`
247247
// Bus type that the ISO will be mounted on. Can be `ide`, `sata` or `scsi`. Defaults to `ide`.
248248
Type string `mapstructure:"type"`

builder/proxmox/common/config_test.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,47 @@ func TestISOs(t *testing.T) {
249249

250250
func TestDeprecatedISOOptionsAreConverted(t *testing.T) {
251251
isotests := []struct {
252-
name string
253-
ISOs map[string]interface{}
252+
name string
253+
expectedToFail bool
254+
ISOs map[string]interface{}
254255
}{
255256
{
256-
// Ensure deprecated device field is converted
257-
name: "device should be converted to type and index",
257+
name: "cd_files valid should succeed",
258+
expectedToFail: false,
259+
ISOs: map[string]interface{}{
260+
"device": "ide1",
261+
"cd_files": []string{
262+
"config_test.go",
263+
},
264+
"iso_storage_pool": "local",
265+
},
266+
},
267+
{
268+
name: "cd_content valid should succeed",
269+
expectedToFail: false,
258270
ISOs: map[string]interface{}{
259-
"device": "ide3",
271+
"device": "ide1",
272+
"cd_content": map[string]string{
273+
"test": "config_test.go",
274+
},
275+
"iso_storage_pool": "local",
276+
},
277+
},
278+
{
279+
name: "iso_url valid should succeed",
280+
expectedToFail: false,
281+
ISOs: map[string]interface{}{
282+
"device": "ide1",
283+
"iso_url": "http://example.com",
284+
"iso_checksum": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
285+
"iso_storage_pool": "local",
286+
},
287+
},
288+
{
289+
name: "iso_file valid should succeed",
290+
expectedToFail: false,
291+
ISOs: map[string]interface{}{
292+
"device": "ide1",
260293
"iso_file": "local:iso/test.iso",
261294
},
262295
},
@@ -284,6 +317,15 @@ func TestDeprecatedISOOptionsAreConverted(t *testing.T) {
284317
if config.ISOs[0].Index != index {
285318
t.Errorf("Expected device to be converted to index %s", index)
286319
}
320+
321+
if c.expectedToFail == true && err == nil {
322+
t.Error("expected config preparation to fail, but no error occured")
323+
}
324+
325+
if c.expectedToFail == false && err != nil {
326+
t.Errorf("expected config preparation to succeed, but %s", err.Error())
327+
}
328+
287329
})
288330
}
289331
}

builder/proxmox/common/step_start_vm_test.go

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,12 @@ func TestStartVM_AssertInitialQuemuConfig(t *testing.T) {
501501

502502
func TestGenerateProxmoxDisks(t *testing.T) {
503503
tests := []struct {
504-
name string
505-
disks []diskConfig
506-
isos []ISOsConfig
507-
expectOutput *proxmox.QemuStorages
504+
name string
505+
disks []diskConfig
506+
isos []ISOsConfig
507+
clonesourcedisks []string
508+
expectedToFail bool
509+
expectOutput *proxmox.QemuStorages
508510
}{
509511
{
510512
"plain config, no special option set",
@@ -522,6 +524,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
522524
},
523525
},
524526
[]ISOsConfig{},
527+
[]string{},
528+
false,
525529
&proxmox.QemuStorages{
526530
Ide: &proxmox.QemuIdeDisks{},
527531
Sata: &proxmox.QemuSataDisks{},
@@ -559,6 +563,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
559563
},
560564
},
561565
[]ISOsConfig{},
566+
[]string{},
567+
false,
562568
&proxmox.QemuStorages{
563569
Ide: &proxmox.QemuIdeDisks{},
564570
Sata: &proxmox.QemuSataDisks{},
@@ -596,6 +602,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
596602
},
597603
},
598604
[]ISOsConfig{},
605+
[]string{},
606+
false,
599607
&proxmox.QemuStorages{
600608
Ide: &proxmox.QemuIdeDisks{},
601609
Sata: &proxmox.QemuSataDisks{},
@@ -633,6 +641,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
633641
},
634642
},
635643
[]ISOsConfig{},
644+
[]string{},
645+
false,
636646
&proxmox.QemuStorages{
637647
Ide: &proxmox.QemuIdeDisks{},
638648
Sata: &proxmox.QemuSataDisks{},
@@ -669,6 +679,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
669679
},
670680
},
671681
[]ISOsConfig{},
682+
[]string{},
683+
false,
672684
&proxmox.QemuStorages{
673685
Ide: &proxmox.QemuIdeDisks{},
674686
Sata: &proxmox.QemuSataDisks{},
@@ -688,6 +700,62 @@ func TestGenerateProxmoxDisks(t *testing.T) {
688700
},
689701
},
690702
},
703+
{
704+
"overallocate sata, should error",
705+
[]diskConfig{
706+
{
707+
Type: "sata",
708+
StoragePool: "local-lvm",
709+
Size: "11G",
710+
CacheMode: "none",
711+
DiskFormat: "qcow2",
712+
IOThread: true,
713+
},
714+
{
715+
Type: "sata",
716+
StoragePool: "local-lvm",
717+
Size: "11G",
718+
CacheMode: "none",
719+
DiskFormat: "qcow2",
720+
IOThread: true,
721+
},
722+
{
723+
Type: "sata",
724+
StoragePool: "local-lvm",
725+
Size: "11G",
726+
CacheMode: "none",
727+
DiskFormat: "qcow2",
728+
IOThread: true,
729+
},
730+
{
731+
Type: "sata",
732+
StoragePool: "local-lvm",
733+
Size: "11G",
734+
CacheMode: "none",
735+
DiskFormat: "qcow2",
736+
IOThread: true,
737+
},
738+
{
739+
Type: "sata",
740+
StoragePool: "local-lvm",
741+
Size: "11G",
742+
CacheMode: "none",
743+
DiskFormat: "qcow2",
744+
IOThread: true,
745+
},
746+
},
747+
[]ISOsConfig{
748+
{
749+
Type: "sata",
750+
ISOFile: "local:iso/test.iso",
751+
},
752+
},
753+
[]string{
754+
"sata0",
755+
},
756+
true,
757+
&proxmox.QemuStorages{},
758+
},
691759
{
692760
"bunch of disks, should be defined in the discovery order",
693761
[]diskConfig{
@@ -757,6 +825,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
757825
},
758826
},
759827
[]ISOsConfig{},
828+
[]string{},
829+
false,
760830
&proxmox.QemuStorages{
761831
Ide: &proxmox.QemuIdeDisks{
762832
Disk_0: &proxmox.QemuIdeStorage{
@@ -910,6 +980,8 @@ func TestGenerateProxmoxDisks(t *testing.T) {
910980
ISOFile: "local:iso/test.iso",
911981
},
912982
},
983+
[]string{},
984+
false,
913985
&proxmox.QemuStorages{
914986
Ide: &proxmox.QemuIdeDisks{
915987
Disk_0: &proxmox.QemuIdeStorage{
@@ -993,8 +1065,19 @@ func TestGenerateProxmoxDisks(t *testing.T) {
9931065

9941066
for _, tt := range tests {
9951067
t.Run(tt.name, func(t *testing.T) {
996-
_, _, devs := generateProxmoxDisks(tt.disks, tt.isos, nil)
997-
assert.Equal(t, devs, tt.expectOutput)
1068+
err, _, devs := generateProxmoxDisks(tt.disks, tt.isos, tt.clonesourcedisks)
1069+
1070+
if tt.expectedToFail && err == nil {
1071+
t.Error("expected config preparation to fail, but no error occured")
1072+
}
1073+
1074+
if !tt.expectedToFail && err != nil {
1075+
t.Errorf("expected config preparation to succeed, but %s", err.Error())
1076+
}
1077+
1078+
if !tt.expectedToFail {
1079+
assert.Equal(t, devs, tt.expectOutput)
1080+
}
9981081
})
9991082
}
10001083
}

docs-partials/builder/proxmox/common/ISOsConfig-not-required.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
`sataX` or `scsiX`.
66
For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
77
`scsi` from 0 to 30.
8-
Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic assignment (next available bus index after hard disks are allocated)
8+
Defaulted to `ide3` in versions up to v1.8, now defaults to dynamic ide assignment (next available ide bus index after hard disks are allocated)
99

1010
- `type` (string) - Bus type that the ISO will be mounted on. Can be `ide`, `sata` or `scsi`. Defaults to `ide`.
1111

0 commit comments

Comments
 (0)