From be97507088ee174c4fbe2a0dab537e9433011e95 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 7 Jan 2020 02:18:01 -0800 Subject: [PATCH] delete qmp socket path. Also, clean up unnecessary use of statebag to recieve step values. (#8572) --- builder/qemu/builder.go | 5 ++++- builder/qemu/step_configure_qmp.go | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 7b97f7d8a..ec510fdd2 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -639,7 +639,10 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack steps = append(steps, new(stepConfigureVNC), steprun, - new(stepConfigureQMP), + &stepConfigureQMP{ + VNCUsePassword: b.config.VNCUsePassword, + QMPSocketPath: b.config.QMPSocketPath, + }, &stepTypeBootCommand{}, ) diff --git a/builder/qemu/step_configure_qmp.go b/builder/qemu/step_configure_qmp.go index fa988ad0b..a9f177893 100644 --- a/builder/qemu/step_configure_qmp.go +++ b/builder/qemu/step_configure_qmp.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "os" "time" "github.com/digitalocean/go-qemu/qmp" @@ -19,27 +20,26 @@ import ( // // Produces: type stepConfigureQMP struct { - monitor *qmp.SocketMonitor + monitor *qmp.SocketMonitor + VNCUsePassword bool + QMPSocketPath string } func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - config := state.Get("config").(*Config) ui := state.Get("ui").(packer.Ui) - if !config.VNCUsePassword { + if !s.VNCUsePassword { return multistep.ActionContinue } - msg := fmt.Sprintf("QMP socket at: %s", config.QMPSocketPath) - ui.Say(msg) - log.Print(msg) + ui.Say(fmt.Sprintf("QMP socket at: %s", s.QMPSocketPath)) // Only initialize and open QMP when we have a use for it. // Open QMP socket var err error var cmd []byte var result []byte - s.monitor, err = qmp.NewSocketMonitor("unix", config.QMPSocketPath, 2*time.Second) + s.monitor, err = qmp.NewSocketMonitor("unix", s.QMPSocketPath, 2*time.Second) if err != nil { err := fmt.Errorf("Error opening QMP socket: %s", err) state.Put("error", err) @@ -69,8 +69,8 @@ func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) mu ui.Error(err.Error()) return multistep.ActionHalt } - msg = fmt.Sprintf("QMP Command: %s\nResult: %s", cmd, result) - log.Printf(msg) + + log.Printf("QMP Command: %s\nResult: %s", cmd, result) // Put QMP monitor in statebag in case there is a use in a following step // Uncomment for future case as it is unused for now @@ -85,5 +85,9 @@ func (s *stepConfigureQMP) Cleanup(multistep.StateBag) { if err != nil { log.Printf("failed to disconnect QMP: %v", err) } + // Delete file associated with qmp socket. + if err := os.Remove(s.QMPSocketPath); err != nil { + log.Printf("Failed to delete the qmp socket file: %s", err) + } } }