From 5903bfb3c6f767f05ad9f1c4c6ef5237de039ea8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 4 Jan 2015 15:41:30 -0800 Subject: [PATCH] commands/push: validate configuration /cc @sethvargo - Some weirdness here but overall should work fine. I'm not sure if there was a GH issue this should be attached to or close. To explain: We just use the first machine with the default provider. A Vagrant::Environment guarantees there is at least one machine, so `env.machine_names.first` will always work. And we can just use the default provider because we don't really care. Finally, it can be any old machine we pass in because we just want the "global" config to validate and there is no way to say "don't validate machine-specific configs", so we might as well just pick the first machine to validate. --- CHANGELOG.md | 2 ++ plugins/commands/push/command.rb | 5 +++++ .../plugins/commands/push/command_test.rb | 22 +++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5901fa74..802d2b209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,10 @@ BUG FIXES: - core: private boxes still referencing vagrantcloud.com will have their vagrant login access token properly appended + - core: push plugin configuration is properly validated - commands/push: push lookups are by user-defined name, not push strategy name [GH-4975] + - commands/push: validate the configuration - guests/arch: fix network configuration due to poor line breaks. [GH-4964] - provisioners/chef: remove Chef version check from solo.rb generation and make `roles_path` populate correctly diff --git a/plugins/commands/push/command.rb b/plugins/commands/push/command.rb index dabe74bb6..902a0c946 100644 --- a/plugins/commands/push/command.rb +++ b/plugins/commands/push/command.rb @@ -19,6 +19,11 @@ module VagrantPlugins name = validate_pushes!(@env.pushes, argv[0]) + # Validate the configuration + @env.machine(@env.machine_names.first, @env.default_provider).action_raw( + :config_validate, + Vagrant::Action::Builtin::ConfigValidate) + @logger.debug("'push' environment with strategy: `#{name}'") @env.push(name) diff --git a/test/unit/plugins/commands/push/command_test.rb b/test/unit/plugins/commands/push/command_test.rb index 06995d51d..0f649c6c4 100644 --- a/test/unit/plugins/commands/push/command_test.rb +++ b/test/unit/plugins/commands/push/command_test.rb @@ -6,11 +6,14 @@ describe VagrantPlugins::CommandPush::Command do include_context "unit" include_context "command plugin helpers" + let(:iso_env) { isolated_environment } let(:env) do - isolated_environment.tap do |env| - env.vagrantfile("") - env.create_vagrant_env - end + iso_env.vagrantfile(<<-VF) +Vagrant.configure("2") do |config| + config.vm.box = "nope" +end +VF + iso_env.create_vagrant_env end let(:argv) { [] } @@ -35,6 +38,17 @@ describe VagrantPlugins::CommandPush::Command do subject.execute end + it "validates the configuration" do + iso_env.vagrantfile("") + + subject = described_class.new(argv, iso_env.create_vagrant_env) + allow(subject).to receive(:validate_pushes!) + .and_return(:noop) + + expect { subject.execute }.to raise_error( + Vagrant::Errors::ConfigInvalid) + end + it "delegates to Environment#push" do expect(env).to receive(:push).once subject.execute