Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boot command parser with PEG parser. #6129

Merged
merged 40 commits into from
Apr 20, 2018
Merged

Replace boot command parser with PEG parser. #6129

merged 40 commits into from
Apr 20, 2018

Conversation

mwhooker
Copy link
Contributor

@mwhooker mwhooker commented Apr 12, 2018

This PR replaces the custom boot command parser with a PEG parser (https://github.com/mna/pigeon). This should make sure our parsing logic is correct and is consistent across the builders.

Closes #6034
Closes #2855

blocks on hashicorp/middleman-hashicorp#58

Still need to

  • more testing
  • vmware
  • hyperv
  • parallels
  • virtualbox
  • qemu
  • run qemu build
  • run hyperv build
  • check docs are correct
  • check that the vbox key changes from VirtualBox fixes #6067 work on parallels and hyper-v
  • fix everything wrapped in <p> tags in the docs partial
  • only accept positive wait values. Do a parser validation check in Prepare().
  • move boot command/boot_wait to be a config. Prepare as above and utility method for joining to a string.
  • join every boot_command array before sending to the parser. Could be a minor speed improvement and would allow the pc-xt driver to decide for itself how many events to send at once. 3ef2a9db7a63767fe4a067b8df11173344d368f4
  • pass context through to driver SendKey and SendSpecial. These operations might take some time and best to be allowed to bail out if we're stopping. Probably okay if this doesn't get done.
  • move common/boot_command => common/bootcommand

@mwhooker
Copy link
Contributor Author

parallels done but it's very slow. May need to add the optimization I talk about in the comments

@mwhooker
Copy link
Contributor Author

#2855 talks about virtualbox not working when under heavy load because it sends one key to each invocation of vboxmanage. Updated code to group codes properly

@mwhooker
Copy link
Contributor Author

I think this is in a state where the checked off builders can start being tested. I'd like to solicit community help here, since i want to test a wide range of boot commands. I've been testing with the boxes on https://www.packer.io/community-tools.html#templates and they're working, but I don't think that's enough.

@mcandre, I would greatly appreciate your help testing this patch if you feel obliged. I know you've been doing a lot of work in this area.

@mwhooker
Copy link
Contributor Author

wondering if I can break any of this with unicode. The CharToggle expression might have some weird edge cases

Copy link
Collaborator

@rickard-von-essen rickard-von-essen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some basic testing with Bento and everything seems fine, but the VNC driver seems like 3x slower than the PC-XT driver?

I think there is room for improvement on speed. My gut feeling is that the Parallels builder was faster before this change.


/*
TODO:
* pc-at abstraction
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pc-xt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah missed this in a2cc17f, but since this is a todo comment I'll let it fall off when it gets done


func Test_parse(t *testing.T) {
in := "<wait><wait20><wait3s><wait4m2ns>"
in += "foo/bar > one 界"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

界 is it correct to handle UTF characters? To my knowledge there are no scan codes for non US character. All special character (such as the Swedish ÅÄÖ) are handled in a software key maps i.e. the OS translate the key code for the characters on that position on an US keyboard into the current used language (for the previous mentioned characters left curly bracket, double quote, and colon respectively).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is a good point. I don't know that actually sending a unicode key will work or make sense. I'm mostly doing this here to make sure I'm decoding utf8 correctly.


- `<waitXX>` - Add an arbitrary pause before sending any additional keys. The
format of `XX` is a possibly signed sequence of decimal numbers, each with
optional fraction and a unit suffix, such as `300ms`, `-1.5h` or `2h45m`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does <wait-1.5h> do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied and pasted this from the go docs and missed that. for sure we should only accept positive values.

that is started serving the directory specified by the `http_directory`
configuration parameter. If `http_directory` isn't specified, these will be
blank!
* `Name` - The name of the VM.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/*/-/

@mwhooker
Copy link
Contributor Author

mwhooker commented Apr 14, 2018

Some basic testing with Bento and everything seems fine, but the VNC driver seems like 3x slower than the PC-XT driver?

This is a limitation of the VNC client and I think was the behavior before this patch. It unfortunately sends one key event at a time, waiting up to keyInterval in between.

with patch:

2018/04/15 21:53:23 ui: ==> ubuntu-1604-vmware: Typing the boot command over VNC...
2018/04/15 21:54:58 packer: 2018/04/15 21:54:58 [INFO] Waiting for SSH, up to timeout: 20m0s

1m35s

without patch:

2018/04/15 21:57:11 ui: ==> ubuntu-1604-vmware: Typing the boot command over VNC...
2018/04/15 21:58:42 ui: ==> ubuntu-1604-vmware: Waiting for SSH to become available...

1m31s

so a little slower, and perhaps within the margin of error. I think one reason why is that the existing code does not wait keyInterval before sending the shift key, whereas this patch waits after every key press.

I think there is room for improvement on speed. My gut feeling is that the Parallels builder was faster before this change.

I ran the below config with and without this patch applied. I just used the logs so I only had 1-second accuracy. Packer with this patch applied took 1 second longer to go from Typing the boot command... to Waiting for SSH. I assume this is because I added the keyInterval wait to the pc-xt driver, since at least with virtualbox I was getting odd errors that made me think it hadn't processed the previous commands before new ones were sent.

I suppose one improvement that could be made is to join the boot command array into a single string. That way the driver can decide how many keys to send at one time. I already do this in the hyper-v builder.

 {
      "name": "{{ user `build_name` }}-parallels",
      "vm_name": "{{ user `build_name` }}-parallels",
      "boot_command": [
        "<enter><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
        "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
        "hostname={{ user `build_name` }}-vmware ",
        "fb=false debconf/fronten=d=noninteractive ",
        "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ",
        "initrd=/install/initrd.gz -- <enter>"
      ],
      "boot_wait": "5s",
...

@mwhooker mwhooker force-pushed the bc_replace branch 2 times, most recently from 6e92906 to e75a965 Compare April 18, 2018 20:25
@mwhooker mwhooker force-pushed the bc_replace branch 2 times, most recently from d3bf90a to 2ff3881 Compare April 18, 2018 23:31
@mwhooker mwhooker mentioned this pull request Apr 18, 2018
@mwhooker mwhooker force-pushed the bc_replace branch 4 times, most recently from 7a77ebd to 284de35 Compare April 19, 2018 00:58
@mwhooker
Copy link
Contributor Author

I think this is code complete. now just on to testing

@mwhooker
Copy link
Contributor Author

check that the vbox key changes from #6067 work on parallels and hyper-v

turns out this wasn't working. basically all the 2 byte scan codes weren't working for at least parallels and probably hyper-v

fixed in 7e9af82

@mwhooker mwhooker changed the title [WIP]Replace boot command parser with PEG parser. Replace boot command parser with PEG parser. Apr 20, 2018
@mwhooker mwhooker merged commit 024fac4 into master Apr 20, 2018
@mwhooker mwhooker deleted the bc_replace branch April 20, 2018 19:21
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants