vagrant-triggers 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b8ad1f94f85b3254ddbe243f0e4624b2cdc2ca4
4
- data.tar.gz: de5f4ed124442ae02058d9aadea4b04ad5555ff3
3
+ metadata.gz: 20f85521449cec74e8c6c0947943879e3464e031
4
+ data.tar.gz: 60dd75ac51dd416be9c09262b612bc9499d65ef8
5
5
  SHA512:
6
- metadata.gz: e8a08937ca2418e411d7fb5991cbd39f611785533ad19fb13022f1fa04cbad285adf9018b3f2e70d993eb80ea7ac14d5c3e110866ed12ea4e25ac861902a0f4c
7
- data.tar.gz: 2e7f17653c43b5893fa791ed0f39b21556e28aff328951a238d023ca0bc4c10d2e82beefa1415aef6f0b3cde31f0382e16355e4f060070b7e95b0492d5e82784
6
+ metadata.gz: 8bb36d46e8cd09f65e8bb0f7e3eb74d1ac3d92857a0a3b9ce51fb3d1a2d2b9849573597b5f3cdf64b34c26c90f29c9b841e1b5e5fe9672f0764ebcd9a0c95630
7
+ data.tar.gz: 448e39b6038ef926e3d95c3d1abe7d7927b3b5e86e8062ea0a7fbc61f33673eb46c8787668f7c41fb4b674fa1ed4c62b82eca9d0ff62741bc682054d513f6008
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ before_install:
6
6
  - rvm @global do gem uninstall -ax bundler
7
7
  - gem install bundler -v 1.5.3
8
8
  env:
9
- - VAGRANT_VERSION=v1.6.2
9
+ - VAGRANT_VERSION=v1.6.5
10
10
  matrix:
11
11
  include:
12
12
  - env: VAGRANT_VERSION=master
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.4.2 (September 12, 2014)
2
+
3
+ IMPROVEMENTS:
4
+
5
+ - Use Vagrant communicator interface for running remote commands [(#17)](https://github.com/emyl/vagrant-triggers/issues/17)
6
+ - Allow options to be overridden by a single command.
7
+
1
8
  ## 0.4.1 (June 20, 2014)
2
9
 
3
10
  BUG FIXES:
data/README.md CHANGED
@@ -46,7 +46,7 @@ The first argument is the command in which the trigger will be tied. It could be
46
46
  ### Options
47
47
 
48
48
  * ```:append_to_path => ["dir", "dir"]```: additional places where looking for scripts. See [this wiki page](https://github.com/emyl/vagrant-triggers/wiki/The-:append_to_path-option) for details.
49
- * ```:force => true```: continue even one of the scripts fails (exits with non-zero code)
49
+ * ```:force => true```: continue even if one of the scripts fails (exits with non-zero code)
50
50
  * ```:stdout => true```: display script output
51
51
  * ```:vm => ["vm1", /vm[2-3]/]```: fire only for matching virtual machines. Value can be a string, a regexp or an array of strings and/or regexps.
52
52
 
@@ -60,6 +60,19 @@ For additional details you can take a look to the [VagrantPlugins::Triggers::DSL
60
60
 
61
61
  Triggers won't run if ```VAGRANT_NO_TRIGGERS``` environment variable is set.
62
62
 
63
+ ## A simple example
64
+
65
+ Cleanup some temporary files after machine destroy:
66
+
67
+ ```ruby
68
+
69
+ Vagrant.configure("2") do |config|
70
+ config.trigger.after :destroy do
71
+ run "rm -Rf tmp/*"
72
+ end
73
+ end
74
+ ```
75
+
63
76
  ## A more detailed example
64
77
 
65
78
  In the following example a VirtualBox VM (not managed by Vagrant) will be tied to the machine defined in ```Vagrantfile```, to make so that it follows its lifecycle:
@@ -18,8 +18,8 @@ module VagrantPlugins
18
18
 
19
19
  def run(raw_command, options = {})
20
20
  info I18n.t("vagrant_triggers.action.trigger.executing_command", :command => raw_command)
21
- command = Shellwords.shellsplit(raw_command)
22
- env_backup = ENV.to_hash
21
+ command = Shellwords.shellsplit(raw_command)
22
+ env_backup = ENV.to_hash
23
23
  begin
24
24
  build_environment
25
25
  result = Vagrant::Util::Subprocess.execute(command[0], *command[1..-1])
@@ -28,18 +28,22 @@ module VagrantPlugins
28
28
  ensure
29
29
  ENV.replace(env_backup)
30
30
  end
31
- if result.exit_code != 0 && !@options[:force]
32
- raise Errors::CommandFailed, :command => raw_command, :stderr => result.stderr
33
- end
34
- if @options[:stdout]
35
- info I18n.t("vagrant_triggers.action.trigger.command_output", :output => result.stdout)
36
- end
37
- result.stdout
31
+ process_result(raw_command, result, @options.merge(options))
38
32
  end
39
33
  alias_method :execute, :run
40
34
 
41
35
  def run_remote(raw_command, options = {})
42
- run("vagrant ssh -c '#{raw_command}' #{@machine.name}", options)
36
+ info I18n.t("vagrant_triggers.action.trigger.executing_remote_command", :command => raw_command)
37
+ stderr = ""
38
+ stdout = ""
39
+ exit_code = @machine.communicate.sudo(raw_command, :elevated => true, :good_exit => (0..255).to_a) do |type, data|
40
+ if type == :stderr
41
+ stderr += data
42
+ elsif type == :stdout
43
+ stdout += data
44
+ end
45
+ end
46
+ process_result(raw_command, Vagrant::Util::Subprocess::Result.new(exit_code, stdout, stderr), @options.merge(options))
43
47
  end
44
48
  alias_method :execute_remote, :run_remote
45
49
 
@@ -75,6 +79,16 @@ module VagrantPlugins
75
79
  # Add the VAGRANT_NO_TRIGGERS variable to avoid loops
76
80
  ENV["VAGRANT_NO_TRIGGERS"] = "1"
77
81
  end
82
+
83
+ def process_result(command, result, options)
84
+ if result.exit_code != 0 && !options[:force]
85
+ raise Errors::CommandFailed, :command => command, :stderr => result.stderr
86
+ end
87
+ if options[:stdout]
88
+ info I18n.t("vagrant_triggers.action.trigger.command_output", :output => result.stdout)
89
+ end
90
+ result.stdout
91
+ end
78
92
  end
79
93
  end
80
94
  end
@@ -1,3 +1,5 @@
1
+ require "vagrant"
2
+
1
3
  # This is a sanity check to make sure no one is attempting to install
2
4
  # this into an early Vagrant version.
3
5
  if Vagrant::VERSION < "1.2.0"
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Triggers
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -9,6 +9,8 @@ en:
9
9
  ---------------
10
10
  executing_command: |-
11
11
  Executing command "%{command}"...
12
+ executing_remote_command: |-
13
+ Executing remote command "%{command}"...
12
14
  running_triggers: |-
13
15
  Running triggers %{condition} %{action}...
14
16
  errors:
@@ -150,11 +150,27 @@ describe VagrantPlugins::Triggers::DSL do
150
150
  end
151
151
  end
152
152
 
153
- context "run_remote" do
154
- it "should generate a 'vagrant ssh -c' command" do
155
- machine.stub(:name => "vm1")
156
- @dsl.should_receive(:run).with("vagrant ssh -c '#{@command}' vm1", {})
157
- @dsl.run_remote(@command, {})
153
+ context "run a remote command" do
154
+ before do
155
+ Vagrant::Util::Subprocess::Result.stub(:new => result)
156
+ machine.stub_chain(:communicate, :sudo).and_return(0)
157
+ end
158
+
159
+ it "should raise an error if executed command exits with non-zero code" do
160
+ result.stub(:exit_code => 1)
161
+ expect { @dsl.run_remote(@command) }.to raise_error(VagrantPlugins::Triggers::Errors::CommandFailed)
162
+ end
163
+
164
+ it "shouldn't raise an error if executed command exits with non-zero code but :force option was specified" do
165
+ dsl = described_class.new(ui, machine, :force => true)
166
+ result.stub(:exit_code => 1)
167
+ expect { dsl.run_remote(@command) }.not_to raise_error()
168
+ end
169
+
170
+ it "should display output if :stdout option was specified" do
171
+ dsl = described_class.new(ui, machine, :stdout => true)
172
+ ui.should_receive(:info).with(/Some output/)
173
+ dsl.run_remote(@command)
158
174
  end
159
175
  end
160
176
  end
@@ -50,5 +50,5 @@ Gem::Specification.new do |spec|
50
50
 
51
51
  spec.add_development_dependency "bundler", "~> 1.3"
52
52
  spec.add_development_dependency "rake"
53
- spec.add_development_dependency "rspec"
53
+ spec.add_development_dependency "rspec", "< 3"
54
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-triggers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Ticci
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - <
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - <
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3'
55
55
  description: This plugin allow the definition of arbitrary scripts that will run on
56
56
  the host before and/or after Vagrant commands.
57
57
  email: emiticci@gmail.com