From f0a73c7c0578605b5cd71ae0d10d41ce4012fd02 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 23 Oct 2014 12:20:16 -0700 Subject: [PATCH] core: call #state in any #action call [GH-4513] --- CHANGELOG.md | 1 + lib/vagrant/machine.rb | 14 +++++++++++++- test/unit/vagrant/machine_test.rb | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be5e12d6b..9bf06574b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ BUG FIXES: - core: Box downloads recognize more complex content types that include "application/json" [GH-4525] - core: If all sub-machines are `autostart: false`, don't start any. [GH-4552] + - core: Update global-status state in more cases. [GH-4513] - commands/box: `--cert` flag works properly. [GH-4691] - command/docker-logs: Won't crash if container is removed. [GH-3990] - command/docker-run: Synced folders will be attached properly. [GH-3873] diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 62646fc90..fc548ec79 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -178,7 +178,19 @@ module Vagrant provider: @provider.to_s end - action_raw(name, callable, extra_env) + # Call the action + result = action_raw(name, callable, extra_env) + + # Call the state method so that we update our index state. Don't + # worry about exceptions here, since we just care about updating + # the cache. + begin + # Called for side effects + self.state + rescue Errors::VagrantError + end + + return result end rescue Errors::EnvironmentLockedError raise Errors::MachineActionLockedError, diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 38321e306..00b8c985a 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -216,6 +216,10 @@ describe Vagrant::Machine do end describe "#action" do + before do + provider.stub(state: Vagrant::MachineState.new(:foo, "", "")) + end + it "should be able to run an action that exists" do action_name = :up called = false @@ -266,6 +270,17 @@ describe Vagrant::Machine do expect { instance.action(action_name) }. to raise_error(Vagrant::Errors::UnimplementedProviderAction) end + + it "calls #state to update the machine index" do + action_name = :up + called = false + callable = lambda { |_env| called = true } + + expect(provider).to receive(:action).with(action_name).and_return(callable) + expect(instance).to receive(:state) + instance.action(:up) + expect(called).to be + end end describe "#action_raw" do