QEMU: Remove QMPEnable and depend upon VNC password usage for QMP enablement.

This commit is contained in:
Jayson Cofell 2019-07-16 08:55:19 -06:00
parent 4b0a7b0af7
commit 7f5fd4851e
5 changed files with 46 additions and 81 deletions

View File

@ -117,7 +117,6 @@ type Config struct {
OutputDir string `mapstructure:"output_directory"`
QemuArgs [][]string `mapstructure:"qemuargs"`
QemuBinary string `mapstructure:"qemu_binary"`
QMPEnable bool `mapstructure:"qmp_enable"`
QMPSocketPath string `mapstructure:"qmp_socket_path"`
ShutdownCommand string `mapstructure:"shutdown_command"`
SSHHostPortMin int `mapstructure:"ssh_host_port_min"`
@ -358,11 +357,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max"))
}
if b.config.VNCUsePassword && !b.config.QMPEnable {
b.config.QMPEnable = true
}
if b.config.QMPEnable && b.config.QMPSocketPath == "" {
if b.config.VNCUsePassword && b.config.QMPSocketPath == "" {
socketName := fmt.Sprintf("%s.monitor", b.config.VMName)
b.config.QMPSocketPath = filepath.Join(b.config.OutputDir, socketName)
}

View File

@ -114,25 +114,6 @@ func TestBuilderPrepare_VNCBindAddress(t *testing.T) {
}
}
func TestBuilderPrepare_VNCPassword(t *testing.T) {
var b Builder
config := testConfig()
// Test a default boot_wait
config["vnc_use_password"] = true
warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil {
t.Fatalf("err: %s", err)
}
if !b.config.QMPEnable {
t.Fatalf("QMP should be enabled.")
}
}
func TestBuilderPrepare_DiskCompaction(t *testing.T) {
var b Builder
config := testConfig()
@ -619,12 +600,11 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
}
}
func TestBuilderPrepare_QMP(t *testing.T) {
func TestBuilderPrepare_VNCPassword(t *testing.T) {
var b Builder
config := testConfig()
// QMP Defaults
config["qmp_enable"] = true
config["vnc_use_password"] = true
config["output_directory"] = "not-a-real-directory"
b = Builder{}
warns, err := b.Prepare(config)

View File

@ -26,7 +26,7 @@ func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) mu
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)
if !config.QMPEnable {
if !config.VNCUsePassword {
return multistep.ActionContinue
}
@ -35,8 +35,6 @@ func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) mu
log.Print(msg)
// Only initialize and open QMP when we have a use for it.
// Handles cases where user may want the socket, but we don't
if config.VNCUsePassword {
// Open QMP socket
var err error
var cmd []byte
@ -77,7 +75,6 @@ func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) mu
// 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
//state.Put("qmp_monitor", QMPMonitor)
}
return multistep.ActionContinue
}

View File

@ -79,6 +79,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
vnc = fmt.Sprintf("%s:%d", vncIP, vncPort-5900)
} else {
vnc = fmt.Sprintf("%s:%d,password", vncIP, vncPort-5900)
defaultArgs["-qmp"] = fmt.Sprintf("unix:%s,server,nowait", config.QMPSocketPath)
}
defaultArgs["-name"] = vmName
@ -90,10 +91,6 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0")
}
if config.QMPEnable {
defaultArgs["-qmp"] = fmt.Sprintf("unix:%s,server,nowait", config.QMPSocketPath)
}
rawVersion, err := driver.Version()
if err != nil {
return nil, err

View File

@ -282,11 +282,7 @@ Linux server and have not enabled X11 forwarding (`ssh -X`).
switch/value pairs. Any value specified as an empty string is ignored. All
values after the switch are concatenated with no separator.
- `qmp_enable` (bool) - Enable QMP socket. Location is specified by
`qmp_socket_path`.
Defaults to false.
- `qmp_socket_path` (string) - QMP Socket Path when `qmp_enable` is true.
- `qmp_socket_path` (string) - QMP Socket Path when `vnc_use_password` is true.
Defaults to `output_directory`/`vm_name`.monitor.
~> **Warning:** The qemu command line allows extreme flexibility, so beware
@ -398,7 +394,7 @@ default port of `5985` or whatever value you have the service set to listen on.
default this is `5900` to `6000`. The minimum and maximum ports are inclusive.
- `vnc_use_password` (bool) - Whether or not to set a password on the VNC server.
This option automatically sets `qmp_enable` to true.
This option automatically enables the QMP socket. See `qmp_socket_path`.
Defaults to `false`.
## Boot Command