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 support for providing watches/checks/services via hiera #72

Merged
merged 2 commits into from
Jan 22, 2015
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
18 changes: 18 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@
$service_enable = true,
$service_ensure = 'running',
$init_style = $consul::params::init_style,
$services = {},
$watches = {},
$checks = {},
) inherits consul::params {

validate_bool($purge_config_dir)
validate_bool($manage_user)
validate_hash($config_hash)
validate_hash($config_defaults)
validate_hash($services)
validate_hash($watches)
validate_hash($checks)

$_config_hash = merge($config_defaults, $config_hash)
validate_hash($_config_hash)
Expand All @@ -84,6 +90,18 @@
warning('data_dir must be set to install consul web ui')
}

if $services {
create_resources(consul::service, $services)
}

if $watches {
create_resources(consul::watch, $watches)
}

if $checks {
create_resources(consul::check, $checks)
}

class { 'consul::install': } ->
class { 'consul::config':
config_hash => $_config_hash,
Expand Down
43 changes: 43 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,49 @@
it { should contain_file('/etc/init/consul.conf').with_content(/sudo -u custom_consul_user -g custom_consul_group/) }
end

context "When the user provides a hash of services" do
let (:params) {{
:services => {
'test_service1' => {
'port' => '5'
}
}
}}

it { should contain_consul__service('test_service1').with_port('5') }
it { should have_consul__service_resource_count(1) }
end

context "When the user provides a hash of watches" do
let (:params) {{
:watches => {
'test_watch1' => {
'type' => 'nodes',
'handler' => 'test.sh',
}
}
}}

it { should contain_consul__watch('test_watch1').with_type('nodes') }
it { should contain_consul__watch('test_watch1').with_handler('test.sh') }
it { should have_consul__watch_resource_count(1) }
end

context "When the user provides a hash of watches" do
let (:params) {{
:checks => {
'test_check1' => {
'interval' => '30',
'script' => 'test.sh',
}
}
}}

it { should contain_consul__check('test_check1').with_interval('30') }
it { should contain_consul__check('test_check1').with_script('test.sh') }
it { should have_consul__check_resource_count(1) }
end

context "On a redhat 6 based OS" do
let(:facts) {{
:operatingsystem => 'CentOS',
Expand Down