Skip to content

Commit

Permalink
Implement Notifier service
Browse files Browse the repository at this point in the history
* Manifest
* Unit tests
* Acceptance tests
* Example manifest

Change-Id: Ib0b82245fa9ffeb2c23bd26e2e7f3db6a0b6fe41
  • Loading branch information
EmilienM committed Nov 3, 2015
1 parent 78af0f0 commit 6e30e9f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/aodh.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
auth_password => 'a_big_secret',
}
class { '::aodh::evaluator': }
class { '::aodh::notifier': }
class { '::aodh::client': }
48 changes: 48 additions & 0 deletions manifests/notifier.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Installs the aodh notifier service
#
# == Params
# [*enabled*]
# (optional) Should the service be enabled.
# Defaults to true.
#
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
# [*package_ensure*]
# (optional) ensure state for package.
# Defaults to 'present'
#
class aodh::notifier (
$manage_service = true,
$enabled = true,
$package_ensure = 'present',
) {

include ::aodh::params

Aodh_config<||> ~> Service['aodh-notifier']

Package[$::aodh::params::notifier_package_name] -> Service['aodh-notifier']
ensure_resource( 'package', [$::aodh::params::notifier_package_name],
{ ensure => $package_ensure }
)

if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}

Package['aodh'] -> Service['aodh-notifier']
service { 'aodh-notifier':
ensure => $service_ensure,
name => $::aodh::params::notifier_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => 'aodh-service',
}
}
1 change: 1 addition & 0 deletions spec/acceptance/aodh_wsgi_apache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class { '::aodh::auth':
auth_password => 'a_big_secret',
}
class { '::aodh::client': }
class { '::aodh::notifier': }
case $::osfamily {
'Debian': {
warning('aodh-evaluator cannot be run on ubuntu system, package is broken. See LP#1508463')
Expand Down
98 changes: 98 additions & 0 deletions spec/classes/aodh_notifier_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'spec_helper'
# LP1492636 - Cohabitation of compile matcher and webmock
WebMock.disable_net_connect!(:allow => "169.254.169.254")

describe 'aodh::notifier' do

let :pre_condition do
"class { '::aodh': }"
end

shared_examples_for 'aodh-notifier' do

context 'when enabled' do
it { is_expected.to contain_class('aodh::params') }

it 'installs aodh-notifier package' do
is_expected.to contain_package(platform_params[:notifier_package_name]).with(
:ensure => 'present'
)
end

it 'configures aodh-notifier service' do
is_expected.to contain_service('aodh-notifier').with(
:ensure => 'running',
:name => platform_params[:notifier_service_name],
:enable => true,
:hasstatus => true,
:hasrestart => true,
:tag => 'aodh-service',
)
end

end

context 'when disabled' do
let :params do
{ :enabled => false }
end

# Catalog compilation does not crash for lack of aodh::db
it { is_expected.to compile }
it 'configures aodh-notifier service' do
is_expected.to contain_service('aodh-notifier').with(
:ensure => 'stopped',
:name => platform_params[:notifier_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => 'aodh-service',
)
end
end

context 'when service management is disabled' do
let :params do
{ :enabled => false,
:manage_service => false }
end

it 'configures aodh-notifier service' do
is_expected.to contain_service('aodh-notifier').with(
:ensure => nil,
:name => platform_params[:notifier_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => 'aodh-service',
)
end
end
end

context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end

let :platform_params do
{ :notifier_package_name => 'aodh-notifier',
:notifier_service_name => 'aodh-notifier' }
end

it_configures 'aodh-notifier'
end

context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end

let :platform_params do
{ :notifier_package_name => 'openstack-aodh-notifier',
:notifier_service_name => 'openstack-aodh-notifier' }
end

it_configures 'aodh-notifier'
end
end

0 comments on commit 6e30e9f

Please sign in to comment.