From 14ca7ecc24d3024b2bb99967a90433aba929e87e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 22 Jul 2011 23:53:19 -0700 Subject: [PATCH] Better validation for networking configuration --- CHANGELOG.md | 3 +++ lib/vagrant/config/vm.rb | 22 +++++++++++++++------- templates/locales/en.yml | 29 ++++------------------------- test/vagrant/config/vm_test.rb | 8 -------- 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8628d8db..f5e116032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - Fix chef solo simply not working with roles/data bags. [GH-425] - Multiple chef solo provisioners now work together. - Update Puppet provisioner so no deprecation warning is shown. [GH-421] + - Removed error on "provisioner=" in config, as this has not existed + for some time now. + - Add better validation for networking. ## 0.8.1 (July 20, 2011) diff --git a/lib/vagrant/config/vm.rb b/lib/vagrant/config/vm.rb index cd6de43b0..63304c253 100644 --- a/lib/vagrant/config/vm.rb +++ b/lib/vagrant/config/vm.rb @@ -67,13 +67,6 @@ module Vagrant @provisioners << Provisioner.new(top, name, options, &block) end - # This shows an error message to smooth the transition for the - # backwards incompatible provisioner syntax change introduced - # in Vagrant 0.7.0. - def provisioner=(_value) - raise Errors::VagrantError, :_key => :provisioner_equals_not_supported - end - def customize(&block) push_proc(&block) end @@ -126,6 +119,21 @@ module Vagrant end end + # Validate some basic networking + network_options.each do |options| + next if !options + + ip = options[:ip].split(".") + + if ip.length != 4 + errors.add(I18n.t("vagrant.config.vm.network_ip_invalid", + :ip => options[:ip])) + elsif ip.last == "1" + errors.add(I18n.t("vagrant.config.vm.network_ip_ends_one", + :ip => options[:ip])) + end + end + # Each provisioner can validate itself provisioners.each do |prov| # TODO: Remove at some point diff --git a/templates/locales/en.yml b/templates/locales/en.yml index dc2517f00..5dfb2075b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -48,31 +48,6 @@ en: multi_vm_required: "A multi-vm environment is required for name specification to this command." multi_vm_target_required: "`vagrant %{command}` requires a specific VM name to target in a multi-VM environment." no_env: "No Vagrant environment detected. Run `vagrant init` to set one up." - provisioner_equals_not_supported: |- - The `config.vm.provisioner =` syntax has been removed in Vagrant 0.7.0. - Please change your provisioners to use the new syntax described below. - All of these changes are reflected on the Vagrant website as well. - - Before: - - config.vm.provisioner = :chef_solo - config.chef.cookbooks_path = "my_cookbooks" - config.chef.add_recipe "apache" - - After: - - config.vm.provision :chef_solo, :cookbooks_path => "my_cookbooks", - :run_list => ["recipe[apache]"] - - Instead of just a hash, you may use a block as well to get access to the - configuration object: - - config.vm.provision :chef_solo do |chef| - chef.cookbooks_path = "my_cookbooks" - chef.add_recipe "apache" - end - - This error message will be removed in later versions of Vagrant. ssh_authentication_failed: |- SSH authentication failed! This is typically caused by the public/private keypair for the SSH user not being properly set on the guest VM. Please @@ -190,6 +165,10 @@ en: boot_mode_invalid: "Boot mode must be one of: vrdp or gui" box_missing: "A box must be specified." box_not_found: "The box '%{name}' could not be found." + network_ip_invalid: "The host only network IP '%{ip}' is invalid." + network_ip_ends_one: |- + The host only network IP '%{ip}' must not end in a 1, as this + is reserved for the host machine. shared_folder_hostpath_missing: "Shared folder host path for '%{name}' doesn't exist: %{path}" shared_folder_nfs_owner_group: |- Shared folder '%{name}': NFS does not support the owner/group settings. diff --git a/test/vagrant/config/vm_test.rb b/test/vagrant/config/vm_test.rb index 3370213f6..585e1aef3 100644 --- a/test/vagrant/config/vm_test.rb +++ b/test/vagrant/config/vm_test.rb @@ -53,12 +53,4 @@ class ConfigVMTest < Test::Unit::TestCase assert @config.proc_stack.include?(proc) end end - - context "deprecated config" do - should "raise an error for provisioner=" do - assert_raises(Vagrant::Errors::VagrantError) { - @config.provisioner = :chef_solo - } - end - end end