Merge pull request #4305 from mitchellh/replace4247
builder/virtualbox: group keyboard codes
This commit is contained in:
commit
308a01795c
|
@ -65,7 +65,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, code := range scancodes(command) {
|
for _, code := range gathercodes(scancodes(command)) {
|
||||||
if code == "wait" {
|
if code == "wait" {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
|
@ -91,7 +91,9 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
pauseFn(multistep.DebugLocationAfterRun, fmt.Sprintf("boot_command[%d]: %s", i, command), state)
|
pauseFn(multistep.DebugLocationAfterRun, fmt.Sprintf("boot_command[%d]: %s", i, command), state)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := driver.VBoxManage("controlvm", vmName, "keyboardputscancode", code); err != nil {
|
args := []string{"controlvm", vmName, "keyboardputscancode"}
|
||||||
|
args = append(args, strings.Split(code, " ")...)
|
||||||
|
if err := driver.VBoxManage(args...); err != nil {
|
||||||
err := fmt.Errorf("Error sending boot command: %s", err)
|
err := fmt.Errorf("Error sending boot command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -105,6 +107,27 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
|
|
||||||
func (*StepTypeBootCommand) Cleanup(multistep.StateBag) {}
|
func (*StepTypeBootCommand) Cleanup(multistep.StateBag) {}
|
||||||
|
|
||||||
|
// Gather scancodes to send to console efficiently.
|
||||||
|
func gathercodes(codes []string) (gathered []string) {
|
||||||
|
working := []string{}
|
||||||
|
pushWorking := func() {
|
||||||
|
if len(working) > 0 {
|
||||||
|
gathered = append(gathered, strings.Join(working, " "))
|
||||||
|
working = []string{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, code := range codes {
|
||||||
|
if strings.HasPrefix(code, "wait") {
|
||||||
|
pushWorking()
|
||||||
|
gathered = append(gathered, code)
|
||||||
|
} else {
|
||||||
|
working = append(working, code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pushWorking()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func scancodes(message string) []string {
|
func scancodes(message string) []string {
|
||||||
// Scancodes reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
// Scancodes reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
||||||
//
|
//
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStepTypeBootCommand_gather(t *testing.T) {
|
||||||
|
input := [][]string{
|
||||||
|
{"02", "82", "wait1", "03", "83"},
|
||||||
|
{"02", "82", "03", "83"},
|
||||||
|
{"wait5", "wait1", "wait10"},
|
||||||
|
{"wait5", "02", "82", "03", "83", "wait1", "wait10"},
|
||||||
|
{"wait1"},
|
||||||
|
{"01"},
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := [][]string{
|
||||||
|
{"02 82", "wait1", "03 83"},
|
||||||
|
{"02 82 03 83"},
|
||||||
|
{"wait5", "wait1", "wait10"},
|
||||||
|
{"wait5", "02 82 03 83", "wait1", "wait10"},
|
||||||
|
{"wait1"},
|
||||||
|
{"01"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, data := range input {
|
||||||
|
gathered := gathercodes(data)
|
||||||
|
if !reflect.DeepEqual(gathered, expected[i]) {
|
||||||
|
t.Fatalf("%#v did not equal expected %#v", gathered, expected[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue