Skip to content

Commit

Permalink
Validations to assure base MAC address is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 8, 2010
1 parent c6b0fae commit 5fcf10d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant/action/vm/match_mac_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def initialize(app, env)
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
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant/config/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def validate(errors)
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
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ class VirtualBoxNotDetected < VagrantError
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")
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def vagrantfile(*args)
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
Expand Down
8 changes: 7 additions & 1 deletion templates/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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!
Expand Down
8 changes: 8 additions & 0 deletions test/vagrant/action/vm/match_mac_address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5fcf10d

Please sign in to comment.