Validations to assure base MAC address is set

This commit is contained in:
Mitchell Hashimoto 2010-10-08 10:44:19 -07:00
parent c6b0fae318
commit 5fcf10d6cd
8 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,7 @@
## 0.6.5 (unreleased)
- Validations on base MAC address to avoid situation described in GH-166, GH-181
from ever happening again.
- Properly load sub-VM configuration on first-pass of config loading. Solves
a LOT of problems with multi-VM. [GH-166] [GH-181]
- Configuration now only validates on final Vagrantfile proc, so multi-VM

View File

@ -16,7 +16,7 @@ Vagrant::Config.run do |config|
config.vm.auto_port_range = (2200..2250)
config.vm.box_ovf = "box.ovf"
config.vm.box_url = nil
config.vm.base_mac = "0800279C2E42"
config.vm.base_mac = nil
config.vm.forward_port("ssh", 22, 2222, :auto => true)
config.vm.disk_image_format = 'VMDK'
config.vm.provisioner = nil

View File

@ -7,6 +7,8 @@ module Vagrant
end
def call(env)
raise Errors::VMBaseMacNotSpecified if !env.env.config.vm.base_mac
env.ui.info I18n.t("vagrant.actions.vm.match_mac.matching")
env["vm"].vm.network_adapters.first.mac_address = env.env.config.vm.base_mac
env["vm"].vm.save

View File

@ -105,6 +105,7 @@ module Vagrant
end
errors.add(I18n.t("vagrant.config.vm.boot_mode_invalid")) if ![:vrdp, :gui].include?(boot_mode.to_sym)
errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if !base_mac
end
end
end

View File

@ -283,6 +283,11 @@ module Vagrant
error_key(:virtualbox_not_detected)
end
class VMBaseMacNotSpecified < VagrantError
status_code(47)
error_key(:no_base_mac, "vagrant.actions.vm.match_mac")
end
class VMFailedToBoot < VagrantError
status_code(21)
error_key(:failed_to_boot, "vagrant.actions.vm.boot")

View File

@ -29,6 +29,7 @@ module Vagrant
File.open(path.to_s, "w") do |f|
f.puts "Vagrant::Config.run do |config|"
f.puts "config.vagrant.home = '#{home_path}'"
f.puts "config.vm.base_mac = 'foo' if !config.vm.base_mac"
f.puts str
f.puts "end"
end

View File

@ -113,8 +113,9 @@ en:
ssh:
private_key_missing: "`private_key_path` file must exist: %{path}"
vm:
shared_folder_hostpath_missing: "Shared folder host path for '%{name}' doesn't exist: %{path}"
base_mac_invalid: "Base MAC address for eth0/NAT must be set. Contact box maintainer for more information."
boot_mode_invalid: "Boot mode must be one of: vrdp or gui"
shared_folder_hostpath_missing: "Shared folder host path for '%{name}' doesn't exist: %{path}"
#-------------------------------------------------------------------------------
# Translations for commands. e.g. `vagrant x`
@ -264,6 +265,11 @@ en:
manually for more verbose error output.
match_mac:
matching: Matching MAC address for NAT networking...
no_base_mac: |-
No base MAC address was specified. This is required for the NAT networking
to work properly (and hence port forwarding, SSH, etc.). Specifying this
MAC address is typically up to the box and box maintiner. Please contact
the relevant person to solve this issue.
network:
collides: |-
The specified host network collides with a non-hostonly network!

View File

@ -25,4 +25,12 @@ class MatchMACAddressVMActionTest < Test::Unit::TestCase
@instance.call(@env)
end
should "raise an exception if no base MAC address is specified" do
@env.env.config.vm.base_mac = nil
assert_raises(Vagrant::Errors::VMBaseMacNotSpecified) {
@instance.call(@env)
}
end
end