From 588d55a3d84d7316c73b07215ccfb7872765b81d Mon Sep 17 00:00:00 2001 From: Barhob Date: Sun, 21 Sep 2014 21:13:53 -0400 Subject: [PATCH] add configurable service name --- manifests/params.pp | 1 + manifests/service.pp | 2 ++ spec/classes/service_spec.rb | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 3acd4b343..a74100734 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -135,6 +135,7 @@ $nx_configtest_enable = false $nx_service_restart = '/etc/init.d/nginx configtest && /etc/init.d/nginx restart' $nx_service_ensure = running + $nx_service_name = 'nginx' $nx_mail = false diff --git a/manifests/service.pp b/manifests/service.pp index 2fa361c21..df9503849 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -17,6 +17,7 @@ $configtest_enable = $nginx::configtest_enable, $service_restart = $nginx::service_restart, $service_ensure = $nginx::service_ensure, + $service_name = 'nginx', ) { $service_enable = $service_ensure ? { @@ -34,6 +35,7 @@ } service { 'nginx': + name => $service_name, ensure => $service_ensure_real, enable => $service_enable, hasstatus => true, diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index f71799186..c2cfa7a64 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -10,15 +10,16 @@ :configtest_enable => false, :service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart', :service_ensure => 'running', + :service_name => 'nginx', } end context "using default parameters" do it { is_expected.to contain_service('nginx').with( - :ensure => 'running', - :enable => true, - :hasstatus => true, - :hasrestart => true + :ensure => 'running', + :enable => true, + :hasstatus => true, + :hasrestart => true, )} it { is_expected.to contain_service('nginx').without_restart } @@ -30,6 +31,7 @@ :configtest_enable => true, :service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart', :service_ensure => 'running', + :service_name => 'nginx', } end it { is_expected.to contain_service('nginx').with_restart('/etc/init.d/nginx configtest && /etc/init.d/nginx restart') } @@ -38,9 +40,16 @@ :configtest_enable => true, :service_restart => 'a restart command', :service_ensure => 'running', + :service_name => 'nginx', } end it { is_expected.to contain_service('nginx').with_restart('a restart command') } end end + describe "when service_name => 'nginx14" do + let :params do { + :service_name => 'nginx14', + } end + it { is_expected.to contain_service('nginx').with_name('nginx14') } + end end