Merge pull request #9275 from zachflower/validate_ip_addresses
Add a clean error message for invalid IP addresses
This commit is contained in:
commit
0d7ad9f18f
|
@ -448,6 +448,10 @@ module Vagrant
|
||||||
error_key(:collides, "vagrant.actions.vm.host_only_network")
|
error_key(:collides, "vagrant.actions.vm.host_only_network")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class NetworkAddressInvalid < VagrantError
|
||||||
|
error_key(:network_address_invalid)
|
||||||
|
end
|
||||||
|
|
||||||
class NetworkDHCPAlreadyAttached < VagrantError
|
class NetworkDHCPAlreadyAttached < VagrantError
|
||||||
error_key(:dhcp_already_attached, "vagrant.actions.vm.network")
|
error_key(:dhcp_already_attached, "vagrant.actions.vm.network")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require "ipaddr"
|
require "ipaddr"
|
||||||
|
require "resolv"
|
||||||
require "set"
|
require "set"
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
@ -258,7 +259,12 @@ module VagrantPlugins
|
||||||
# Default IP is in the 20-bit private network block for DHCP based networks
|
# Default IP is in the 20-bit private network block for DHCP based networks
|
||||||
options[:ip] = "172.28.128.1" if options[:type] == :dhcp && !options[:ip]
|
options[:ip] = "172.28.128.1" if options[:type] == :dhcp && !options[:ip]
|
||||||
|
|
||||||
|
begin
|
||||||
ip = IPAddr.new(options[:ip])
|
ip = IPAddr.new(options[:ip])
|
||||||
|
rescue IPAddr::InvalidAddressError => e
|
||||||
|
raise Vagrant::Errors::NetworkAddressInvalid, :ip => options[:ip], :error_msg => e.message
|
||||||
|
end
|
||||||
|
|
||||||
if ip.ipv4?
|
if ip.ipv4?
|
||||||
options[:netmask] ||= "255.255.255.0"
|
options[:netmask] ||= "255.255.255.0"
|
||||||
|
|
||||||
|
|
|
@ -891,6 +891,11 @@ en:
|
||||||
%{message}
|
%{message}
|
||||||
network_type_not_supported: |-
|
network_type_not_supported: |-
|
||||||
The %{type} network type is not supported for this box or guest.
|
The %{type} network type is not supported for this box or guest.
|
||||||
|
network_address_invalid: |-
|
||||||
|
The IP address '%{ip}' is not valid. Please review the error message
|
||||||
|
below to help resolve the issue:
|
||||||
|
|
||||||
|
%{error_msg}
|
||||||
network_manager_not_installed: |-
|
network_manager_not_installed: |-
|
||||||
Vagrant was instructed to configure the %{device} network device to
|
Vagrant was instructed to configure the %{device} network device to
|
||||||
be managed by NetworkManager. However, the configured guest VM does
|
be managed by NetworkManager. However, the configured guest VM does
|
||||||
|
|
|
@ -70,6 +70,20 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
||||||
}])
|
}])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises the appropriate error when provided with an invalid IP address" do
|
||||||
|
guest = double("guest")
|
||||||
|
machine.config.vm.network 'private_network', { ip: '192.168.33.06' }
|
||||||
|
|
||||||
|
expect{ subject.call(env) }.to raise_error(Vagrant::Errors::NetworkAddressInvalid)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises no invalid network error when provided with a valid IP address" do
|
||||||
|
guest = double("guest")
|
||||||
|
machine.config.vm.network 'private_network', { ip: '192.168.33.6' }
|
||||||
|
|
||||||
|
expect{ subject.call(env) }.not_to raise_error(Vagrant::Errors::NetworkAddressInvalid)
|
||||||
|
end
|
||||||
|
|
||||||
context "with a dhcp private network" do
|
context "with a dhcp private network" do
|
||||||
let(:bridgedifs) { [] }
|
let(:bridgedifs) { [] }
|
||||||
let(:hostonlyifs) { [] }
|
let(:hostonlyifs) { [] }
|
||||||
|
|
Loading…
Reference in New Issue