diff --git a/lib/vagrant/action/builtin/handle_box.rb b/lib/vagrant/action/builtin/handle_box.rb index c9c5d130d..d8eb9c051 100644 --- a/lib/vagrant/action/builtin/handle_box.rb +++ b/lib/vagrant/action/builtin/handle_box.rb @@ -20,7 +20,7 @@ module Vagrant def call(env) machine = env[:machine] - if !machine.config.vm.box + if !machine.config.vm.box || machine.config.vm.box.to_s.empty? @logger.info("Skipping HandleBox because no box is set") return @app.call(env) end diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 3dc7ada99..9d62c4224 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -197,7 +197,7 @@ module Vagrant local_keys = keys.dup # Load the box Vagrantfile, if there is one - if config.vm.box && boxes + if !config.vm.box.to_s.empty? && boxes box = boxes.find(config.vm.box, box_formats, config.vm.box_version) if box box_vagrantfile = find_vagrantfile(box.directory) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 1fa0d2e5e..acc6df6a6 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -734,6 +734,10 @@ module VagrantPlugins errors << I18n.t("vagrant.config.vm.clone_and_box") end + if box && box.empty? + errors << I18n.t("vagrant.config.vm.box_empty", machine_name: machine.name) + end + errors << I18n.t("vagrant.config.vm.hostname_invalid_characters", name: machine.name) if \ @hostname && @hostname !~ /^[a-z0-9][-.a-z0-9]*$/i diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 6e08ab7e4..782904f49 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1995,6 +1995,7 @@ en: Checksum type specified but "box_download_checksum" is blank box_download_checksum_notblank: |- Checksum specified but must also specify "box_download_checksum_type" + box_empty: "Box value for guest '%{machine_name}' is an empty string." box_missing: "A box must be specified." box_download_options_type: |- Found "box_download_options" specified as type '%{type}', should be a Hash diff --git a/test/unit/plugins/guests/openwrt/guest_test.rb b/test/unit/plugins/guests/openwrt/guest_test.rb new file mode 100644 index 000000000..e69de29bb diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index b8d06fae4..ebcef38a3 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -86,6 +86,12 @@ describe VagrantPlugins::Kernel_V2::VMConfig do assert_invalid end + it "cannot be an empty string" do + subject.box = "" + subject.finalize! + assert_invalid + end + it "is not required if the provider says so" do machine.provider_options[:box_optional] = true subject.box = nil diff --git a/test/unit/vagrant/action/builtin/handle_box_test.rb b/test/unit/vagrant/action/builtin/handle_box_test.rb index 2d2eb271b..056ebc5bf 100644 --- a/test/unit/vagrant/action/builtin/handle_box_test.rb +++ b/test/unit/vagrant/action/builtin/handle_box_test.rb @@ -37,6 +37,15 @@ describe Vagrant::Action::Builtin::HandleBox do subject.call(env) end + it "works if box is empty string" do + machine.config.vm.box = "" + machine.config.vm.box_url = nil + + expect(app).to receive(:call).with(env) + + subject.call(env) + end + it "doesn't do anything if a box exists" do allow(machine).to receive(:box).and_return(box) diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index d4b99445f..71f75d217 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -368,6 +368,17 @@ describe Vagrant::Vagrantfile do to raise_error(Vagrant::Errors::ProviderNotUsable) end + it "does not try to load the box if the box is empty" do + provider_cls = register_provider("foo") + + configure do |config| + config.vm.box = "" + end + + expect(boxes).not_to receive(:find) + results = subject.machine_config(:default, :foo, boxes) + end + context "when provider validation is ignored" do before do configure do |config|