Skip to content

Commit

Permalink
Merge pull request redhat-openstack#209 from queeno/ensure_apt_source
Browse files Browse the repository at this point in the history
manage_repos sets 'ensure' in apt::source
  • Loading branch information
cmurphy committed Dec 14, 2014
2 parents be96585 + 8086d73 commit ecd7447
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 12 deletions.
9 changes: 7 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$package_name = $rabbitmq::params::package_name,
$package_provider = $rabbitmq::params::package_provider,
$package_source = $rabbitmq::params::package_source,
$repos_ensure = $rabbitmq::params::repos_ensure,
$manage_repos = $rabbitmq::params::manage_repos,
$plugin_dir = $rabbitmq::params::plugin_dir,
$port = $rabbitmq::params::port,
Expand Down Expand Up @@ -63,7 +64,7 @@
validate_string($package_gpg_key)
validate_string($package_name)
validate_string($package_provider)
validate_bool($manage_repos)
validate_bool($repos_ensure)
validate_re($version, '^\d+\.\d+\.\d+(-\d+)*$') # Allow 3 digits and optional -n postfix.
# Validate config parameters.
validate_array($cluster_disk_nodes)
Expand Down Expand Up @@ -123,7 +124,11 @@
include '::rabbitmq::service'
include '::rabbitmq::management'

if $rabbitmq::manage_repos == true {
if $manage_repos != undef {
warning('$manage_repos is now deprecated. Please use $repos_ensure instead')
}

if $manage_repos != false {
case $::osfamily {
'RedHat', 'SUSE':
{ include '::rabbitmq::repo::rhel' }
Expand Down
3 changes: 2 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
$management_port = '15672'
$package_apt_pin = ''
$package_gpg_key = 'http://www.rabbitmq.com/rabbitmq-signing-key-public.asc'
$manage_repos = true
$repos_ensure = true
$manage_repos = undef
$service_ensure = 'running'
$service_manage = true
#config
Expand Down
6 changes: 6 additions & 0 deletions manifests/repo/apt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

Class['rabbitmq::repo::apt'] -> Package<| title == 'rabbitmq-server' |>

$ensure_source = $rabbitmq::repos_ensure ? {
false => 'absent',
default => 'present',
}

apt::source { 'rabbitmq':
ensure => $ensure_source,
location => $location,
release => $release,
repos => $repos,
Expand Down
14 changes: 8 additions & 6 deletions manifests/repo/rhel.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# Imports the gpg key if it doesn't already exist.
class rabbitmq::repo::rhel {

$package_gpg_key = $rabbitmq::package_gpg_key
if $rabbitmq::repos_ensure {

Class['rabbitmq::repo::rhel'] -> Package<| title == 'rabbitmq-server' |>
$package_gpg_key = $rabbitmq::package_gpg_key

exec { "rpm --import ${package_gpg_key}":
path => ['/bin','/usr/bin','/sbin','/usr/sbin'],
unless => 'rpm -q gpg-pubkey-056e8e56-468e43f2 2>/dev/null',
}
Class['rabbitmq::repo::rhel'] -> Package<| title == 'rabbitmq-server' |>

exec { "rpm --import ${package_gpg_key}":
path => ['/bin','/usr/bin','/sbin','/usr/sbin'],
unless => 'rpm -q gpg-pubkey-056e8e56-468e43f2 2>/dev/null',
}
}
}
175 changes: 172 additions & 3 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
describe 'apt::source default values' do
it 'should add a repo with defaults values' do
should contain_apt__source('rabbitmq').with( {
:ensure => 'present',
:location => 'http://www.rabbitmq.com/debian/',
:release => 'testing',
:repos => 'main',
Expand All @@ -30,23 +31,191 @@
context 'on Debian' do
let(:params) {{ :manage_repos => false }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
it 'does not include rabbitmq::repo::apt when manage_repos is false' do
should_not contain_class('rabbitmq::repo::apt')
it 'does ensure rabbitmq apt::source is absent when manage_repos is false' do
should_not contain_apt__source('rabbitmq')
end
end

context 'on Debian' do
let(:params) {{ :manage_repos => true }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}

it 'includes rabbitmq::repo::apt' do
should contain_class('rabbitmq::repo::apt')
end

describe 'apt::source default values' do
it 'should add a repo with defaults values' do
should contain_apt__source('rabbitmq').with( {
:ensure => 'present',
:location => 'http://www.rabbitmq.com/debian/',
:release => 'testing',
:repos => 'main',
})
end
end
end

context 'on Debian' do
let(:params) {{ :repos_ensure => false }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
it 'does ensure rabbitmq apt::source is absent when repos_ensure is false' do
should contain_apt__source('rabbitmq').with(
'ensure' => 'absent'
)
end
end

context 'on Debian' do
let(:params) {{ :repos_ensure => true }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}

it 'includes rabbitmq::repo::apt' do
should contain_class('rabbitmq::repo::apt')
end

describe 'apt::source default values' do
it 'should add a repo with defaults values' do
should contain_apt__source('rabbitmq').with( {
:ensure => 'present',
:location => 'http://www.rabbitmq.com/debian/',
:release => 'testing',
:repos => 'main',
})
end
end
end

context 'on Debian' do
let(:params) {{ :manage_repos => true, :repos_ensure => false }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}

it 'includes rabbitmq::repo::apt' do
should contain_class('rabbitmq::repo::apt')
end

describe 'apt::source default values' do
it 'should add a repo with defaults values' do
should contain_apt__source('rabbitmq').with( {
:ensure => 'absent',
})
end
end
end

context 'on Debian' do
let(:params) {{ :manage_repos => true, :repos_ensure => true }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}

it 'includes rabbitmq::repo::apt' do
should contain_class('rabbitmq::repo::apt')
end

describe 'apt::source default values' do
it 'should add a repo with defaults values' do
should contain_apt__source('rabbitmq').with( {
:ensure => 'present',
:location => 'http://www.rabbitmq.com/debian/',
:release => 'testing',
:repos => 'main',
})
end
end
end

context 'on Debian' do
let(:params) {{ :manage_repos => false, :repos_ensure => true }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
it 'does ensure rabbitmq apt::source is absent when manage_repos is false and repos_ensure is true' do
should_not contain_apt__source('rabbitmq')
end
end

context 'on Debian' do
let(:params) {{ :manage_repos => false, :repos_ensure => false }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
it 'does ensure rabbitmq apt::source is absent when manage_repos is false and repos_ensure is false' do
should_not contain_apt__source('rabbitmq')
end
end

context 'on Redhat' do
let(:facts) {{ :osfamily => 'RedHat' }}
it 'includes rabbitmq::repo::rhel' do
should contain_class('rabbitmq::repo::rhel')
should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :repos_ensure => false }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does not import repo public key when repos_ensure is false' do
should contain_class('rabbitmq::repo::rhel')
should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :repos_ensure => true }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does import repo public key when repos_ensure is true' do
should contain_class('rabbitmq::repo::rhel')
should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :manage_repos => false }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does not include rabbitmq::repo::rhel when manage_repos is false' do
it 'does not import repo public key when manage_repos is false' do
should_not contain_class('rabbitmq::repo::rhel')
should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :manage_repos => true }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does import repo public key when manage_repos is true' do
should contain_class('rabbitmq::repo::rhel')
should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :manage_repos => false, :repos_ensure => true }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does not import repo public key when manage_repos is false and repos_ensure is true' do
should_not contain_class('rabbitmq::repo::rhel')
should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :manage_repos => true, :repos_ensure => true }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does import repo public key when manage_repos is true and repos_ensure is true' do
should contain_class('rabbitmq::repo::rhel')
should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :manage_repos => false, :repos_ensure => false }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does not import repo public key when manage_repos is false and repos_ensure is false' do
should_not contain_class('rabbitmq::repo::rhel')
should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

context 'on Redhat' do
let(:params) {{ :manage_repos => true, :repos_ensure => false }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does not import repo public key when manage_repos is true and repos_ensure is false' do
should contain_class('rabbitmq::repo::rhel')
should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
end
end

Expand Down

0 comments on commit ecd7447

Please sign in to comment.