delete qmp socket path. Also, clean up unnecessary use of statebag to recieve step values. (#8572)
This commit is contained in:
parent
bb71db6b39
commit
be97507088
|
@ -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{},
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue