0

I'm working through some of the basic Chef tutorials, and trying to get my test kitchen set up for my cookbook using vagrant hosted on my local machine. I know that I need to port-forward my RDP connection to this box from port 3389 to 33389. Based on this documentation, it looks as if I can specify the rdp port that I reach out to when I kitchen login by adding rdp_port: 33389 to my transport settings.

Therefore, I set up my kitchen.yml file like this:

---
driver:
  name: vagrant
  network:
    - ["private_network", {ip: "192.168.35.35"}]
    - [ "forwarded_port", {guest: 3389, host: 33389}]

provisioner:
  name: chef_zero

verifier:
  name: inspec

platforms:
  - name: windows_2012_r2

transport:
  name: winrm
  rdp_port: 33389
  elevated: true


suites:
  - name: default
    run_list:
      - recipe[test_kitchen_rdp_issues::default]
    verifier:
      inspec_tests:
        - test/recipes
    attributes:

After running kitchen create, followed by kitchen login, I'm provided with the following error from remote desktop connection:

Your computer could not connect to another console session on the remote computer because you already have a console session in progress

When I kitchen diagnose, I can see the following output:

    ---
timestamp: 2016-09-21 22:40:12 UTC
kitchen_version: 1.11.1
instances:
  default-windows-2012-r2:
    platform:
      os_type: windows
      shell_type: powershell
    state_file:
      hostname: 127.0.0.1
      last_action: create
      password: vagrant
      port: '55985'
      rdp_port: '3389'
      username: vagrant
    driver:
      boot_timeout:
      box: windows_2012_r2
      box_check_update:
      box_download_insecure:
      box_url:
      box_version:
      customize: {}
      gui:
      kitchen_root: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues
      linked_clone:
      log_level: :info
      name: vagrant
      network:
      - - private_network
        - ip: 192.168.35.35
      - - forwarded_port
        - guest: 3389
          host: 33389
      pre_create_command:
      provider: virtualbox
      provision: false
      ssh: {}
      synced_folders: []
      test_base_path: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues/test/integration
      vagrant_binary: vagrant
      vagrantfile_erb: C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/kitchen-vagrant-0.20.0/templates/Vagrantfile.erb
      vagrantfiles: []
      vm_hostname:
    provisioner:
      attributes: {}
      chef_client_path: "\\bin\\chef-client.bat"
      chef_omnibus_install_options:
      chef_omnibus_url: https://omnitruck.chef.io/install.sh
      chef_zero_host:
      chef_zero_port: 8889
      client_rb: {}
      clients_path:
      command_prefix:
      config_path:
      cookbook_files_glob: README.*,metadata.{json,rb},attributes/**/*,definitions/**/*,files/**/*,libraries/**/*,providers/**/*,recipes/**/*,resources/**/*,templates/**/*
      data_bags_path:
      data_path:
      encrypted_data_bag_secret_key_path:
      environments_path:
      ftp_proxy:
      http_proxy:
      https_proxy:
      json_attributes: true
      kitchen_root: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues
      log_file:
      log_level: auto
      max_retries: 1
      name: chef_zero
      named_run_list: {}
      nodes_path:
      policyfile:
      policyfile_path:
      profile_ruby: false
      require_chef_omnibus: true
      retry_on_exit_code: []
      roles_path:
      root_path: "$env:TEMP\\kitchen"
      ruby_bindir: "\\embedded\\bin"
      run_list:
      - recipe[test_kitchen_rdp_issues::default]
      sudo:
      sudo_command:
      test_base_path: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues/test/integration
      wait_for_retry: 30
    transport:
      connection_retries: 5
      connection_retry_sleep: 1
      elevated: true
      endpoint_template: http://%{hostname}:%{port}/wsman
      kitchen_root: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues
      log_level: :info
      max_wait_until_ready: 600
      name: winrm
      password:
      port: 5985
      rdp_port: 33389
      test_base_path: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues/test/integration
      username: administrator
      winrm_transport: :negotiate
    verifier:
      chef_omnibus_root: "/opt/chef"
      command_prefix:
      ftp_proxy:
      http_proxy:
      https_proxy:
      inspec_tests:
      - test/recipes
      kitchen_root: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues
      log_level: :info
      name: inspec
      root_path: "$env:TEMP\\verifier"
      sudo:
      sudo_command:
      suite_name: default
      test_base_path: C:/Users/dev/learn-chef/cookbooks/test_kitchen_rdp_issues/test/recipes

Notice that, while the transport settings list the rdp_port correctly as 33389, the state_file settings still list the rdp_port as 3389, seemingly ignoring the port forwarding. Manually changing the state file (at .kitchen/default-windows-2012-r2.yml) to set rdp_port to 33389 there fixes my problem, and I am able to log in via kitchen login just fine.

Does transport::rdp_port work as expected? I'd like to be able to set up my kitchen.yml file in such a way that I can just perform a kitchen login without having to manually edit the generated files that come with kitchen create.

Edit: misread "state_file" as "static_file"

kjb4
  • 141
  • 1
  • 6
  • Your kitchen version is a few revs out of date. Have you tried with the current ChefDK release? – coderanger Sep 21 '16 at 23:24
  • Or, more importantly than the kitchen version is the driver version. Specifically do you see a `performing legacy action` warning at any point? – coderanger Sep 21 '16 at 23:25

1 Answers1

0

From looking through the TK source code, it looks like it generates the RDP URL that is handed to rdesktop using the VMs IP/hostname, not the machine running kitchen. This would mean Vagrant port maps have no effect.

coderanger
  • 52,400
  • 4
  • 52
  • 75