From 680fd619030bd551a9ca505d2b1abc6f9064f59e Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Mon, 5 Feb 2024 17:40:14 -0600 Subject: [PATCH 1/7] add vagrant architecture support Signed-off-by: Corey Hemminger --- lib/kitchen/driver/vagrant.rb | 17 +++++++++++++---- templates/Vagrantfile.erb | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index e3dc9d8..2a04b37 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -56,6 +56,8 @@ class Vagrant < Kitchen::Driver::Base default_config :box_version, nil + default_config :box_arch, nil + default_config :boot_timeout, nil default_config :customize, {} @@ -125,7 +127,7 @@ def create(state) # @return [String,nil] the Vagrant box for this Instance def default_box if bento_box?(instance.platform.name) - "bento/#{instance.platform.name}#{"-arm64" if RbConfig::CONFIG["host_cpu"].eql?("arm64")}" + "bento/#{instance.platform.name}" else instance.platform.name end @@ -225,7 +227,7 @@ def cache_directory protected WEBSITE = "https://www.vagrantup.com/downloads.html".freeze - MIN_VER = "1.1.0".freeze + MIN_VER = "2.4.0".freeze class << self @@ -313,14 +315,21 @@ def finalize_ca_cert! def finalize_box_auto_update! return if config[:box_auto_update].nil? - config[:box_auto_update] = "vagrant box update #{"--insecure " if config[:box_download_insecure]}--box #{config[:box]} --provider #{config[:provider]}" + cmd = "#{config[:vagrant_binary]} box update --box #{config[:box]}" + cmd += " --architecture #{config[:box_arch]}" if config[:box_arch] + cmd += " --provider #{config[:provider]}" if config[:provider] + cmd += " --insecure" if config[:box_download_insecure] + config[:box_auto_update] = cmd end # Create vagrant command to remove older versions of the box def finalize_box_auto_prune! return if config[:box_auto_prune].nil? - config[:box_auto_prune] = "vagrant box prune --force --keep-active-boxes --name #{config[:box]} --provider #{config[:provider]}" + cmd = "#{config[:vagrant_binary]} box prune --force --keep-active-boxes --name #{config[:box]}" + cmd += " --architecture #{config[:box_arch]}" if config[:box_arch] + cmd += " --provider #{config[:provider]}" if config[:provider] + config[:box_auto_prune] = cmd end # Replaces any `{{vagrant_root}}` tokens in the pre create command. diff --git a/templates/Vagrantfile.erb b/templates/Vagrantfile.erb index 869d801..3849000 100644 --- a/templates/Vagrantfile.erb +++ b/templates/Vagrantfile.erb @@ -20,6 +20,10 @@ Vagrant.configure("2") do |c| c.vm.box_version = "<%= config[:box_version] %>" <% end %> +<% if config[:box_arch] %> + c.vm.box_architecture = "<%= config[:box_arch] %>" +<% end %> + <% if !config[:box_check_update].nil? %> c.vm.box_check_update = <%= config[:box_check_update] %> <% end %> From 39f8d874f175554d369c6cc6f3c40d6b4bc4fcc7 Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Mon, 5 Feb 2024 17:57:20 -0600 Subject: [PATCH 2/7] spec fix for new vagrant version Signed-off-by: Corey Hemminger --- spec/kitchen/driver/vagrant_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/kitchen/driver/vagrant_spec.rb b/spec/kitchen/driver/vagrant_spec.rb index 7337d40..659c9a9 100644 --- a/spec/kitchen/driver/vagrant_spec.rb +++ b/spec/kitchen/driver/vagrant_spec.rb @@ -542,7 +542,7 @@ def run_command(_cmd, options = {}) with_unsupported_vagrant expect { driver.verify_dependencies }.to raise_error( - Kitchen::UserError, /Please upgrade to version 1.1.0 or higher/ + Kitchen::UserError, /Please upgrade to version 2.4.0 or higher/ ) end @@ -551,7 +551,7 @@ def run_command(_cmd, options = {}) .with("vagrant --version", any_args).and_raise(Errno::ENOENT) expect { driver.verify_dependencies }.to raise_error( - Kitchen::UserError, /Vagrant 1.1.0 or higher is not installed/ + Kitchen::UserError, /Vagrant 2.4.0 or higher is not installed/ ) end end From 1a9b1d872ab9a2f6f1fdd3ed0be625b9a4491b40 Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Mon, 5 Feb 2024 18:00:10 -0600 Subject: [PATCH 3/7] spec version fix Signed-off-by: Corey Hemminger --- spec/kitchen/driver/vagrant_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/kitchen/driver/vagrant_spec.rb b/spec/kitchen/driver/vagrant_spec.rb index 659c9a9..955b74a 100644 --- a/spec/kitchen/driver/vagrant_spec.rb +++ b/spec/kitchen/driver/vagrant_spec.rb @@ -2139,7 +2139,7 @@ def debug_lines end def with_modern_vagrant - with_vagrant("1.7.2") + with_vagrant("2.4.1") end def with_unsupported_vagrant From a99d381c08be647664c2bc7dde9e050f49ff13e1 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 5 Feb 2024 21:18:21 -0500 Subject: [PATCH 4/7] Update vagrant.rb Signed-off-by: Tim Smith --- lib/kitchen/driver/vagrant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 2a04b37..f8cdabf 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -226,7 +226,7 @@ def cache_directory protected - WEBSITE = "https://www.vagrantup.com/downloads.html".freeze + WEBSITE = "https://developer.hashicorp.com/vagrant/install".freeze MIN_VER = "2.4.0".freeze class << self From 9e954ec74946d1b6a19d8e05b5794fe5d8367f20 Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 6 Feb 2024 11:37:41 -0600 Subject: [PATCH 5/7] remove dependency on vagrant-winrm gem as it's built into vagrant 2.2.0 since Oct 2018 Signed-off-by: Corey Hemminger --- lib/kitchen/driver/vagrant.rb | 53 ------------------------ spec/kitchen/driver/vagrant_spec.rb | 64 ----------------------------- 2 files changed, 117 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index f8cdabf..013e544 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -230,12 +230,6 @@ def cache_directory MIN_VER = "2.4.0".freeze class << self - - # @return [true,false] whether or not the vagrant-winrm plugin is - # installed - # @api private - attr_accessor :winrm_plugin_passed - # @return [String] the version of Vagrant installed on the workstation # @api private attr_accessor :vagrant_version @@ -399,19 +393,6 @@ def finalize_network! end end - # Loads any required third party Ruby libraries or runs any shell out - # commands to prepare the plugin. This method will be called in the - # context of the main thread of execution and so does not necessarily - # have to be thread safe. - # - # @raise [ClientError] if any library loading fails or any of the - # dependency requirements cannot be satisfied - # @api private - def load_needed_dependencies! - super - verify_winrm_plugin if winrm_transport? - end - # Renders the Vagrantfile ERb template. # # @return [String] the contents for a Vagrantfile @@ -606,46 +587,12 @@ def vagrant_version " Please download a package from #{WEBSITE}." end - # Verify that the vagrant-winrm plugin is installed and a suitable - # version of Vagrant is installed - # - # @api private - def verify_winrm_plugin - if Gem::Version.new(vagrant_version) < Gem::Version.new("1.6") - raise UserError, "Detected an old version of Vagrant " \ - "(#{vagrant_version}) that cannot support the vagrant-winrm " \ - "Vagrant plugin." \ - " Please upgrade to version 1.6 or higher from #{WEBSITE}." - end - - if Gem::Version.new(vagrant_version) < Gem::Version.new("2.2.0") && !winrm_plugin_installed? - raise UserError, "Vagrant version #{vagrant_version} requires the " \ - "vagrant-winrm plugin to properly communicate with this Vagrant VM " \ - "over WinRM Transport. Please install this plugin with: " \ - "`vagrant plugin install vagrant-winrm' and try again." \ - "Alternatively upgrade to Vagrant >= 2.2.0 which does not " \ - "require the vagrant-winrm plugin." - end - end - # @return [true,false] whether or not the host is windows # # @api private def windows_host? RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ end - - # @return [true,false] whether or not the vagrant-winrm plugin is - # installed - # @api private - def winrm_plugin_installed? - return true if self.class.winrm_plugin_passed - - self.class.winrm_plugin_passed = run_silently( - "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd - ) - .split("\n").find { |line| line =~ /vagrant-winrm\s+/ } - end end end end diff --git a/spec/kitchen/driver/vagrant_spec.rb b/spec/kitchen/driver/vagrant_spec.rb index 955b74a..bc4a817 100644 --- a/spec/kitchen/driver/vagrant_spec.rb +++ b/spec/kitchen/driver/vagrant_spec.rb @@ -79,7 +79,6 @@ def run_command(_cmd, options = {}) before(:each) { stub_const("ENV", env) } after do - driver_object.class.send(:winrm_plugin_passed=, nil) driver_object.class.send(:vagrant_version=, nil) end @@ -556,69 +555,6 @@ def run_command(_cmd, options = {}) end end - describe "#load_needed_dependencies!" do - - describe "with winrm transport" do - - before { allow(transport).to receive(:name).and_return("WinRM") } - - it "old version of Vagrant raises UserError" do - with_vagrant("1.5.0") - - expect { instance }.to raise_error( - Kitchen::Error, /Please upgrade to version 1.6 or higher/ - ) - end - - it "modern vagrant without plugin installed raises UserError" do - with_modern_vagrant - allow(driver_object).to receive(:run_command) - .with("vagrant plugin list", any_args).and_return("nope (1.2.3)") - - expect { instance }.to raise_error( - Kitchen::Error, /vagrant plugin install vagrant-winrm/ - ) - end - - it "modern vagrant with plugin installed succeeds" do - with_modern_vagrant - allow(driver_object).to receive(:run_command) - .with("vagrant plugin list", any_args) - .and_return("vagrant-winrm (1.2.3)") - - instance - end - end - - describe "without winrm transport" do - - before { allow(transport).to receive(:name).and_return("Anything") } - - it "old version of Vagrant succeeds" do - with_vagrant("1.5.0") - - instance - end - - it "modern vagrant without plugin installed succeeds" do - with_modern_vagrant - allow(driver_object).to receive(:run_command) - .with("vagrant plugin list", any_args).and_return("nope (1.2.3)") - - instance - end - - it "modern vagrant with plugin installed succeeds" do - with_modern_vagrant - allow(driver_object).to receive(:run_command) - .with("vagrant plugin list", any_args) - .and_return("vagrant-winrm (1.2.3)") - - instance - end - end - end - describe "#create" do let(:cmd) { driver.create(state) } From 12508eeac25fc93599f452cb596b6b5e71576eba Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 6 Feb 2024 12:07:21 -0600 Subject: [PATCH 6/7] update readme with vagrant version requirement bump. Signed-off-by: Corey Hemminger --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11543c6..4305a65 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ required. ### Vagrant -A Vagrant version of 1.6 or later. +A Vagrant version of 2.4 or later. ## Installation From 649bb11d73daa28aee8ddf6e4e73fbad0159613d Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 6 Feb 2024 12:25:56 -0600 Subject: [PATCH 7/7] remove arch from prune command Signed-off-by: Corey Hemminger --- lib/kitchen/driver/vagrant.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 013e544..992b5e7 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -321,7 +321,6 @@ def finalize_box_auto_prune! return if config[:box_auto_prune].nil? cmd = "#{config[:vagrant_binary]} box prune --force --keep-active-boxes --name #{config[:box]}" - cmd += " --architecture #{config[:box_arch]}" if config[:box_arch] cmd += " --provider #{config[:provider]}" if config[:provider] config[:box_auto_prune] = cmd end