miscellaneous qemu cleanup. Fix generator strings; generate code

fix diskimage logic
linting
fix tests
This commit is contained in:
Megan Marsh 2020-09-15 16:42:08 -07:00
parent 3577c4a283
commit 83ee4e7d13
8 changed files with 22 additions and 14 deletions

View File

@ -1,6 +1,3 @@
//go:generate struct-markdown
//go:generate mapstructure-to-hcl2 -type Config
package qemu package qemu
import ( import (

View File

@ -1,3 +1,6 @@
//go:generate struct-markdown
//go:generate mapstructure-to-hcl2 -type Config
package qemu package qemu
import ( import (

View File

@ -519,9 +519,15 @@ func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
} }
// Test good contents // Test good contents
tf.Seek(0, 0) if _, err := tf.Seek(0, 0); err != nil {
tf.Truncate(0) t.Fatalf("errorf getting key")
tf.Write([]byte(testPem)) }
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() config["ssh_private_key_file"] = tf.Name()
c = Config{} c = Config{}
warns, err = c.Prepare(config) warns, err = c.Prepare(config)

View File

@ -35,7 +35,7 @@ func (s *stepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
// installation CD or a pre-baked image // installation CD or a pre-baked image
bootDrive := "once=d" bootDrive := "once=d"
message := "Starting VM, booting from CD-ROM" message := "Starting VM, booting from CD-ROM"
if !s.DiskImage { if s.DiskImage {
bootDrive = "c" bootDrive = "c"
message = "Starting VM, booting disk image" message = "Starting VM, booting disk image"
} }

View File

@ -76,9 +76,11 @@ func Test_CDFilesPath(t *testing.T) {
"-machine", "type=,accel=", "-machine", "type=,accel=",
"-device", ",netdev=user.0", "-device", ",netdev=user.0",
"-drive", "file=/path/to/test.iso,index=0,media=cdrom", "-drive", "file=/path/to/test.iso,index=0,media=cdrom",
"-drive", "file=fake_cd_path.iso,index=1,media=cdrom ", "-drive", "file=fake_cd_path.iso,index=1,media=cdrom",
} }
assert.ElementsMatch(t, args, expected, fmt.Sprintf("unexpected generated args: %#v", args))
// cd_path is set and DiskImage is true // cd_path is set and DiskImage is true
config := &Config{ config := &Config{
DiskImage: true, DiskImage: true,

View File

@ -21,15 +21,15 @@ import (
type stepWaitGuestAddress struct { type stepWaitGuestAddress struct {
CommunicatorType string CommunicatorType string
NetBridge string NetBridge string
timeout time.Duration
timeout time.Duration
} }
func (s *stepWaitGuestAddress) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepWaitGuestAddress) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.CommunicatorType == "none" { if s.CommunicatorType == "none" {
ui.Message("Not using a communicator -- skipping StepWaitGuestAddress") ui.Message("No communicator is configured -- skipping StepWaitGuestAddress")
return multistep.ActionContinue return multistep.ActionContinue
} }
if s.NetBridge == "" { if s.NetBridge == "" {
@ -41,9 +41,9 @@ func (s *stepWaitGuestAddress) Run(ctx context.Context, state multistep.StateBag
ctx, cancel := context.WithTimeout(ctx, s.timeout) ctx, cancel := context.WithTimeout(ctx, s.timeout)
defer cancel() defer cancel()
ui.Say(fmt.Sprintf("Waiting for the guest address to become available in the %s network bridge...", config.NetBridge)) ui.Say(fmt.Sprintf("Waiting for the guest address to become available in the %s network bridge...", s.NetBridge))
for { for {
guestAddress := getGuestAddress(qmpMonitor, config.NetBridge, "user.0") guestAddress := getGuestAddress(qmpMonitor, s.NetBridge, "user.0")
if guestAddress != "" { if guestAddress != "" {
log.Printf("Found guest address %s", guestAddress) log.Printf("Found guest address %s", guestAddress)
state.Put("guestAddress", guestAddress) state.Put("guestAddress", guestAddress)

View File

@ -1,4 +1,4 @@
<!-- Code generated from the comments of the Config struct in builder/qemu/builder.go; DO NOT EDIT MANUALLY --> <!-- Code generated from the comments of the Config struct in builder/qemu/config.go; DO NOT EDIT MANUALLY -->
- `iso_skip_cache` (bool) - Use iso from provided url. Qemu must support - `iso_skip_cache` (bool) - Use iso from provided url. Qemu must support
curl block device. This defaults to `false`. curl block device. This defaults to `false`.