Access provider driver through machine for version check
Updates the VirtualBox version check for network range validation
to access the driver via the machine instances provider within the
passed env.
This commit is contained in:
parent
0adfe2745e
commit
ac92fd8e1d
@ -296,7 +296,7 @@ module VagrantPlugins
|
||||
error: e.message
|
||||
end
|
||||
|
||||
validate_hostonly_ip!(options[:ip])
|
||||
validate_hostonly_ip!(options[:ip], @env[:machine].provider.driver)
|
||||
|
||||
if ip.ipv4?
|
||||
# Verify that a host-only network subnet would not collide
|
||||
@ -515,8 +515,8 @@ module VagrantPlugins
|
||||
# ranges. It only validates if the network configuration file exists.
|
||||
# This was introduced in 6.1.28 so previous version won't have restrictions
|
||||
# placed on the valid ranges
|
||||
def validate_hostonly_ip!(ip)
|
||||
return if Gem::Version.new(Driver::Meta.version) < HOSTONLY_VALIDATE_VERSION ||
|
||||
def validate_hostonly_ip!(ip, driver)
|
||||
return if Gem::Version.new(driver.version) < HOSTONLY_VALIDATE_VERSION ||
|
||||
Vagrant::Util::Platform.windows?
|
||||
|
||||
ip = IPAddr.new(ip.to_s) if !ip.is_a?(IPAddr)
|
||||
|
||||
@ -21,7 +21,8 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
||||
|
||||
let(:env) {{ machine: machine, ui: machine.ui }}
|
||||
let(:app) { lambda { |*args| }}
|
||||
let(:driver) { double("driver") }
|
||||
let(:driver) { double("driver", version: vbox_version) }
|
||||
let(:vbox_version) { "6.1.0" }
|
||||
|
||||
let(:nics) { {} }
|
||||
|
||||
@ -30,8 +31,6 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
||||
before do
|
||||
allow(driver).to receive(:enable_adapters)
|
||||
allow(driver).to receive(:read_network_interfaces) { nics }
|
||||
allow(VagrantPlugins::ProviderVirtualBox::Driver::Meta).to receive(:version).
|
||||
and_return("6.1.0")
|
||||
end
|
||||
|
||||
describe "#hostonly_config" do
|
||||
@ -65,23 +64,21 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
||||
describe "#validate_hostonly_ip!" do
|
||||
let(:address) { "192.168.1.2" }
|
||||
let(:net_conf) { [IPAddr.new(address + "/24")]}
|
||||
let(:vbox_version) { "6.1.28" }
|
||||
|
||||
before do
|
||||
allow(VagrantPlugins::ProviderVirtualBox::Driver::Meta).to receive(:version).
|
||||
and_return("6.1.28")
|
||||
|
||||
allow(subject).to receive(:load_net_conf).and_return(net_conf)
|
||||
expect(subject).to receive(:validate_hostonly_ip!).and_call_original
|
||||
end
|
||||
|
||||
it "should load net configuration" do
|
||||
expect(subject).to receive(:load_net_conf).and_return(net_conf)
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
end
|
||||
|
||||
context "when address is within ranges" do
|
||||
it "should not error" do
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
end
|
||||
end
|
||||
|
||||
@ -90,24 +87,21 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
||||
|
||||
it "should raise an error" do
|
||||
expect {
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
}.to raise_error(Vagrant::Errors::VirtualBoxInvalidHostSubnet)
|
||||
end
|
||||
end
|
||||
|
||||
context "when virtualbox version does not restrict range" do
|
||||
before do
|
||||
allow(VagrantPlugins::ProviderVirtualBox::Driver::Meta).to receive(:version).
|
||||
and_return("6.1.20")
|
||||
end
|
||||
let(:vbox_version) { "6.1.20" }
|
||||
|
||||
it "should not error" do
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
end
|
||||
|
||||
it "should not attempt to load network configuration" do
|
||||
expect(subject).not_to receive(:load_net_conf)
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
end
|
||||
end
|
||||
|
||||
@ -117,12 +111,12 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
||||
end
|
||||
|
||||
it "should not error" do
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
end
|
||||
|
||||
it "should not attempt to load network configuration" do
|
||||
expect(subject).not_to receive(:load_net_conf)
|
||||
subject.validate_hostonly_ip!(address)
|
||||
subject.validate_hostonly_ip!(address, driver)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user