chef-handler-serf 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +7 -0
- data/chef-handler-serf.gemspec +1 -1
- data/lib/chef/event_dispatch/serf.rb +19 -6
- data/spec/serf_handler_spec.rb +46 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bdcb572b6968268fdd7848893a7ee2cddfef682
|
4
|
+
data.tar.gz: 606b9c8bd900a3d9aeb10269d156397ed0edf3fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0e0d76a9b197d6ec3ec27df1a20f831c7d03b9efede3c1a28233c15730f2d991019af2d63ecfc9de0ec326033eb3b617ff7e3f2aa9c45f18f4c3edf63fb8890
|
7
|
+
data.tar.gz: 4a7ac97dd4be2a1f1219afd0fbab84f8d5e29ad994d169cb725a14de29b1d7384001f188c049bbdd68c89bdbc990f16f50013e9b6806eac31cb8da26775353ca
|
data/README.md
CHANGED
@@ -40,6 +40,13 @@ run
|
|
40
40
|
|
41
41
|
```
|
42
42
|
|
43
|
+
### Additional Options
|
44
|
+
chef handler for serf can be configured to ignore failures when serf node
|
45
|
+
is down (Errno::ECONNREFUSED).
|
46
|
+
```ruby
|
47
|
+
event_handlers << Chef::EventDispatch::Serf.new(ignore_failure: true)
|
48
|
+
```
|
49
|
+
|
43
50
|
Resource updated events can also be published as serf events using the
|
44
51
|
`publish` meta attribute, introduced by _chef-handler-serf_.
|
45
52
|
|
data/chef-handler-serf.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'chef-handler-serf'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.4'
|
8
8
|
spec.authors = ['Ranjib Dey']
|
9
9
|
spec.email = ['ranjib@pagerduty.com']
|
10
10
|
spec.summary = %q{Chef event handler for serf}
|
@@ -23,32 +23,45 @@ class Chef
|
|
23
23
|
def initialize(options = {})
|
24
24
|
@subscribe = options.delete(:subscribe) || []
|
25
25
|
@publish_all = options.delete(:publish_all) || false
|
26
|
-
@
|
26
|
+
@ignore_failure = options.delete(:ignore_failure)
|
27
|
+
@conn_opts = options.dup
|
27
28
|
end
|
28
29
|
|
29
30
|
def run_start(version)
|
30
31
|
payload = payload_to_json(version: version)
|
31
|
-
|
32
|
+
serf_event(__method__.to_s, payload)
|
32
33
|
end
|
33
34
|
|
34
35
|
def converge_complete
|
35
|
-
|
36
|
-
@conn.close unless @conn.closed?
|
36
|
+
serf_event(__method__.to_s, payload_to_json)
|
37
37
|
end
|
38
38
|
|
39
39
|
def resource_updated(res, action)
|
40
40
|
if @publish_all or @subscribe.include?(res.to_s) or res.publish
|
41
41
|
payload = payload_to_json(resource: res.to_s, action: action.to_s)
|
42
|
-
|
42
|
+
serf_event(__method__.to_s, payload)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
private
|
47
46
|
def payload_to_json(data = {})
|
48
47
|
Chef::JSONCompat.to_json(
|
49
48
|
data.merge(node: Chef::Config[:node_name])
|
50
49
|
)
|
51
50
|
end
|
51
|
+
|
52
|
+
def serf_event(*args)
|
53
|
+
begin
|
54
|
+
Serfx.connect(@conn_opts) do |conn|
|
55
|
+
conn.event(*args)
|
56
|
+
end
|
57
|
+
rescue Errno::ECONNREFUSED => e
|
58
|
+
if @ignore_failure
|
59
|
+
Chef::Log.warn("Failed to publish event in serf: #{e.message}")
|
60
|
+
else
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
52
65
|
end
|
53
66
|
end
|
54
67
|
end
|
data/spec/serf_handler_spec.rb
CHANGED
@@ -3,19 +3,38 @@ require 'chef'
|
|
3
3
|
require 'chef/event_dispatch/serf'
|
4
4
|
|
5
5
|
describe 'serf handler' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
before(:each) do
|
7
|
+
Chef::Config[:event_handlers].clear
|
8
|
+
end
|
9
|
+
let(:pass_payload) do
|
10
|
+
Chef::JSONCompat.to_json(
|
11
|
+
resource: 'execute[pass]',
|
12
|
+
action: 'run',
|
13
|
+
node: Chef::Config[:node_name]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
let(:fail_payload) do
|
17
|
+
Chef::JSONCompat.to_json(
|
18
|
+
resource: 'execute[fail]',
|
19
|
+
action: 'run',
|
20
|
+
node: Chef::Config[:node_name]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
let(:recipe) do
|
11
24
|
Chef::Config[:solo] = true
|
12
|
-
Chef::Config[:event_handlers] << handler
|
13
25
|
client = Chef::Client.new
|
14
26
|
client.run_ohai
|
15
27
|
client.load_node
|
16
28
|
client.build_node
|
17
29
|
rc = Chef::RunContext.new(client.node, {}, client.events)
|
18
|
-
|
30
|
+
rec = Chef::Recipe.new('spec', 'serf', rc)
|
31
|
+
rec
|
32
|
+
end
|
33
|
+
it 'should publish an event in serf' do
|
34
|
+
conn = double(Serfx::Connection)
|
35
|
+
allow(Serfx).to receive(:connect).with({}).and_yield(conn)
|
36
|
+
handler = Chef::EventDispatch::Serf.new
|
37
|
+
Chef::Config[:event_handlers] << handler
|
19
38
|
recipe.instance_eval do
|
20
39
|
execute 'pass' do
|
21
40
|
command 'echo HelloWorld'
|
@@ -25,24 +44,29 @@ describe 'serf handler' do
|
|
25
44
|
command 'echo HelloWorld'
|
26
45
|
end
|
27
46
|
end
|
28
|
-
|
29
|
-
runner = Chef::Runner.new(rc)
|
30
|
-
|
31
|
-
pass_payload = Chef::JSONCompat.to_json(
|
32
|
-
resource: 'execute[pass]',
|
33
|
-
action: 'run',
|
34
|
-
node: Chef::Config[:node_name]
|
35
|
-
)
|
36
|
-
|
37
|
-
fail_payload = Chef::JSONCompat.to_json(
|
38
|
-
resource: 'execute[fail]',
|
39
|
-
action: 'run',
|
40
|
-
node: Chef::Config[:node_name]
|
41
|
-
)
|
42
|
-
|
47
|
+
runner = Chef::Runner.new(recipe.run_context)
|
43
48
|
expect(conn).to receive(:event).with('resource_updated', pass_payload)
|
44
49
|
expect(conn).to_not receive(:event).with('resource_updated', fail_payload)
|
45
50
|
runner.converge
|
46
51
|
end
|
52
|
+
it 'should not explode if serf is down and ignore_failure is set' do
|
53
|
+
conn = double(Serfx::Connection)
|
54
|
+
allow(Serfx).to receive(:connect).with({}).and_raise(Errno::ECONNREFUSED)
|
55
|
+
handler = Chef::EventDispatch::Serf.new(ignore_failure: true)
|
56
|
+
Chef::Config[:event_handlers] << handler
|
57
|
+
recipe.instance_eval do
|
58
|
+
execute 'pass' do
|
59
|
+
command 'echo HelloWorld'
|
60
|
+
publish true
|
61
|
+
end
|
62
|
+
execute 'fail' do
|
63
|
+
command 'echo HelloWorld'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
runner = Chef::Runner.new(recipe.run_context)
|
67
|
+
expect do
|
68
|
+
runner.converge
|
69
|
+
end.to_not raise_error
|
70
|
+
end
|
47
71
|
end
|
48
72
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-handler-serf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ranjib Dey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|