From 5e29ce197611f886f3acdc17a74a57bf7da65f24 Mon Sep 17 00:00:00 2001 From: Graham Taylor Date: Thu, 22 Jan 2015 12:09:05 +0000 Subject: [PATCH 1/2] Add support for providing watches/checks/services via hiera into the consul class --- manifests/init.pp | 18 +++++++++++++++++ spec/classes/init_spec.rb | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 3171f212..6cf5b0ff 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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) @@ -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, diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 63617169..1d97111e 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -242,6 +242,47 @@ 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 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 have_consul__check_resource_count(1) } + end + context "On a redhat 6 based OS" do let(:facts) {{ :operatingsystem => 'CentOS', From 504ea134b2d807a3773d422ea30de94bb546b140 Mon Sep 17 00:00:00 2001 From: Graham Taylor Date: Thu, 22 Jan 2015 12:12:49 +0000 Subject: [PATCH 2/2] Add in a couple of missing test assertions --- spec/classes/init_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 1d97111e..82d65bb2 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -266,6 +266,7 @@ }} 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 @@ -280,6 +281,7 @@ }} 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