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

Implement post_create_command #96

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thheinen
Copy link
Collaborator

@thheinen thheinen commented Jul 7, 2020

Description

In some cases, remote machines need to get brought into a certain condition before Kitchen can even connect to them. A strong use case might be opening firewalls for WinRM connections:

Customers should use production-grade images in Test Kitchen to achieve Dev/Prod Parity, so changing the firewall in the template is not desired. On the other hand, Kitchen cannot connect before the firewall allows it. By using the VMware Tools Guest Operations API (just as with the Active IP Discovery already present in the driver), such modifications can be made even before network connections are attached.

The solution would also offer the possibility to assign static IPs etc with some scripting. It creates a list of scripts to run, so future features can queue commands as well.

Additionally in this PR:

  • use the credentials from the SSH/WinRM transport to connect to VMware Tools by default, can be overridden as before.
    This makes the feature easier to use, as the credentials for both are likely identical.
  • switched benchmark_* methods to use guards instead of littering if around.
    In the mid-term, this driver will need a plugin system to not include too many exotic features and make it testable. That's why I started cleaning the main control flow to be linear and pulled the logic into guards. I will open an issue for the discussion of plugins later.

Issues Resolved

Issue #69 is kind of relevant, but setting hostname/IP is better done with Guest customization. This PR would offer a way to automate it before that feature lands, though.

Check List

Signed-off-by: Thomas Heinen <[email protected]>
@thheinen thheinen requested a review from a team as a code owner July 7, 2020 14:32
@thheinen thheinen added the Triage: Feature Request Indicates an issue requesting new functionality. label Jul 7, 2020
README.md Outdated Show resolved Hide resolved
Signed-off-by: Thomas Heinen <[email protected]>

Co-authored-by: Tim Smith <[email protected]>
@thheinen
Copy link
Collaborator Author

Small reminder for this PR :)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Signed-off-by: Thomas Heinen <[email protected]>

Co-authored-by: Kimberly Garmoe <[email protected]>
@thheinen thheinen requested review from a team as code owners July 17, 2020 09:47
@thheinen
Copy link
Collaborator Author

Thank you Kimberly - that's much more readable now 👍

@thheinen thheinen requested review from kagarmoe and removed request for a team July 20, 2020 14:43
@kagarmoe kagarmoe requested a review from tas50 August 12, 2020 01:50
@thheinen
Copy link
Collaborator Author

I'd like to ping again. The unsuccessful check is a pipeline-internal failure actually.

This feature is the base for a follow-on PR which includes some support for static IPs without time-intensive customization and includes more flexible scripting options. It's been pending for several weeks now.

@clintoncwolfe clintoncwolfe self-requested a review August 17, 2020 15:53
Comment on lines -58 to +59
default_config :vm_username, "vagrant"
default_config :vm_password, "vagrant"
default_config :vm_username, nil
default_config :vm_password, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a breaking change for some people - to drop the default value of "vagrant". I'd prefer to keep the value if possible.


def kitchen
require "binding_of_caller"
binding.callers.find { |b| b.frame_description == "create" && b.receiver.class == Kitchen::Instance }.receiver
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a TODO comment and reference test-kitchen/test-kitchen#1674

Kitchen.logger.debug format("Script execution: %s", script)

tools = Support::GuestOperations.new(vim, vm, guest_auth, ssl_verify)
output = tools.run_shell_capture_output(script, :auto, timeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm, when I run this with a Windows 2016 template with VMWare tools installed, this fails at this point because it fails to write a temporary file:

-----> Creating <default-windows-2016>...
       Assigning network VM Network...
       Cloning 'Templates/windows2016-template' to create the VM...
       Waiting for VMware tools to become available (timeout: 90 seconds)...
       Running post create script 'kitchen.yml'
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #create action: [FileNotFound: File C:\Windows\TEMP\vm_utils_run_out_0.2658098154379308 was not found] on default-windows-2016
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

My Kitchenfile:

driver:
  name: vcenter
  vcenter_username: (...)
  vcenter_password: (...)
  vcenter_host:  (...)

platforms:
  - name: windows-2016
    driver:
      targethost: (...)
      network_name: VM Network
      folder: cwolfe
      clone_type: full
      vm_wait_timeout: 180
      datacenter: (...)
      template: Templates/windows2016-template
      post_create_script: |
        netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile="Public" new remoteip="any"
    transport:
      username: vagrant
      password: vagrant

suites:
  - name: default

provisioner:
  name: chef_zero

verifier:
  name: inspec

C:\Windows\Temp\ exists. Any advice?

@kagarmoe kagarmoe added the Status: Waiting on Contributor A pull request that has unresolved requested actions from the author. label Jun 15, 2021
@kagarmoe
Copy link

Closing because of staleness. We can reopen if we hear from @tecracer-theinen .

@kagarmoe kagarmoe closed this Jun 17, 2021
@tas50 tas50 reopened this Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting on Contributor A pull request that has unresolved requested actions from the author. Triage: Feature Request Indicates an issue requesting new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants