vagrant-triggers 0.5.2 → 0.5.3

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: 2fc9e72e96c859d7a51666232ac6616d94ab1bad
4
- data.tar.gz: 9a6582a7dba4fcf707ea943f33d1c3dd143a3a3f
3
+ metadata.gz: 143df3dafe6617342eeea922dee510ade4fc69f0
4
+ data.tar.gz: 92cf760b6937957927f66aa6d29a12b48c128e07
5
5
  SHA512:
6
- metadata.gz: 4894efdbaa8bfadcafa9b681c5c165bccd9a8c172181874c9b627cbe9c554c8c4f2cd2da3708cb479d5e232fc9c510707a705c417f9b4f27c0f1c0a09cec29f0
7
- data.tar.gz: b1420068c5d83aa1b67fe2958d13a20fe4305820194e1c8428744fb5d01f6d342c517fbd45e5a37052cb664015933aba1f77f4015ebf0973e443f7255ffde6d4
6
+ metadata.gz: e707bffcb9a263a74c760c6d7e4f7b1f3b802562c544ffc01b0dbc0838436ec4c4aeb90d9778a5627d7a088fa0e02bd7f11f5dbe0e3ad38535ae8ed8c223ada1
7
+ data.tar.gz: 99b49229d13930918cc02cc3060493ecba6930c6ad5a0d33b856836c5700676b9d7cfd80be6fdbd4d4655b78eb89d6937431866557a5e4cf8fa0dbfb4c381f65
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.2.3
4
4
  before_install:
5
5
  - gem update --system
6
6
  - rvm @global do gem uninstall -ax bundler
@@ -10,10 +10,12 @@ env:
10
10
  global:
11
11
  - SPEC_OPTS="--tag ~skip_travis"
12
12
  matrix:
13
- - VAGRANT_VERSION=v1.7.4
13
+ - VAGRANT_VERSION=v1.8.1
14
14
  matrix:
15
15
  include:
16
16
  - env: VAGRANT_VERSION=master
17
+ rvm: 2.2.3
18
+ - env: VAGRANT_VERSION=v1.7.4
17
19
  rvm: 2.0.0
18
20
  - env: VAGRANT_VERSION=v1.6.5
19
21
  rvm: 2.0.0
@@ -27,5 +29,5 @@ matrix:
27
29
  rvm: 1.9.3
28
30
  allow_failures:
29
31
  - env: VAGRANT_VERSION=master
30
- rvm: 2.0.0
32
+ rvm: 2.2.3
31
33
  sudo: false
@@ -1,3 +1,13 @@
1
+ ## 0.5.3 (April 9, 2016)
2
+
3
+ IMPROVEMENTS:
4
+
5
+ - Add ```:good_exit``` option for specifying custom positive exit codes [(#37)](https://github.com/emyl/vagrant-triggers/issues/37)
6
+
7
+ BUG FIXES:
8
+
9
+ - Gracefully catch communication errors [(#55)](https://github.com/emyl/vagrant-triggers/issues/55)
10
+
1
11
  ## 0.5.2 (September 9, 2015)
2
12
 
3
13
  BUG FIXES:
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/emyl/vagrant-triggers.png?branch=master)](https://travis-ci.org/emyl/vagrant-triggers)
4
4
 
5
- Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
5
+ Allow the definition of arbitrary scripts that will run on the host or guest before and/or after Vagrant commands.
6
6
 
7
7
  ## Installation
8
8
 
@@ -13,9 +13,33 @@ Installation is performed in the prescribed manner for Vagrant plugins:
13
13
 
14
14
  $ vagrant plugin install vagrant-triggers
15
15
 
16
- ## Usage
16
+ ## Example Usage
17
17
 
18
- ### Basic usage
18
+ ```ruby
19
+ Vagrant.configure("2") do |config|
20
+ # Your existing Vagrant configuration
21
+ ...
22
+
23
+ # run some script before the guest is destroyed
24
+ config.trigger.before :destroy do
25
+ info "Dumping the database before destroying the VM..."
26
+ run_remote "bash /vagrant/cleanup.sh"
27
+ end
28
+
29
+ # clean up files on the host after the guest is destroyed
30
+ config.trigger.after :destroy do
31
+ run "rm -Rf tmp/*"
32
+ end
33
+
34
+ # start apache on the guest after the guest starts
35
+ config.trigger.after :up do
36
+ run_remote "service apache2 start"
37
+ end
38
+
39
+ end
40
+ ```
41
+
42
+ ## Syntax Overview
19
43
 
20
44
  ```ruby
21
45
  Vagrant.configure("2") do |config|
@@ -62,6 +86,7 @@ end
62
86
 
63
87
  * ```: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.
64
88
  * ```:force => true|false```: continue even if one of the scripts fails (exits with non-zero code). Defaults to false.
89
+ * ```:good_exit => [ ... ]```: good command exit codes. Defaults to ```[0]```. **Don't forget to include 0 if you change the default value, unless you really want**.
65
90
  * ```:stderr => true|false```: display standard error from scripts. Defaults to true.
66
91
  * ```:stdout => true|false```: display standard output from scripts. Defaults to true.
67
92
  * ```: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.
@@ -103,17 +128,7 @@ end
103
128
 
104
129
  Multiple commands can be blacklisted using an array.
105
130
 
106
- ## A simple example
107
-
108
- Cleanup some temporary files after machine destroy:
109
131
 
110
- ```ruby
111
- Vagrant.configure("2") do |config|
112
- config.trigger.after :destroy do
113
- run "rm -Rf tmp/*"
114
- end
115
- end
116
- ```
117
132
 
118
133
  ## A more detailed example
119
134
 
@@ -49,15 +49,7 @@ module VagrantPlugins
49
49
  end
50
50
 
51
51
  triggers_to_fire.each do |trigger|
52
- if trigger[:proc]
53
- begin
54
- dsl = DSL.new(@env[:machine], trigger[:options])
55
- dsl.instance_eval &trigger[:proc]
56
- rescue Errors::NotMatchingMachine
57
- end
58
- else
59
- @logger.debug("Trigger command not found.")
60
- end
52
+ DSL.fire!(trigger, @env[:machine])
61
53
  end
62
54
  end
63
55
 
@@ -7,8 +7,9 @@ module VagrantPlugins
7
7
 
8
8
  def initialize
9
9
  @options = {
10
- :stderr => true,
11
- :stdout => true
10
+ :good_exit => [0],
11
+ :stderr => true,
12
+ :stdout => true
12
13
  }
13
14
  end
14
15
 
@@ -6,7 +6,7 @@ module VagrantPlugins
6
6
 
7
7
  def initialize
8
8
  @blacklist = []
9
- @options = { :stdout => true, :stderr => true }
9
+ @options = { :good_exit => [0], :stderr => true, :stdout => true }
10
10
  @triggers = []
11
11
  end
12
12
 
@@ -5,6 +5,14 @@ require "vagrant/util/subprocess"
5
5
  module VagrantPlugins
6
6
  module Triggers
7
7
  class DSL
8
+ def self.fire!(trigger, machine)
9
+ begin
10
+ dsl = new(machine, trigger[:options])
11
+ dsl.instance_eval &trigger[:proc] if trigger[:proc]
12
+ rescue Errors::NotMatchingMachine
13
+ end
14
+ end
15
+
8
16
  def initialize(machine, options = {})
9
17
  if options[:vm]
10
18
  match = false
@@ -17,7 +25,7 @@ module VagrantPlugins
17
25
  @buffer = Hash.new("")
18
26
  @logger = Log4r::Logger.new("vagrant::plugins::triggers::dsl")
19
27
  @machine = machine
20
- @options = options
28
+ @options = { :good_exit => [0] }.merge(options)
21
29
  @ui = machine.ui
22
30
 
23
31
  @command_output = lambda do |channel, data, options|
@@ -53,7 +61,7 @@ module VagrantPlugins
53
61
  ensure
54
62
  ENV.replace(env_backup)
55
63
  end
56
- process_result(raw_command, result, options)
64
+ process_result("local", raw_command, result, options)
57
65
  end
58
66
  alias_method :execute, :run
59
67
 
@@ -61,11 +69,16 @@ module VagrantPlugins
61
69
  options.merge!(@options) { |key, old, new| old }
62
70
  info I18n.t("vagrant_triggers.action.trigger.executing_remote_command", :command => raw_command)
63
71
  @buffer.clear
64
- exit_code = @machine.communicate.sudo(raw_command, :elevated => true, :good_exit => (0..255).to_a) do |channel, data|
65
- @command_output.call(channel, data, options)
72
+ exit_code = 1
73
+ begin
74
+ exit_code = @machine.communicate.sudo(raw_command, :elevated => true, :good_exit => (0..255).to_a) do |channel, data|
75
+ @command_output.call(channel, data, options)
76
+ end
77
+ rescue => e
78
+ @command_output.call(:stderr, e.message, options)
66
79
  end
67
80
  info I18n.t("vagrant_triggers.action.trigger.remote_command_finished")
68
- process_result(raw_command, Vagrant::Util::Subprocess::Result.new(exit_code, @buffer[:stdout], @buffer[:stderr]), options)
81
+ process_result("remote", raw_command, Vagrant::Util::Subprocess::Result.new(exit_code, @buffer[:stdout], @buffer[:stderr]), options)
69
82
  end
70
83
  alias_method :execute_remote, :run_remote
71
84
 
@@ -101,9 +114,9 @@ module VagrantPlugins
101
114
  ENV["VAGRANT_SKIP_SUBPROCESS_JAILBREAK"] = "1"
102
115
  end
103
116
 
104
- def process_result(command, result, options)
105
- if result.exit_code != 0 && !options[:force]
106
- raise Errors::CommandFailed, :command => command, :stderr => result.stderr
117
+ def process_result(context, command, result, options)
118
+ unless options[:good_exit].include?(result.exit_code) || options[:force]
119
+ raise Errors::CommandFailed, :context => context, :command => command, :stderr => result.stderr
107
120
  end
108
121
  result.stdout
109
122
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Triggers
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  end
5
5
  end
@@ -14,8 +14,8 @@ en:
14
14
  Running triggers %{condition} %{action}...
15
15
  errors:
16
16
  command_failed: |-
17
- The command "%{command}" returned a failed exit code. The
18
- error output is shown below:
17
+ The %{context} command "%{command}" returned a failed exit
18
+ code or an exception. The error output is shown below:
19
19
 
20
20
  %{stderr}
21
21
  command_unavailable: |-
@@ -57,7 +57,8 @@ describe VagrantPlugins::Triggers::Action::Trigger do
57
57
 
58
58
  it "shouldn't execute trigger with no command or block" do
59
59
  @triggers[0][:proc] = nil
60
- VagrantPlugins::Triggers::DSL.should_not_receive(:new)
60
+ dsl = double("dsl")
61
+ dsl.should_not_receive(:instance_eval)
61
62
  described_class.new(app, env, condition).call(env)
62
63
  end
63
64
 
@@ -4,13 +4,17 @@ describe VagrantPlugins::Triggers::Config::Provisioner do
4
4
  let(:config) { described_class.new }
5
5
 
6
6
  describe "defaults" do
7
- it "should default :stdout option to true" do
8
- expect(config.options[:stdout]).to be true
7
+ it "should default :good_exit option to [0]" do
8
+ expect(config.options[:good_exit]).to eq([0])
9
9
  end
10
10
 
11
11
  it "should default :stderr option to true" do
12
12
  expect(config.options[:stderr]).to be true
13
13
  end
14
+
15
+ it "should default :stdout option to true" do
16
+ expect(config.options[:stdout]).to be true
17
+ end
14
18
  end
15
19
 
16
20
  describe "fire" do
@@ -12,9 +12,9 @@ describe VagrantPlugins::Triggers::Config::Trigger do
12
12
  expect(config.triggers).to eq([])
13
13
  end
14
14
 
15
- it "should default :stdout option to true" do
15
+ it "should default :good_exit option to [0]" do
16
16
  config.before(:up) { run "ls" }
17
- expect(config.triggers.first[:options][:stdout]).to eq(true)
17
+ expect(config.triggers.first[:options][:good_exit]).to eq([0])
18
18
  end
19
19
 
20
20
  it "should default :stderr option to true" do
@@ -22,7 +22,22 @@ describe VagrantPlugins::Triggers::Config::Trigger do
22
22
  expect(config.triggers.first[:options][:stderr]).to eq(true)
23
23
  end
24
24
 
25
- it "should override options" do
25
+ it "should default :stdout option to true" do
26
+ config.before(:up) { run "ls" }
27
+ expect(config.triggers.first[:options][:stdout]).to eq(true)
28
+ end
29
+
30
+ it "should override :good_exit option" do
31
+ config.before(:up, :good_exit => [0, 2]) { run "ls" }
32
+ expect(config.triggers.first[:options][:good_exit]).to eq([0, 2])
33
+ end
34
+
35
+ it "should override :stderr option" do
36
+ config.before(:up, :stderr => false) { run "ls" }
37
+ expect(config.triggers.first[:options][:stderr]).to eq(false)
38
+ end
39
+
40
+ it "should override :stdout option" do
26
41
  config.before(:up, :stdout => false) { run "ls" }
27
42
  expect(config.triggers.first[:options][:stdout]).to eq(false)
28
43
  end
@@ -93,6 +93,12 @@ describe VagrantPlugins::Triggers::DSL do
93
93
  expect { dsl.run(@command) }.not_to raise_error()
94
94
  end
95
95
 
96
+ it "shouldn't raise an error if executed command exits with non-zero code but the code is included in the :good_exit array" do
97
+ dsl = described_class.new(machine, :good_exit => [0, 2])
98
+ result.stub(:exit_code => 2)
99
+ expect { dsl.run(@command) }.not_to raise_error()
100
+ end
101
+
96
102
  it "should return standard output" do
97
103
  dsl = described_class.new(machine)
98
104
  expect(dsl.run(@command)).to eq("Some output")
@@ -228,12 +234,24 @@ describe VagrantPlugins::Triggers::DSL do
228
234
  expect { @dsl.run_remote(@command) }.to raise_error(VagrantPlugins::Triggers::Errors::CommandFailed)
229
235
  end
230
236
 
237
+ it "should catch communication errors and raise a proper exception" do
238
+ machine.stub_chain(:communicate, :sudo).and_raise(StandardError)
239
+ result.stub(:exit_code => 1)
240
+ expect { @dsl.run_remote(@command) }.to raise_error(VagrantPlugins::Triggers::Errors::CommandFailed)
241
+ end
242
+
231
243
  it "shouldn't raise an error if executed command exits with non-zero code but :force option was specified" do
232
244
  dsl = described_class.new(machine, :force => true)
233
245
  result.stub(:exit_code => 1)
234
246
  expect { dsl.run_remote(@command) }.not_to raise_error()
235
247
  end
236
248
 
249
+ it "shouldn't raise an error if executed command exits with non-zero code but the code is included in the :good_exit array" do
250
+ dsl = described_class.new(machine, :good_exit => [0, 2])
251
+ result.stub(:exit_code => 2)
252
+ expect { dsl.run_remote(@command) }.not_to raise_error()
253
+ end
254
+
237
255
  it "should return standard output" do
238
256
  dsl = described_class.new(machine)
239
257
  expect(dsl.run_remote(@command)).to eq("Some output")
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-triggers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Ticci
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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
54
  version: '0'
55
55
  description: This plugin allow the definition of arbitrary scripts that will run on
@@ -59,23 +59,25 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
62
64
  - CHANGELOG.md
63
65
  - Gemfile
64
- - lib/vagrant-triggers/action/trigger.rb
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/vagrant-triggers.rb
65
70
  - lib/vagrant-triggers/action.rb
71
+ - lib/vagrant-triggers/action/trigger.rb
72
+ - lib/vagrant-triggers/config.rb
66
73
  - lib/vagrant-triggers/config/provisioner.rb
67
74
  - lib/vagrant-triggers/config/trigger.rb
68
- - lib/vagrant-triggers/config.rb
69
75
  - lib/vagrant-triggers/dsl.rb
70
76
  - lib/vagrant-triggers/errors.rb
71
77
  - lib/vagrant-triggers/plugin.rb
72
78
  - lib/vagrant-triggers/provisioner.rb
73
79
  - lib/vagrant-triggers/version.rb
74
- - lib/vagrant-triggers.rb
75
- - LICENSE.txt
76
80
  - locales/en.yml
77
- - Rakefile
78
- - README.md
79
81
  - spec/spec_helper.rb
80
82
  - spec/vagrant-triggers/action/trigger_spec.rb
81
83
  - spec/vagrant-triggers/config/provisioner_spec.rb
@@ -84,8 +86,6 @@ files:
84
86
  - spec/vagrant-triggers/provisioner_spec.rb
85
87
  - spec/vagrant-triggers/vagrant_spec.rb
86
88
  - vagrant-triggers.gemspec
87
- - .gitignore
88
- - .travis.yml
89
89
  homepage: https://github.com/emyl/vagrant-triggers
90
90
  licenses:
91
91
  - MIT
@@ -96,17 +96,17 @@ require_paths:
96
96
  - lib
97
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - '>='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.0.14
109
+ rubygems_version: 2.4.5.1
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Triggers for Vagrant commands.