Skip to content

Commit

Permalink
(hashicorp#9775) Move triggers object init in machine
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
briancain committed May 4, 2018
1 parent 09be82f commit 88db2a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/vagrant/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/unit/vagrant/machine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88db2a1

Please sign in to comment.