File: config_test.go

package info (click to toggle)
packer 1.6.6%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 32,016 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (695 lines) | stat: -rw-r--r-- 16,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
package qemu

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"reflect"
	"testing"
	"time"

	"github.com/hashicorp/packer/packer-plugin-sdk/common"
	packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
	"github.com/stretchr/testify/assert"
)

var testPem = `
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAxd4iamvrwRJvtNDGQSIbNvvIQN8imXTRWlRY62EvKov60vqu
hh+rDzFYAIIzlmrJopvOe0clqmi3mIP9dtkjPFrYflq52a2CF5q+BdwsJXuRHbJW
LmStZUwW1khSz93DhvhmK50nIaczW63u4EO/jJb3xj+wxR1Nkk9bxi3DDsYFt8SN
AzYx9kjlEYQ/+sI4/ATfmdV9h78SVotjScupd9KFzzi76gWq9gwyCBLRynTUWlyD
2UOfJRkOvhN6/jKzvYfVVwjPSfA9IMuooHdScmC4F6KBKJl/zf/zETM0XyzIDNmH
uOPbCiljq2WoRM+rY6ET84EO0kVXbfx8uxUsqQIDAQABAoIBAQCkPj9TF0IagbM3
5BSs/CKbAWS4dH/D4bPlxx4IRCNirc8GUg+MRb04Xz0tLuajdQDqeWpr6iLZ0RKV
BvreLF+TOdV7DNQ4XE4gSdJyCtCaTHeort/aordL3l0WgfI7mVk0L/yfN1PEG4YG
E9q1TYcyrB3/8d5JwIkjabxERLglCcP+geOEJp+QijbvFIaZR/n2irlKW4gSy6ko
9B0fgUnhkHysSg49ChHQBPQ+o5BbpuLrPDFMiTPTPhdfsvGGcyCGeqfBA56oHcSF
K02Fg8OM+Bd1lb48LAN9nWWY4WbwV+9bkN3Ym8hO4c3a/Dxf2N7LtAQqWZzFjvM3
/AaDvAgBAoGBAPLD+Xn1IYQPMB2XXCXfOuJewRY7RzoVWvMffJPDfm16O7wOiW5+
2FmvxUDayk4PZy6wQMzGeGKnhcMMZTyaq2g/QtGfrvy7q1Lw2fB1VFlVblvqhoJa
nMJojjC4zgjBkXMHsRLeTmgUKyGs+fdFbfI6uejBnnf+eMVUMIdJ+6I9AoGBANCn
kWO9640dttyXURxNJ3lBr2H3dJOkmD6XS+u+LWqCSKQe691Y/fZ/ZL0Oc4Mhy7I6
hsy3kDQ5k2V0fkaNODQIFJvUqXw2pMewUk8hHc9403f4fe9cPrL12rQ8WlQw4yoC
v2B61vNczCCUDtGxlAaw8jzSRaSI5s6ax3K7enbdAoGBAJB1WYDfA2CoAQO6y9Sl
b07A/7kQ8SN5DbPaqrDrBdJziBQxukoMJQXJeGFNUFD/DXFU5Fp2R7C86vXT7HIR
v6m66zH+CYzOx/YE6EsUJms6UP9VIVF0Rg/RU7teXQwM01ZV32LQ8mswhTH20o/3
uqMHmxUMEhZpUMhrfq0isyApAoGAe1UxGTXfj9AqkIVYylPIq2HqGww7+jFmVEj1
9Wi6S6Sq72ffnzzFEPkIQL/UA4TsdHMnzsYKFPSbbXLIWUeMGyVTmTDA5c0e5XIR
lPhMOKCAzv8w4VUzMnEkTzkFY5JqFCD/ojW57KvDdNZPVB+VEcdxyAW6aKELXMAc
eHLc1nkCgYEApm/motCTPN32nINZ+Vvywbv64ZD+gtpeMNP3CLrbe1X9O+H52AXa
1jCoOldWR8i2bs2NVPcKZgdo6fFULqE4dBX7Te/uYEIuuZhYLNzRO1IKU/YaqsXG
3bfQ8hKYcSnTfE0gPtLDnqCIxTocaGLSHeG3TH9fTw+dA8FvWpUztI4=
-----END RSA PRIVATE KEY-----
`

func testConfig() map[string]interface{} {
	return map[string]interface{}{
		"iso_checksum":            "md5:0B0F137F17AC10944716020B018F8126",
		"iso_url":                 "http://www.google.com/",
		"ssh_username":            "foo",
		common.BuildNameConfigKey: "foo",
	}
}

func TestBuilderPrepare_Defaults(t *testing.T) {
	var c Config
	config := testConfig()
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	if c.OutputDir != "output-foo" {
		t.Errorf("bad output dir: %s", c.OutputDir)
	}

	if c.CommConfig.HostPortMin != 2222 {
		t.Errorf("bad min ssh host port: %d", c.CommConfig.HostPortMin)
	}

	if c.CommConfig.HostPortMax != 4444 {
		t.Errorf("bad max ssh host port: %d", c.CommConfig.HostPortMax)
	}

	if c.CommConfig.Comm.SSHPort != 22 {
		t.Errorf("bad ssh port: %d", c.CommConfig.Comm.SSHPort)
	}

	if c.VMName != "packer-foo" {
		t.Errorf("bad vm name: %s", c.VMName)
	}

	if c.Format != "qcow2" {
		t.Errorf("bad format: %s", c.Format)
	}
}

func TestBuilderPrepare_VNCBindAddress(t *testing.T) {
	var c Config
	config := testConfig()

	// Test a default boot_wait
	delete(config, "vnc_bind_address")
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	if c.VNCBindAddress != "127.0.0.1" {
		t.Fatalf("bad value: %s", c.VNCBindAddress)
	}
}

func TestBuilderPrepare_DiskCompaction(t *testing.T) {
	var c Config
	config := testConfig()

	// Bad
	config["skip_compaction"] = false
	config["disk_compression"] = true
	config["format"] = "img"
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}
	if c.SkipCompaction != true {
		t.Fatalf("SkipCompaction should be true")
	}
	if c.DiskCompression != false {
		t.Fatalf("DiskCompression should be false")
	}

	// Good
	config["skip_compaction"] = false
	config["disk_compression"] = true
	config["format"] = "qcow2"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
	if c.SkipCompaction != false {
		t.Fatalf("SkipCompaction should be false")
	}
	if c.DiskCompression != true {
		t.Fatalf("DiskCompression should be true")
	}
}

func TestBuilderPrepare_DiskSize(t *testing.T) {
	type testcase struct {
		InputSize   string
		OutputSize  string
		ErrExpected bool
	}

	testCases := []testcase{
		{"", "40960M", false},       // not provided
		{"12345", "12345M", false},  // no unit given, defaults to M
		{"12345x", "12345x", true},  // invalid unit
		{"12345T", "12345T", false}, // terabytes
		{"12345b", "12345b", false}, // bytes get preserved when set.
		{"60000M", "60000M", false}, // Original test case
	}
	for _, tc := range testCases {
		// Set input disk size
		var c Config
		config := testConfig()
		delete(config, "disk_size")
		config["disk_size"] = tc.InputSize

		warns, err := c.Prepare(config)
		if len(warns) > 0 {
			t.Fatalf("bad: %#v", warns)
		}
		if (err == nil) == tc.ErrExpected {
			t.Fatalf("bad: error when providing disk size %s; Err expected: %t; err recieved: %v", tc.InputSize, tc.ErrExpected, err)
		}

		if c.DiskSize != tc.OutputSize {
			t.Fatalf("bad size: received: %s but expected %s", c.DiskSize, tc.OutputSize)
		}
	}
}

func TestBuilderPrepare_AdditionalDiskSize(t *testing.T) {
	var c Config
	config := testConfig()

	config["disk_additional_size"] = []string{"1M"}
	config["disk_image"] = true
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error")
	}

	delete(config, "disk_image")
	config["disk_additional_size"] = []string{"1M"}
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	if c.AdditionalDiskSize[0] != "1M" {
		t.Fatalf("bad size: %s", c.AdditionalDiskSize)
	}
}

func TestBuilderPrepare_Format(t *testing.T) {
	var c Config
	config := testConfig()

	// Bad
	config["format"] = "illegal value"
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Good
	config["format"] = "qcow2"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	// Good
	config["format"] = "raw"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
}

func TestBuilderPrepare_UseBackingFile(t *testing.T) {
	var c Config
	config := testConfig()

	config["use_backing_file"] = true

	// Bad: iso_url is not a disk_image
	config["disk_image"] = false
	config["format"] = "qcow2"
	c = Config{}
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Bad: format is not 'qcow2'
	config["disk_image"] = true
	config["format"] = "raw"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Good: iso_url is a disk image and format is 'qcow2'
	config["disk_image"] = true
	config["format"] = "qcow2"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
}

func TestBuilderPrepare_SkipResizeDisk(t *testing.T) {
	config := testConfig()
	config["skip_resize_disk"] = true
	config["disk_image"] = false

	var c Config
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Errorf("unexpected warns when calling prepare with skip_resize_disk set to true: %#v", warns)
	}
	if err == nil {
		t.Errorf("setting skip_resize_disk to true when disk_image is false should have error")
	}
}

func TestBuilderPrepare_FloppyFiles(t *testing.T) {
	var c Config
	config := testConfig()

	delete(config, "floppy_files")
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("bad err: %s", err)
	}

	if len(c.FloppyFiles) != 0 {
		t.Fatalf("bad: %#v", c.FloppyFiles)
	}

	floppies_path := "../../packer-plugin-sdk/test-fixtures/floppies"
	config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	expected := []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
	if !reflect.DeepEqual(c.FloppyFiles, expected) {
		t.Fatalf("bad: %#v", c.FloppyFiles)
	}
}

func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
	var c Config
	config := testConfig()
	config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
	c = Config{}
	_, errs := c.Prepare(config)
	if errs == nil {
		t.Fatalf("Nonexistent floppies should trigger multierror")
	}

	if len(errs.(*packersdk.MultiError).Errors) != 2 {
		t.Fatalf("Multierror should work and report 2 errors")
	}
}

func TestBuilderPrepare_InvalidKey(t *testing.T) {
	var c Config
	config := testConfig()

	// Add a random key
	config["i_should_not_be_valid"] = true
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}
}

func TestBuilderPrepare_OutputDir(t *testing.T) {
	var c Config
	config := testConfig()

	// Test with existing dir
	dir, err := ioutil.TempDir("", "packer")
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	defer os.RemoveAll(dir)

	config["output_directory"] = dir
	c = Config{}
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Test with a good one
	config["output_directory"] = "i-hope-i-dont-exist"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
}

func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
	var c Config
	config := testConfig()

	// Test with a bad value
	config["shutdown_timeout"] = "this is not good"
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Test with a good one
	config["shutdown_timeout"] = "5s"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
}

func TestBuilderPrepare_SSHHostPort(t *testing.T) {
	var c Config
	config := testConfig()

	// Bad
	config["host_port_min"] = 1000
	config["host_port_max"] = 500
	c = Config{}
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Bad
	config["host_port_min"] = -500
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Good
	config["host_port_min"] = 500
	config["host_port_max"] = 1000
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
}

func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
	var c Config
	config := testConfig()

	config["ssh_private_key_file"] = ""
	c = Config{}
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	config["ssh_private_key_file"] = "/i/dont/exist"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Test bad contents
	tf, err := ioutil.TempFile("", "packer")
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	defer os.Remove(tf.Name())
	defer tf.Close()

	if _, err := tf.Write([]byte("HELLO!")); err != nil {
		t.Fatalf("err: %s", err)
	}

	config["ssh_private_key_file"] = tf.Name()
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Test good contents
	if _, err := tf.Seek(0, 0); err != nil {
		t.Fatalf("errorf getting key")
	}
	if err := tf.Truncate(0); err != nil {
		t.Fatalf("errorf getting key")
	}
	if _, err := tf.Write([]byte(testPem)); err != nil {
		t.Fatalf("errorf getting key")
	}
	config["ssh_private_key_file"] = tf.Name()
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("err: %s", err)
	}
}

func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
	var c Config
	config := testConfig()

	// Test a default boot_wait
	delete(config, "ssh_timeout")
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	// Test with a bad value
	config["ssh_timeout"] = "this is not good"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err == nil {
		t.Fatal("should have error")
	}

	// Test with a good one
	config["ssh_timeout"] = "5s"
	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
}

func TestBuilderPrepare_QemuArgs(t *testing.T) {
	var c Config
	config := testConfig()

	// Test with empty
	delete(config, "qemuargs")
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	if !reflect.DeepEqual(c.QemuArgs, [][]string{}) {
		t.Fatalf("bad: %#v", c.QemuArgs)
	}

	// Test with a good one
	config["qemuargs"] = [][]interface{}{
		{"foo", "bar", "baz"},
	}

	c = Config{}
	warns, err = c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	expected := [][]string{
		{"foo", "bar", "baz"},
	}

	if !reflect.DeepEqual(c.QemuArgs, expected) {
		t.Fatalf("bad: %#v", c.QemuArgs)
	}
}

func TestBuilderPrepare_VNCPassword(t *testing.T) {
	var c Config
	config := testConfig()
	config["vnc_use_password"] = true
	config["output_directory"] = "not-a-real-directory"

	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	expected := filepath.Join("not-a-real-directory", "packer-foo.monitor")
	if !reflect.DeepEqual(c.QMPSocketPath, expected) {
		t.Fatalf("Bad QMP socket Path: %s", c.QMPSocketPath)
	}
}

func TestCommConfigPrepare_BackwardsCompatibility(t *testing.T) {
	var c Config
	config := testConfig()
	hostPortMin := 1234
	hostPortMax := 4321
	sshTimeout := 2 * time.Minute

	config["ssh_wait_timeout"] = sshTimeout
	config["ssh_host_port_min"] = hostPortMin
	config["ssh_host_port_max"] = hostPortMax

	warns, err := c.Prepare(config)
	if len(warns) == 0 {
		t.Fatalf("should have deprecation warn")
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}

	if c.CommConfig.Comm.SSHTimeout != sshTimeout {
		t.Fatalf("SSHTimeout should be %s for backwards compatibility, but it was %s", sshTimeout.String(), c.CommConfig.Comm.SSHTimeout.String())
	}

	if c.CommConfig.HostPortMin != hostPortMin {
		t.Fatalf("HostPortMin should be %d for backwards compatibility, but it was %d", hostPortMin, c.CommConfig.HostPortMin)
	}

	if c.CommConfig.HostPortMax != hostPortMax {
		t.Fatalf("HostPortMax should be %d for backwards compatibility, but it was %d", hostPortMax, c.CommConfig.HostPortMax)
	}
}

func TestBuilderPrepare_LoadQemuImgArgs(t *testing.T) {
	var c Config
	config := testConfig()
	config["qemu_img_args"] = map[string][]string{
		"convert": []string{"-o", "preallocation=full"},
		"resize":  []string{"-foo", "bar"},
		"create":  []string{"-baz", "bang"},
	}
	warns, err := c.Prepare(config)
	if len(warns) > 0 {
		t.Fatalf("bad: %#v", warns)
	}
	if err != nil {
		t.Fatalf("should not have error: %s", err)
	}
	assert.Equal(t, []string{"-o", "preallocation=full"},
		c.QemuImgArgs.Convert, "Convert args not loaded properly")
	assert.Equal(t, []string{"-foo", "bar"},
		c.QemuImgArgs.Resize, "Resize args not loaded properly")
	assert.Equal(t, []string{"-baz", "bang"},
		c.QemuImgArgs.Create, "Create args not loaded properly")
}