From 88db2a1b894593ff0a688847b16b3713efe10ec7 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 4 May 2018 09:37:20 -0700 Subject: [PATCH] (#9775) Move triggers object init in machine Prior to this commit, the hyper-v provider called an action on a machine that hadn't fully finished initializing. This commit fixes that by moving up the initialization of the triggers object next to the rest of the instance variables of the machine object. --- lib/vagrant/machine.rb | 3 +-- test/unit/vagrant/machine_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index fefbbc376a3..5a3f4a3d0ca 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -110,6 +110,7 @@ def initialize(name, provider_name, provider_cls, provider_config, provider_opti @ui = Vagrant::UI::Prefixed.new(@env.ui, @name) @ui_mutex = Mutex.new @state_mutex = Mutex.new + @triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self) # Read the ID, which is usually in local storage @id = nil @@ -149,8 +150,6 @@ def initialize(name, provider_name, provider_cls, provider_config, provider_opti # Output a bunch of information about this machine in # machine-readable format in case someone is listening. @ui.machine("metadata", "provider", provider_name) - - @triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self) end # This calls an action on the provider. The provider may or may not diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index d6411bd169e..0b415d9da64 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -74,6 +74,12 @@ def new_instance subject = new_instance expect(subject.state.id).to eq(Vagrant::MachineState::NOT_CREATED_ID) expect(subject.id).to be_nil + expect(subject.id).to be_nil + end + + it "should initialize the trigger object" do + subject = new_instance + expect(subject.instance_variable_get(:@triggers)).not_to be_nil end describe "as a base" do