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

Add args parameter to consul::watch #404

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions manifests/watch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
# Name of an event to watch for.
#
# [*handler*]
# Full path to the script that will be excuted.
# Full path to the script that will be excuted. This parameter is deprecated
# in Consul 1.0.0, see https://github.com/hashicorp/consul/issues/3509.
#
# [*args*]
# Arguments to be `exec`ed for the watch.
#
# [*key*]
# Watch a specific key.
Expand Down Expand Up @@ -44,6 +48,7 @@
# Type of data to watch. (Like key, service, services, nodes)
#
define consul::watch(
$args = undef,
$datacenter = undef,
$ensure = present,
$event_name = undef,
Expand All @@ -62,6 +67,7 @@

$basic_hash = {
'type' => $type,
'args' => $args,
'handler' => $handler,
'datacenter' => $datacenter,
'token' => $token,
Expand All @@ -71,8 +77,12 @@
fail ('Watches are only supported in Consul 0.4.0 and above')
}

if (! $handler ) {
fail ('All watch conditions must have a handler defined')
if (! $handler and ! $args) {
fail ('All watch conditions must have a handler or args list defined')
}

if ($handler and $args) {
fail ('Watch conditions cannot have both a handler and args list defined')
}

if (! $type ) {
Expand Down
23 changes: 23 additions & 0 deletions spec/defines/consul_watch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@
}
end

describe 'with valid type and args' do
let(:params) {{
'type' => 'nodes',
'args' => ['sh', '-c', 'true'],
}}
it {
should contain_file('/etc/consul/watch_my_watch.json') \
.with_content(/"args" *: *\[ *"sh", *"-c", *"true" *\]/) \
.with_content(/"type" *: *"nodes"/)
}
end

describe 'with both args and handler' do
let(:params) {{
'type' => 'nodes',
'handler' => 'handler_path',
'args' => ['sh', '-c', 'true'],
}}
it {
expect { should raise_error(Puppet::Error)}
}
end

describe 'global attributes' do
let (:params) {{
'type' => 'nodes',
Expand Down