test-kitchen / kitchen-vagrant

A Test Kitchen Driver for Vagrant
Other
348 stars 189 forks source link

Specifying custom SSH port does not work #411

Open walterdolce opened 4 years ago

walterdolce commented 4 years ago

Probably relates to test-kitchen/test-kitchen#1159

I have the following scenario at play:

How can I tell kitchen-vagrant to connect to the VM via port 444?

So far I have tried using the following, either in combination or in isolation, but none of them have worked:

# .kitchen.yml
driver:
  name: vagrant
  communicator: ssh  # whether or not I specify this, it makes no difference
  network:
    - ["forwarded_port", {guest: 444, host: 444, auto_correct: true}]

# Does not really matter how I define the below, it never works
platforms:
  - name: ubuntu-16.04
    transport:
      name: ssh
      port: 444
    driver:
      port: 444
    driver_config:
      port: 444

I would expect that if I modify the port settings of the driver, instead of seeing the following:

       ==> default: Forwarding ports...
           default: 444 (guest) => 444 (host) (adapter 1)
           default: 22 (guest) => 2222 (host) (adapter 1)
       ==> default: Running 'pre-boot' VM customizations...
       ==> default: Booting VM...
       ==> default: Waiting for machine to boot. This may take a few minutes...
           default: SSH address: 127.0.0.1:2222

I would see the following:

       ==> default: Waiting for machine to boot. This may take a few minutes...
           default: SSH address: 127.0.0.1:444

But that doesn't happen. It's probably also worth mentioning that the automatically generated "test-kitchen state" (I think it's called..) remains the same all the time:

# .kitchen/default-ubuntu-1604.yml
---
hostname: 127.0.0.1
port: '2222'
username: vagrant
ssh_key: "/path/to/project/.kitchen/kitchen-vagrant/default-ubuntu-1604/.vagrant/machines/default/virtualbox/private_key"
last_action: create
last_error: 

But I would expect to see port: 444. That doesn't happen either.

What am I missing?

Thanks!

walterdolce commented 4 years ago

In order to overcome the above, I had to do the following, which less than ideal 😅 :

# kitchen.yml
---
lifecycle:
  pre_converge:
    - local: |
        sed -i '' "s/port: '.*'/port: '4443'/g" .kitchen/${KITCHEN_INSTANCE_NAME}.yml

driver:
  name: vagrant
  network:
    - ["forwarded_port", {guest: 444, host: 444, auto_correct: true}]