Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix restart_on_change and add tests to Class[prometheus] #83

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
$real_download_url = pick($download_url,
"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
}
$notify_service = $restart_on_change ? {
true => Service['prometheus'],
default => undef,
}


$config_hash_real = assert_type(Hash, deep_merge($config_defaults, $config_hash))

Expand Down
197 changes: 197 additions & 0 deletions spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
require 'spec_helper'

describe 'prometheus' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

context 'without parameters' do
# prometheus::install
it {
is_expected.to contain_file('/var/lib/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0755'
)
}

prom_version = '1.5.2'
prom_os = facts[:kernel].downcase
prom_arch = facts[:architecture] == 'i386' ? '386' : 'amd64'

it {
is_expected.to contain_archive("/tmp/prometheus-#{prom_version}.tar.gz").with(
'ensure' => 'present',
'extract' => true,
'extract_path' => '/opt',
'source' => "https://github.com/prometheus/prometheus/releases/download/v#{prom_version}/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}.tar.gz",
'checksum_verify' => false,
'creates' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus",
'cleanup' => true
).that_comes_before("File[/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus]")
}

it {
is_expected.to contain_file("/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus").with(
'owner' => 'root',
'group' => 0,
'mode' => '0555'
)
}

it {
is_expected.to contain_file('/usr/local/bin/prometheus').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_file('/usr/local/share/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0755'
)
}

it {
is_expected.to contain_file('/usr/local/share/prometheus/consoles').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/consoles"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_file('/usr/local/share/prometheus/console_libraries').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/console_libraries"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_user('prometheus').with(
'ensure' => 'present',
'system' => true,
'groups' => []
)
}

it {
is_expected.to contain_group('prometheus').with(
'ensure' => 'present',
'system' => true
)
}

# prometheus::config
if ['debian-7-x86_64'].include?(os) ||
['centos-6-x86_64', 'redhat-6-x86_64'].include?(os)
# init_style = 'debian' or
# init_style = 'sysv'

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'mode' => '0555',
'owner' => 'root',
'group' => 'root',
# 'content' => ...
)
}
elsif ['centos-7-x86_64', 'debian-8-x86_64', 'redhat-7-x86_64', 'ubuntu-16.04-x86_64'].include?(os)
# init_style = 'systemd'

it {
is_expected.to contain_file('/etc/systemd/system/prometheus.service').with(
'mode' => '0644',
'owner' => 'root',
'group' => 'root',
# 'content' => ...
).that_notifies(['Exec[prometheus-systemd-reload]', 'Class[Prometheus::Run_service]'])
}

it {
is_expected.to contain_exec('prometheus-systemd-reload').with(
'command' => 'systemctl daemon-reload',
'path' => ['/usr/bin', '/bin', '/usr/sbin'],
'refreshonly' => true
)
}
elsif ['ubuntu-14.04-x86_64'].include?(os)
# init_style = 'upstart'

it {
is_expected.to contain_file('/etc/init/prometheus.conf').with(
'mode' => '0444',
'owner' => 'root',
'group' => 'root',
# 'content' => ...
)
}

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'ensure' => 'link',
'target' => '/lib/init/upstart-job',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
)
}
else
it {
is_expected.to raise_error(Puppet::Error, %r{I don.t know how to create an init script for style})
}
end

it {
is_expected.to contain_file('/etc/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'purge' => true,
'recurse' => true
)
}

it {
is_expected.to contain_file('prometheus.yaml').with(
'ensure' => 'present',
'path' => '/etc/prometheus/prometheus.yaml',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0660',
# 'content' => ...,
).that_notifies('Class[prometheus::service_reload]')
}

# prometheus::alerts
it {
is_expected.not_to contain_file('/etc/prometheus/alert.rules')
}

# prometheus::run_service
it {
is_expected.to contain_service('prometheus').with(
'ensure' => 'running',
'name' => 'prometheus',
'enable' => true,
'hasrestart' => true
)
}

# prometheus::service_reload
it {
is_expected.to contain_exec('prometheus-reload').with(
# 'command' => 'systemctl reload prometheus',
'path' => ['/usr/bin', '/bin', '/usr/sbin'],
'refreshonly' => true
)
}
end
end
end
end