From 14c82348fd127a819ed36491bacd71345c0484d5 Mon Sep 17 00:00:00 2001 From: Justin Lambert Date: Tue, 7 Jan 2014 05:48:33 -0700 Subject: [PATCH] remove str2bool, add repo_source --- manifests/api/config.pp | 2 +- manifests/api/service.pp | 4 ++-- manifests/client/config.pp | 2 +- manifests/client/service.pp | 4 ++-- manifests/dashboard/config.pp | 2 +- manifests/dashboard/service.pp | 4 ++-- manifests/init.pp | 16 +++++++--------- manifests/package.pp | 2 +- manifests/rabbitmq/config.pp | 2 +- manifests/redis/config.pp | 2 +- manifests/repo/apt.pp | 10 ++++++++-- manifests/repo/yum.pp | 12 ++++++++---- manifests/server/service.pp | 4 ++-- spec/classes/sensu_package_spec.rb | 10 ++++++++++ 14 files changed, 47 insertions(+), 29 deletions(-) diff --git a/manifests/api/config.pp b/manifests/api/config.pp index 2324042020..b8a7b435b2 100644 --- a/manifests/api/config.pp +++ b/manifests/api/config.pp @@ -8,7 +8,7 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::purge_config_real and !$sensu::server_real and !$sensu::api_real and !$sensu::dashboard_real { + if $sensu::purge_config and !$sensu::server and !$sensu::api and !$sensu::dashboard { $ensure = 'absent' } else { $ensure = 'present' diff --git a/manifests/api/service.pp b/manifests/api/service.pp index 81bbe17958..51d432bced 100644 --- a/manifests/api/service.pp +++ b/manifests/api/service.pp @@ -8,9 +8,9 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::manage_services_real { + if $sensu::manage_services { - case $sensu::api_real { + case $sensu::api { true: { $ensure = 'running' $enable = true diff --git a/manifests/client/config.pp b/manifests/client/config.pp index 63ab4a7e07..8ce3747571 100644 --- a/manifests/client/config.pp +++ b/manifests/client/config.pp @@ -8,7 +8,7 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::purge_config_real and !$sensu::client_real { + if $sensu::purge_config and !$sensu::client { $ensure = 'absent' } else { $ensure = 'present' diff --git a/manifests/client/service.pp b/manifests/client/service.pp index 8923925a21..d1eed1d355 100644 --- a/manifests/client/service.pp +++ b/manifests/client/service.pp @@ -9,9 +9,9 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::manage_services_real { + if $sensu::manage_services { - case $sensu::client_real { + case $sensu::client { true: { $ensure = 'running' $enable = true diff --git a/manifests/dashboard/config.pp b/manifests/dashboard/config.pp index 10d9d5083e..14db25f025 100644 --- a/manifests/dashboard/config.pp +++ b/manifests/dashboard/config.pp @@ -8,7 +8,7 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::purge_config_real and !$sensu::dashboard_real { + if $sensu::purge_config and !$sensu::dashboard { $ensure = 'absent' } else { $ensure = 'present' diff --git a/manifests/dashboard/service.pp b/manifests/dashboard/service.pp index 78950b89d2..560997f4fb 100644 --- a/manifests/dashboard/service.pp +++ b/manifests/dashboard/service.pp @@ -8,9 +8,9 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::manage_services_real { + if $sensu::manage_services { - case $sensu::dashboard_real { + case $sensu::dashboard { true: { $ensure = 'running' $enable = true diff --git a/manifests/init.pp b/manifests/init.pp index 1fedd5b923..74fd3d6e5b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -19,6 +19,10 @@ # Default: main # Valid values: main, unstable # +# [*repo_source*] +# String. Location of the yum/apt repo. Overrides the default location +# Default: undef +# # [*client*] # Boolean. Include the sensu client # Default: true @@ -154,6 +158,7 @@ $version = 'latest', $install_repo = true, $repo = 'main', + $repo_source = undef, $client = true, $server = false, $api = false, @@ -186,14 +191,8 @@ $log_level = 'info', ){ - $client_real = str2bool($client) - $server_real = str2bool($server) - $api_real = str2bool($api) - $dashboard_real = str2bool($dashboard) - $install_repo_real = str2bool($install_repo) - $purge_config_real = str2bool($purge_config) - $safe_mode_real = str2bool($safe_mode) - $manage_services_real = str2bool($manage_services) + validate_bool($client, $server, $api, $dashboard, $install_repo, $purge_config, $safe_mode, $manage_services) + $subscriptions_real = any2array($subscriptions) validate_re($repo, ['^main$', '^unstable$'], "Repo must be 'main' or 'unstable'. Found: ${repo}") validate_re($version, ['^absent$', '^installed$', '^latest$', '^present$', '^[\d\.\-]+$'], "Invalid package version: ${version}") @@ -203,7 +202,6 @@ if !is_integer($api_port) { fail('api_port must be an integer') } if !is_integer($dashboard_port) { fail('dashboard_port must be an integer') } - # Include everything and let each module determine its state. This allows # transitioning to purged config and stopping/disabling services anchor { 'sensu::begin': } -> diff --git a/manifests/package.pp b/manifests/package.pp index 0a0aeb2b04..1fcddff157 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -40,7 +40,7 @@ owner => 'sensu', group => 'sensu', mode => '0555', - purge => $sensu::purge_config_real, + purge => $sensu::purge_config, recurse => true, force => true, require => Package['sensu'], diff --git a/manifests/rabbitmq/config.pp b/manifests/rabbitmq/config.pp index c0498f24ea..854ea24544 100644 --- a/manifests/rabbitmq/config.pp +++ b/manifests/rabbitmq/config.pp @@ -8,7 +8,7 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::purge_config_real and !$sensu::server_real and !$sensu::client_real { + if $sensu::purge_config and !$sensu::server and !$sensu::client { $ensure = 'absent' } else { $ensure = 'present' diff --git a/manifests/redis/config.pp b/manifests/redis/config.pp index 09f7164919..1d2947deb6 100644 --- a/manifests/redis/config.pp +++ b/manifests/redis/config.pp @@ -8,7 +8,7 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::purge_config_real and !$sensu::server_real and !$sensu::api_real and !$sensu::dashboard_real { + if $sensu::purge_config and !$sensu::server and !$sensu::api and !$sensu::dashboard { $ensure = 'absent' } else { $ensure = 'present' diff --git a/manifests/repo/apt.pp b/manifests/repo/apt.pp index 59dd1a38d4..a1e0edfe4c 100644 --- a/manifests/repo/apt.pp +++ b/manifests/repo/apt.pp @@ -12,14 +12,20 @@ if defined(apt::source) and defined(apt::key) { - $ensure = $sensu::install_repo_real ? { + $ensure = $sensu::install_repo ? { true => 'present', default => 'absent' } + if $sensu::repo_source { + $url = $sensu::repo_source + } else { + $url = 'http://repos.sensuapp.org/apt' + } + apt::source { 'sensu': ensure => $ensure, - location => 'http://repos.sensuapp.org/apt', + location => $url, release => 'sensu', repos => $sensu::repo, include_src => false, diff --git a/manifests/repo/yum.pp b/manifests/repo/yum.pp index fa8b65863d..4b2d1abe5f 100644 --- a/manifests/repo/yum.pp +++ b/manifests/repo/yum.pp @@ -8,10 +8,14 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::install_repo_real { - $url = $sensu::repo ? { - 'unstable' => 'http://repos.sensuapp.org/yum-unstable/el/$releasever/$basearch/', - default => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/' + if $sensu::install_repo { + if $sensu::repo_source { + $url = $sensu::repo_source + } else { + $url = $sensu::repo ? { + 'unstable' => 'http://repos.sensuapp.org/yum-unstable/el/$releasever/$basearch/', + default => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/' + } } yumrepo { 'sensu': diff --git a/manifests/server/service.pp b/manifests/server/service.pp index 5286c2005a..6d7438b042 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -8,9 +8,9 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $sensu::manage_services_real { + if $sensu::manage_services { - case $sensu::server_real { + case $sensu::server { true: { $ensure = 'running' $enable = true diff --git a/spec/classes/sensu_package_spec.rb b/spec/classes/sensu_package_spec.rb index 09a44c990f..be1d8bf293 100644 --- a/spec/classes/sensu_package_spec.rb +++ b/spec/classes/sensu_package_spec.rb @@ -58,6 +58,11 @@ it { should contain_apt__source('sensu').with_repos('unstable') } end + context 'override repo url' do + let(:params) { { :repo_source => 'http://repo.mydomain.com/apt' } } + it { should contain_apt__source('sensu').with( :location => 'http://repo.mydomain.com/apt') } + end + context 'install_repo => false' do let(:params) { { :install_repo => false, :repo => 'main' } } it { should contain_apt__source('sensu').with_ensure('absent') } @@ -91,6 +96,11 @@ it { should contain_yumrepo('sensu').with(:baseurl => 'http://repos.sensuapp.org/yum-unstable/el/$releasever/$basearch/' )} end + context 'override repo url' do + let(:params) { { :repo_source => 'http://repo.mydomain.com/yum' } } + it { should contain_yumrepo('sensu').with( :baseurl => 'http://repo.mydomain.com/yum') } + end + context 'install_repo => false' do let(:params) { { :install_repo => false } } it { should_not contain_yumrepo('sensu') }