Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hook with methods #2569

Merged
merged 3 commits into from
Dec 3, 2013
Merged

Fix hook with methods #2569

merged 3 commits into from
Dec 3, 2013

Conversation

fgrehm
Copy link
Contributor

@fgrehm fgrehm commented Dec 3, 2013

This is a follow-up of my heads up over here

I tried using the new provisioner_run hook from GH-2405 using the following Vagrantfile and it turned out that the action class does not get executed:

class Action
  def initialize(app, env)
    @app = app
  end

  def call(env)
    puts "Before '#{env[:provisioner_name]}'"
    @app.call env
    puts "After '#{env[:provisioner_name]}'"
  end
end

class Plugin < Vagrant.plugin('2')
  name 'testing-hook'
  action_hook 'hook-name', :provisioner_run do |hook|
    hook.prepend Action
  end
end

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.provision :shell, inline: 'echo hello'
  config.vm.provision :shell, inline: 'echo hello 2'
end

The output of a vagrant provision:

$ be vagrant provision
You appear to be running Vagrant in a Bundler environment. Because
Vagrant should be run within installers (outside of Bundler), Vagrant
will assume that you're developing plugins and will change its behavior
in certain ways to better assist plugin development.

[default] Running provisioner: shell...
[default] Running: inline script
stdin: is not a tty
hello
[default] Running provisioner: shell...
[default] Running: inline script
stdin: is not a tty
hello 2

vagrant provision after this patch:

$ be vagrant provision
You appear to be running Vagrant in a Bundler environment. Because
Vagrant should be run within installers (outside of Bundler), Vagrant
will assume that you're developing plugins and will change its behavior
in certain ways to better assist plugin development.

[default] Running provisioner: shell...
Before 'shell'
[default] Running: inline script
stdin: is not a tty
hello
After 'shell'
[default] Running provisioner: shell...
Before 'shell'
[default] Running: inline script
stdin: is not a tty
hello 2
After 'shell'

While this PR also adds a spec for the new Method support, I wasn't able to figure out where I should add a spec for making sure the hook behaves as expected when a Method object gets provided.

@fgrehm
Copy link
Contributor Author

fgrehm commented Dec 3, 2013

/cc @phinze @mitchellh

@mitchellh
Copy link
Contributor

Ah hah! Nice catch. Actually, we should just check if it responds to call.. Yeah.

@mitchellh
Copy link
Contributor

Merging.

mitchellh added a commit that referenced this pull request Dec 3, 2013
@mitchellh mitchellh merged commit 900a8a4 into master Dec 3, 2013
@mitchellh mitchellh deleted the fix-hook-with-methods branch December 3, 2013 19:44
@fgrehm
Copy link
Contributor Author

fgrehm commented Dec 3, 2013

Thanks!

@tmatilai
Copy link
Contributor

Is this broken again? At least the example Vagrantfile in description doesn't seem to trigger the action.

@ghost ghost locked and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants