test-kitchen / kitchen-vagrant

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

Unable to configure network with Vagrant/VirtualBox #459

Closed stblassitude closed 2 years ago

stblassitude commented 2 years ago

:speaking_head: Foreword

Thank for taking the time to fill this bug report fully. Without it we may not be able to fix the bug, and the issue may be closed without resolution.

:ghost: Brief Description

When trying to configure a VB/Vagrant with a custom network, Vagrant reports an error.

Version

1.9.0

Environment

$ ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
$ bundle version
Bundler version 1.17.2 (2018-12-19 commit 3fc4de72b)
$ vagrant --version
Vagrant 2.2.17
$ bundle exec kitchen version
Test Kitchen version 3.0.0
$ bundle list                                                
Gems included by the bundle:
  * bcrypt_pbkdf (1.1.0)
  * builder (3.2.4)
  * bundler (1.17.2)
  * chef-utils (17.2.29)
  * concurrent-ruby (1.1.9)
  * ed25519 (1.2.4)
  * erubi (1.10.0)
  * facter (2.5.7)
  * faraday (0.17.4)
  * faraday_middleware (0.14.0)
  * fast_gettext (1.1.2)
  * ffi (1.15.3)
  * gettext (3.2.9)
  * gettext-setup (0.34)
  * gssapi (1.3.1)
  * gyoku (1.3.1)
  * hiera (3.7.0)
  * httpclient (2.8.3)
  * json_pure (1.8.6)
  * kitchen-puppet (3.5.2)
  * kitchen-vagrant (1.9.0)
  * librarian-puppet (3.0.1)
  * librarianp (1.0.0)
  * license-acceptance (2.1.13)
  * little-plugger (1.1.4)
  * locale (2.1.3)
  * logging (2.3.0)
  * minitar (0.9)
  * mixlib-install (3.12.11)
  * mixlib-shellout (3.2.5)
  * mixlib-versioning (1.2.12)
  * multi_json (1.15.0)
  * multipart-post (2.1.1)
  * net-scp (3.0.0)
  * net-ssh (6.1.0)
  * net-ssh-gateway (2.0.0)
  * nori (2.6.0)
  * pastel (0.8.0)
  * puppet (4.10.12)
  * puppet_forge (2.3.4)
  * rsync (1.0.9)
  * rubyntlm (0.6.3)
  * rubyzip (2.3.2)
  * semantic_puppet (1.0.4)
  * strings (0.2.1)
  * strings-ansi (0.2.0)
  * test-kitchen (3.0.0)
  * text (1.3.1)
  * thor (1.1.0)
  * tomlrb (2.0.1)
  * tty-box (0.7.0)
  * tty-color (0.6.0)
  * tty-cursor (0.7.1)
  * tty-prompt (0.23.1)
  * tty-reader (0.9.0)
  * tty-screen (0.8.1)
  * unicode-display_width (2.0.0)
  * unicode_utils (1.4.0)
  * winrm (2.3.6)
  * winrm-elevated (1.2.3)
  * winrm-fs (1.3.5)
  * wisper (2.0.1)

Scenario

Converge a box. The .kitchen.yml contains:

driver:
  name: vagrant
  network:
  #   - ["forwarded_port", {guest: 3000, host: 3000, auto_correct: true}]
    - ["private_network", {ip: "192.168.33.33"}]

Steps to Reproduce

$ bundle exec kitchen converge
-----> Starting Test Kitchen (v3.0.0)
-----> Creating <default-freebsd13>...
       /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/plugins/kernel_v2/config/vm.rb:319:in `network': wrong number of arguments (given 2, expected 1) (ArgumentError)

Expected Result

Box converges with custom network.

Actual Result

The generated Vagrantfile starts like this:

Vagrant.configure("2") do |c|
  c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  c.vm.box = "stblassitude/freebsd-13"
  c.vm.hostname = "porttest-13"
  c.vm.network(:private_network, {:ip=>"192.168.33.33"})
...

The network config should read

  c.vm.network :private_network, :ip=>"192.168.33.33"

Manually correcting the Vagrantfile and running vagrant up in .kitchen/kitchen-vagrant/default-freebsd13 brings up the box.

:heavy_plus_sign: Additional context

Add any other context about the problem here. e.g. related issues or existing pull requests.

dbuenoparedes commented 2 years ago

I have the exact same issue, in my case I'm trying to converge a box using the libvirt provider but seems that the syntax of the Vagrantfile is wrong.

I've also tried with kitchen-vagrant v1.7.0 getting the same result.

The (same) error I'm getting:

-----> Starting Test Kitchen (v2.7.2)
-----> Creating <default-server>...
       /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/plugins/kernel_v2/config/vm.rb:319:in `network': wrong number of arguments (given 2, expected 1) (ArgumentError)
        from /home/dbuenoparedes/git-repos/infra-chef/cookbooks/fuze_proxmox/.kitchen/kitchen-vagrant/default-server/Vagrantfile:5:in `block in <top (required)>'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/v2/loader.rb:37:in `load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:126:in `block (2 levels) in load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:119:in `each'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:119:in `block in load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:116:in `each'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:116:in `load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/vagrantfile.rb:29:in `initialize'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:793:in `new'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:793:in `vagrantfile'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:974:in `process_configured_plugins'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:178:in `initialize'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/bin/vagrant:194:in `new'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/bin/vagrant:194:in `<main>'
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #create action: [Expected process to exit with [0], but received '1'
---- Begin output of vagrant up --no-provision --provider libvirt ----
STDOUT: 
STDERR: /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/plugins/kernel_v2/config/vm.rb:319:in `network': wrong number of arguments (given 2, expected 1) (ArgumentError)
        from /home/dbuenoparedes/git-repos/infra-chef/cookbooks/fuze_proxmox/.kitchen/kitchen-vagrant/default-server/Vagrantfile:5:in `block in <top (required)>'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/v2/loader.rb:37:in `load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:126:in `block (2 levels) in load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:119:in `each'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:119:in `block in load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:116:in `each'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/config/loader.rb:116:in `load'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/vagrantfile.rb:29:in `initialize'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:793:in `new'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:793:in `vagrantfile'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:974:in `process_configured_plugins'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/lib/vagrant/environment.rb:178:in `initialize'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/bin/vagrant:194:in `new'
        from /opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/bin/vagrant:194:in `<main>'
---- End output of vagrant up --no-provision --provider libvirt ----
Ran vagrant up --no-provision --provider libvirt returned 1] on default-server
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

My env:

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
$ bundle version
Bundler version 2.1.4 (2021-07-16 commit unknown)
$ vagrant --version
Vagrant 2.2.17
gem list --local | grep test-kitchen
test-kitchen (2.7.2)
$ gem list --local | grep vagrant
kitchen-vagrant (1.9.0, 1.7.0)

My kitchen.yml config:

    driver:
      name: vagrant
      provider: libvirt
      customize:
        cpus: 2
        memory: 2048
      network:
        - ["private_network", {libvirt__network_name: "vagrant-libvirt"}]

The resulting Vagrantfile config looks like:

Vagrant.configure("2") do |c|
  c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  c.vm.network(:private_network, {:libvirt__network_name=>"vagrant-libvirt"})
  c.vm.synced_folder ".", "/vagrant", disabled: true
  c.vm.provider :libvirt do |p|
    p.cpus = 2
    p.memory = 2048
  end
end

Whereas if I manually fix it to look like the following it works:

  c.vm.network :private_network, :libvirt__network_name=>"vagrant-libvirt"
stblassitude commented 2 years ago

I've installed ruby 2.7.2 via rvm, but still get the same error.

stblassitude commented 2 years ago

Downgrading to vagrant 2.2.16 fixes it for me. I still believe the syntax currently used is undocumented and should be updated to the correct, documented syntax.

dbuenoparedes commented 2 years ago

Neat, I knew it was working for me before but wasn't sure what changed, now we know it's a Vagrant version update what changed this behavior...

caryp commented 2 years ago

Same problem here

tas50 commented 2 years ago

Hashi is going to back out the Ruby 3 bump in Vagrant that caused this: https://github.com/hashicorp/vagrant/issues/12448

I'd advise downgrading until then.

Leletir commented 2 years ago

Hello,

I still have the problem with vagrant 2.2.19, downgrading to 2.2.16 worked.

pkelly-mitre commented 4 days ago

I am also still getting the same error with vagrant 2.4.1 and Test kitchen version 3.0.0

Stromweld commented 4 days ago

@pkelly-mitre can you try latest version of vagrant(2.4.1), test-kitchen(3.6.0), and kitchen-vagrant(2.0.1)?