From 6db640fb14c1ba3aa5f25a22ad58dc478fd7d6ff Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 11 Sep 2023 17:48:02 -0700 Subject: [PATCH] Adjust vbox hostonly config for ipv6 Check the type when an ipv6 address is being used. If the type does not have a `6` suffix, append it. --- .../providers/virtualbox/action/network.rb | 3 +++ .../virtualbox/action/network_test.rb | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index efa5929d3..13342932a 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -302,6 +302,9 @@ module VagrantPlugins elsif ip.ipv6? options[:netmask] ||= 64 + # Append a 6 to the end of the type if it is not already set + options[:type] = "#{options[:type]}6".to_sym if + !options[:type].to_s.end_with?("6") else raise IPAddr::AddressFamilyError, 'unknown address family' end diff --git a/test/unit/plugins/providers/virtualbox/action/network_test.rb b/test/unit/plugins/providers/virtualbox/action/network_test.rb index f71ceaab2..79e5a7535 100644 --- a/test/unit/plugins/providers/virtualbox/action/network_test.rb +++ b/test/unit/plugins/providers/virtualbox/action/network_test.rb @@ -62,6 +62,28 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do expect(subject).to receive(:validate_hostonly_ip!) subject.hostonly_config(options) end + + context "when address is ipv6" do + let(:address) { "::1" } + + context "when type is static6" do + let(:type) { :static6 } + + it "should have a static6 type" do + result = subject.hostonly_config(options) + expect(result[:type]).to eq(:static6) + end + end + + context "when type is static" do + let(:type) { :static } + + it "should have static6 type" do + result = subject.hostonly_config(options) + expect(result[:type]).to eq(:static6) + end + end + end end describe "#validate_hostonly_ip!" do