Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
notify web service for local_settings.py and graphite_wsgi.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dwerder committed Apr 17, 2016
1 parent 5e7ce00 commit 6f7fb67
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 62 deletions.
12 changes: 9 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
$gr_web_group_REAL = pick($::graphite::gr_web_group, $::graphite::params::apache_web_group)
include graphite::config_apache
$web_server_package_require = [Package[$::graphite::params::apache_pkg]]
$web_server_service_notify = Service[$::graphite::params::apache_service_name]
}

'nginx' : {
Expand All @@ -46,6 +47,7 @@
include graphite::config_gunicorn
include graphite::config_nginx
$web_server_package_require = [Package['nginx']]
$web_server_service_notify = Service['gunicorn']
}

'wsgionly' : {
Expand All @@ -67,6 +69,7 @@
$gr_web_user_REAL = pick($::graphite::gr_web_user)
$gr_web_group_REAL = pick($::graphite::gr_web_group)
$web_server_package_require = undef
$web_server_service_notify = undef
}

default : {
Expand Down Expand Up @@ -159,20 +162,23 @@
group => $gr_web_group_REAL,
mode => '0644',
owner => $gr_web_user_REAL,
require => $web_server_package_require;
require => $web_server_package_require,
notify => $web_server_service_notify;

"${::graphite::graphiteweb_conf_dir_REAL}/graphite_wsgi.py":
ensure => file,
content => template('graphite/opt/graphite/conf/graphite.wsgi.erb'),
group => $gr_web_group_REAL,
mode => '0644',
owner => $gr_web_user_REAL,
require => $web_server_package_require;
require => $web_server_package_require,
notify => $web_server_service_notify;

"${::graphite::graphiteweb_install_lib_dir_REAL}/graphite_wsgi.py":
ensure => link,
target => "${::graphite::graphiteweb_conf_dir_REAL}/graphite_wsgi.py",
require => File["${::graphite::graphiteweb_conf_dir_REAL}/graphite_wsgi.py"];
require => File["${::graphite::graphiteweb_conf_dir_REAL}/graphite_wsgi.py"],
notify => $web_server_service_notify;
}

if $::graphite::gr_remote_user_header_name {
Expand Down
144 changes: 85 additions & 59 deletions spec/classes/graphite_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,53 @@
it { is_expected.to contain_class('graphite::config_apache') }

it { is_expected.to contain_file('/opt/graphite/conf/storage-schemas.conf').with({
'ensure' => 'file', 'mode' => '0644', 'notify' => /carbon-cache/, 'content' => /^retentions = 1m:90d$/ }) }
'ensure' => 'file', 'mode' => '0644', 'notify' => /carbon-cache/, 'content' => /^retentions = 1m:90d$/ }) }
it { is_expected.to contain_file('/opt/graphite/conf/carbon.conf').with({
'ensure' => 'file', 'mode' => '0644', 'notify' => /carbon-cache/, 'content' => /^MAX_UPDATES_PER_SECOND = 500$/ }) }
'ensure' => 'file', 'mode' => '0644', 'notify' => /carbon-cache/, 'content' => /^MAX_UPDATES_PER_SECOND = 500$/ }) }
it { is_expected.to contain_file('/opt/graphite/conf/storage-aggregation.conf').with({
'ensure' => 'file', 'mode' => '0644', 'content' => /^aggregationMethod = average$/ }) }
'ensure' => 'file', 'mode' => '0644', 'content' => /^aggregationMethod = average$/ }) }
it { is_expected.to contain_file('/opt/graphite/conf/whitelist.conf').with({
'ensure' => 'file', 'mode' => '0644', 'content' => /^\.\*$/ }) }
'ensure' => 'file', 'mode' => '0644', 'content' => /^\.\*$/ }) }
it { is_expected.to contain_file('/opt/graphite/conf/blacklist.conf').with({
'ensure' => 'file', 'mode' => '0644', 'content' => /^# This file is reloaded automatically when changes are made$/ }) }
'ensure' => 'file', 'mode' => '0644', 'content' => /^# This file is reloaded automatically when changes are made$/ }) }

# cron check
it { is_expected.to contain_file('/opt/graphite/bin/carbon-logrotate.sh').with({
'ensure' => 'file', 'mode' => '0544', 'content' => /^CARBON_LOGS_PATH="\/opt\/graphite\/storage\/log"$/ }) }
'ensure' => 'file', 'mode' => '0544', 'content' => /^CARBON_LOGS_PATH="\/opt\/graphite\/storage\/log"$/ }) }
it { is_expected.to contain_cron('Rotate carbon logs').with({
'command' => '/opt/graphite/bin/carbon-logrotate.sh',
'hour' => '3',
'minute' => '15',
'require' => 'File[/opt/graphite/bin/carbon-logrotate.sh]',
'user' => 'root',}) }
'command' => '/opt/graphite/bin/carbon-logrotate.sh',
'hour' => '3',
'minute' => '15',
'require' => 'File[/opt/graphite/bin/carbon-logrotate.sh]',
'user' => 'root',}) }
end

shared_context 'RedHat supported platforms' do
it { is_expected.to contain_file('/opt/graphite/storage/whisper').with({
'ensure' => 'directory', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0755', }) }
'ensure' => 'directory', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0755', }) }
it { is_expected.to contain_file('/opt/graphite/storage/log/carbon-cache').with({
'ensure' => 'directory', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0755', }) }
'ensure' => 'directory', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0755', }) }
it { is_expected.to contain_file('/opt/graphite/storage/graphite.db').with({
'ensure' => 'file', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0644', }) }
'ensure' => 'file', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0644', }) }
it { is_expected.to contain_file('/opt/graphite/webapp/graphite/local_settings.py').with({
'ensure' => 'file', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0644',
'content' => /^CONF_DIR = '\/opt\/graphite\/conf'$/ }).that_requires('Package[httpd]') }
'ensure' => 'file',
'owner' => 'apache',
'group' => 'apache',
'mode' => '0644',
'content' => /^CONF_DIR = '\/opt\/graphite\/conf'$/,
'notify' => 'Service[httpd]'}).that_requires('Package[httpd]') }
it { is_expected.to contain_file('/opt/graphite/conf/graphite_wsgi.py').with({
'ensure' => 'file', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0644' }).that_requires('Package[httpd]') }
'path' => '/opt/graphite/conf/graphite_wsgi.py',
'ensure' => 'file',
'owner' => 'apache',
'group' => 'apache',
'mode' => '0644',
'notify' => 'Service[httpd]'}).that_requires('Package[httpd]') }
it { is_expected.to contain_file('/opt/graphite/webapp/graphite/graphite_wsgi.py').with({
'ensure' => 'link', 'target' => '/opt/graphite/conf/graphite_wsgi.py', 'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]' }) }
'ensure' => 'link',
'target' => '/opt/graphite/conf/graphite_wsgi.py',
'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]',
'notify' => 'Service[httpd]' }) }
it { is_expected.to contain_service('carbon-cache').with({
'ensure' => 'running',
'enable' => 'true',
Expand All @@ -56,68 +68,82 @@
['/opt/graphite/storage',
'/opt/graphite/storage/rrd',
'/opt/graphite/storage/lists',
'/opt/graphite/storage/log'].each { |f|
it { is_expected.to contain_file(f).with($attributes_redhat)}
'/opt/graphite/storage/log',
'/var/lib/graphite-web'].each { |f|
it { is_expected.to contain_file(f).with($attributes_redhat)}
}
end

shared_context 'RedHat 6 platforms' do
it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({
'ensure' => 'file',
'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/,
'mode' => '0750',
'require' => 'File[/opt/graphite/conf/carbon.conf]',
'notify' => [] }) }
'ensure' => 'file',
'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/,
'mode' => '0750',
'require' => 'File[/opt/graphite/conf/carbon.conf]',
'notify' => [] }) }
end

shared_context 'RedHat 7 platforms' do
it { is_expected.to contain_exec('graphite-reload-systemd') }
it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({
'ensure' => 'file',
'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/,
'mode' => '0750',
'require' => 'File[/opt/graphite/conf/carbon.conf]',
'notify' => /graphite-reload-systemd/ }) }
'ensure' => 'file',
'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/,
'mode' => '0750',
'require' => 'File[/opt/graphite/conf/carbon.conf]',
'notify' => /graphite-reload-systemd/ }) }
end

shared_context 'Debian supported platforms' do
it { is_expected.to contain_file('/opt/graphite/storage/whisper').with({
'ensure' => 'directory', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0755', }) }
'ensure' => 'directory', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0755', }) }
it { is_expected.to contain_file('/opt/graphite/storage/log/carbon-cache').with({
'ensure' => 'directory', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0755', }) }
'ensure' => 'directory', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0755', }) }
it { is_expected.to contain_file('/opt/graphite/storage/graphite.db').with({
'ensure' => 'file', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0644', }) }
'ensure' => 'file', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0644', }) }
it { is_expected.to contain_file('/opt/graphite/webapp/graphite/local_settings.py').with({
'ensure' => 'file', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0644',
'content' => /^CONF_DIR = '\/opt\/graphite\/conf'$/ }).that_requires('Package[apache2]') }
'ensure' => 'file',
'owner' => 'www-data',
'group' => 'www-data',
'mode' => '0644',
'content' => /^CONF_DIR = '\/opt\/graphite\/conf'$/,
'notify' => 'Service[apache2]' }).that_requires('Package[apache2]') }
it { is_expected.to contain_file('/opt/graphite/conf/graphite_wsgi.py').with({
'ensure' => 'file', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0644' }).that_requires('Package[apache2]') }
it { is_expected.to contain_file('/opt/graphite/webapp/graphite/graphite_wsgi.py').with({
'ensure' => 'link', 'target' => '/opt/graphite/conf/graphite_wsgi.py', 'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]' }) }
'path' => '/opt/graphite/conf/graphite_wsgi.py',
'ensure' => 'file',
'owner' => 'www-data',
'group' => 'www-data',
'mode' => '0644',
'notify' => 'Service[apache2]'}).that_requires('Package[apache2]') }
it { is_expected.to contain_file('/opt/graphite/webapp/graphite/graphite_wsgi.py').only_with({
'path' => '/opt/graphite/webapp/graphite/graphite_wsgi.py',
'ensure' => 'link',
'target' => '/opt/graphite/conf/graphite_wsgi.py',
'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]',
'notify' => 'Service[apache2]'}) }
it { is_expected.to contain_service('carbon-cache').only_with({
'ensure' => 'running',
'enable' => 'true',
'hasrestart' => 'true',
'hasstatus' => 'true',
'provider' => nil,
'require' => 'File[/etc/init.d/carbon-cache]' }) }
'ensure' => 'running',
'enable' => 'true',
'hasrestart' => 'true',
'hasstatus' => 'true',
'provider' => nil,
'require' => 'File[/etc/init.d/carbon-cache]' }) }
it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({
'ensure' => 'file',
'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/,
'mode' => '0750',
'require' => 'File[/opt/graphite/conf/carbon.conf]',
'notify' => [] }) }
'ensure' => 'file',
'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/,
'mode' => '0750',
'require' => 'File[/opt/graphite/conf/carbon.conf]',
'notify' => [] }) }

$attributes_debian = {'ensure' => 'directory', 'group' => 'www-data', 'mode' => '0755', 'owner' => 'www-data', 'subscribe' => 'Exec[Initial django db creation]'}
['/opt/graphite/storage',
'/opt/graphite/storage/rrd',
'/opt/graphite/storage/lists',
'/opt/graphite/storage/log'].each { |f|
it { is_expected.to contain_file(f).with($attributes_debian)}
'/opt/graphite/storage/log',
'/var/lib/graphite-web'].each { |f|
it { is_expected.to contain_file(f).with($attributes_debian)}
}
end


context 'Unsupported OS' do
let(:facts) {{ :osfamily => 'unsupported', :operatingsystem => 'UnknownOS' }}
it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )}
Expand All @@ -128,10 +154,10 @@
let(:facts) do
facts
end
let :pre_condition do
'include ::graphite'
let :pre_condition do
'include ::graphite'
end

it_behaves_like 'all platforms'

case facts[:osfamily]
Expand All @@ -150,7 +176,7 @@
else
it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )}
end

end
end

Expand Down

0 comments on commit 6f7fb67

Please sign in to comment.