guard-puppet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Reapply your Puppet configs automatically using Guard! Awesome!
2
2
 
3
3
  ``` ruby
4
- guard 'puppet', :verbose => true, :manifest => 'manifests/site.pp' do
4
+ guard 'puppet' do
5
5
  watch(%r{^(manifests|modules)})
6
6
  end
7
7
  ```
@@ -10,9 +10,10 @@ It's assumed your configs are all in the current folder, which is the
10
10
  equivalent of `--confdir=$PWD` at the command line. Otherwise,
11
11
  there's not much use of using Guard with Puppet. :)
12
12
 
13
- Two options so far:
13
+ Three options so far:
14
14
 
15
15
  * `:verbose`: Show more output from Puppet (default: `true`)
16
+ * `:debug`: Show even more output from Puppet (default: `false`)
16
17
  * `:manifest`: The main manifest file to run (default: `manifests/site.pp`)
17
18
 
18
19
  Bugs and fixes? You know the drill.
@@ -9,6 +9,8 @@ module ::Guard
9
9
  def initialize(watchers = [], options = {})
10
10
  super
11
11
  @options = options
12
+
13
+ UI.info "Guard::Puppet is watching for changes..."
12
14
  end
13
15
 
14
16
  def run_all
@@ -0,0 +1,24 @@
1
+ module Puppet; end
2
+
3
+ require 'puppet/util'
4
+ require 'puppet/util/log'
5
+
6
+ ::Puppet::Util::Log.newdesttype :guard do
7
+ attr_reader :messages
8
+
9
+ def initialize
10
+ close
11
+ end
12
+
13
+ def handle(msg)
14
+ @messages << msg
15
+ end
16
+
17
+ def close
18
+ @messages = []
19
+ end
20
+
21
+ def has_failed?
22
+ messages.find { |msg| (::Puppet::Util::Log.levels.index(msg.level)) >= 4 }
23
+ end
24
+ end
@@ -1,6 +1,7 @@
1
1
  require 'guard/puppet'
2
2
  require 'puppet/util/command_line'
3
3
  require 'puppet/application/apply'
4
+ require 'guard/puppet/log'
4
5
 
5
6
  module Guard
6
7
  class Puppet
@@ -12,21 +13,48 @@ module Guard
12
13
  :verbose => true,
13
14
  :manifest => 'manifests/site.pp'
14
15
  }.merge(options)
16
+
15
17
  end
16
18
 
17
19
  def run
18
- ::Puppet::Util::CommandLine.new('puppet', command_line_params).execute
19
- 0
20
- rescue SystemExit => e
21
- e.status
20
+ messages = ::Puppet::Util::Log.newdestination(:guard)
21
+
22
+ begin
23
+ maybe_bundle_with_env do
24
+ ::Puppet::Util::CommandLine.new('puppet', command_line_params).execute
25
+ end
26
+ 0
27
+ rescue SystemExit => e
28
+ if e.status == 0
29
+ if messages.has_failed?
30
+ 1
31
+ else
32
+ 0
33
+ end
34
+ else
35
+ e.status
36
+ end
37
+ ensure
38
+ ::Puppet::Util::Log.close(:guard)
39
+ end
22
40
  end
23
41
 
24
42
  def command_line_params
25
43
  command = [ "apply", %{--confdir="#{Dir.pwd}"} ]
26
44
  command << "-v" if @options[:verbose]
45
+ command << "-d" if @options[:debug]
27
46
  command << @options[:manifest] if @options[:manifest]
28
47
  command
29
48
  end
49
+
50
+ private
51
+ def maybe_bundle_with_env(&block)
52
+ if defined?(::Bundler)
53
+ Bundler.with_clean_env(&block)
54
+ else
55
+ yield
56
+ end
57
+ end
30
58
  end
31
59
  end
32
60
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module PuppetVersion
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'guard/puppet/log'
3
+ require 'puppet/util/log'
4
+
5
+ describe 'guard logging for puppet' do
6
+ let(:guard) { ::Puppet::Util::Log.destinations[:guard] }
7
+
8
+ before do
9
+ ::Puppet::Util::Log.newdestination(:guard)
10
+ end
11
+
12
+ it 'should receive a message' do
13
+ guard.handle("test")
14
+ guard.messages.should == [ "test" ]
15
+ end
16
+
17
+ it 'should not be a failure' do
18
+ guard.handle(stub(:level => :info))
19
+ guard.should_not have_failed
20
+ end
21
+
22
+ it 'should be a failure' do
23
+ guard.handle(stub(:level => :err))
24
+ guard.should have_failed
25
+ end
26
+
27
+ after do
28
+ ::Puppet::Util::Log.close(:guard)
29
+ end
30
+ end
@@ -23,13 +23,42 @@ describe Guard::Puppet::Runner do
23
23
 
24
24
  it { should == [ 'apply', %{--confdir="#{Dir.pwd}"}, '-v', '123' ] }
25
25
  end
26
+
27
+ context 'debug' do
28
+ let(:options) { { :debug => true} }
29
+
30
+ it { should == [ 'apply', %{--confdir="#{Dir.pwd}"}, '-v', '-d', 'manifests/site.pp' ] }
31
+ end
26
32
  end
27
33
 
28
34
  describe '#run' do
29
- it 'should return the result of an exit call' do
30
- ::Puppet::Util::CommandLine.expects(:new).raises(SystemExit.new(10))
35
+ before do
36
+ ::Puppet::Util::CommandLine.expects(:new).raises(SystemExit.new(return_value))
37
+ end
38
+
39
+ context 'returns a non-zero value' do
40
+ let(:return_value) { 10 }
41
+
42
+ it 'should return the result of an exit call' do
43
+ runner.run.should == return_value
44
+ end
45
+ end
46
+
47
+ context 'returns a zero value' do
48
+ let(:return_value) { 0 }
49
+ let(:messages) do
50
+ messages = stub
51
+ messages.stubs(:has_failed?).returns(true)
52
+ messages
53
+ end
54
+
55
+ before do
56
+ Puppet::Util::Log.stubs(:newdestination).returns(messages)
57
+ end
31
58
 
32
- runner.run.should == 10
59
+ it 'should check the status of the messages output' do
60
+ runner.run.should == 1
61
+ end
33
62
  end
34
63
  end
35
64
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: guard-puppet
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bintz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-05 00:00:00 -04:00
13
+ date: 2011-07-06 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -74,9 +74,11 @@ files:
74
74
  - Rakefile
75
75
  - guard-puppet.gemspec
76
76
  - lib/guard/puppet.rb
77
+ - lib/guard/puppet/log.rb
77
78
  - lib/guard/puppet/runner.rb
78
79
  - lib/guard/puppet/templates/Guardfile
79
80
  - lib/guard/puppet/version.rb
81
+ - spec/lib/guard/puppet/log_spec.rb
80
82
  - spec/lib/guard/puppet/runner_spec.rb
81
83
  - spec/lib/guard/puppet_spec.rb
82
84
  - spec/spec_helper.rb
@@ -109,6 +111,7 @@ signing_key:
109
111
  specification_version: 3
110
112
  summary: Reapply Puppet configs automatically using Guard.
111
113
  test_files:
114
+ - spec/lib/guard/puppet/log_spec.rb
112
115
  - spec/lib/guard/puppet/runner_spec.rb
113
116
  - spec/lib/guard/puppet_spec.rb
114
117
  - spec/spec_helper.rb