From 5fcf10d6cd50958bd12fb39691786ed5debe6714 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 8 Oct 2010 10:44:19 -0700 Subject: [PATCH] Validations to assure base MAC address is set --- CHANGELOG.md | 2 ++ config/default.rb | 2 +- lib/vagrant/action/vm/match_mac_address.rb | 2 ++ lib/vagrant/config/vm.rb | 1 + lib/vagrant/errors.rb | 5 +++++ lib/vagrant/test_helpers.rb | 1 + templates/locales/en.yml | 8 +++++++- test/vagrant/action/vm/match_mac_address_test.rb | 8 ++++++++ 8 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdf067f3c..1f4a90466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/config/default.rb b/config/default.rb index b1312e068..faa7f5e08 100644 --- a/config/default.rb +++ b/config/default.rb @@ -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 diff --git a/lib/vagrant/action/vm/match_mac_address.rb b/lib/vagrant/action/vm/match_mac_address.rb index b64cfd783..fc48d5a92 100644 --- a/lib/vagrant/action/vm/match_mac_address.rb +++ b/lib/vagrant/action/vm/match_mac_address.rb @@ -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 diff --git a/lib/vagrant/config/vm.rb b/lib/vagrant/config/vm.rb index 6d549d910..c70892237 100644 --- a/lib/vagrant/config/vm.rb +++ b/lib/vagrant/config/vm.rb @@ -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 diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 54d6a8c09..3eac27f54 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -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") diff --git a/lib/vagrant/test_helpers.rb b/lib/vagrant/test_helpers.rb index 3928b4c92..2c68dc0a3 100644 --- a/lib/vagrant/test_helpers.rb +++ b/lib/vagrant/test_helpers.rb @@ -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 diff --git a/templates/locales/en.yml b/templates/locales/en.yml index c0dbb4607..a613ac95a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -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! diff --git a/test/vagrant/action/vm/match_mac_address_test.rb b/test/vagrant/action/vm/match_mac_address_test.rb index a4a6f5384..0795502b8 100644 --- a/test/vagrant/action/vm/match_mac_address_test.rb +++ b/test/vagrant/action/vm/match_mac_address_test.rb @@ -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