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 idempotency test for alertmanger archlinux #717

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions data/Archlinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ prometheus::bird_exporter::manage_user: false
prometheus::bird_exporter::manage_group: false
prometheus::bird_exporter::init_style: 'none'
prometheus::bird_exporter::service_name: 'prometheus-bird-exporter'
prometheus::alertmanager::config_file: "%{hiera('prometheus::alertmanager::config_dir')}/alertmanager.yml"
prometheus::alertmanager::templates: [ "%{lookup('prometheus::alertmanager::config_dir')}/template/*.tmpl" ]
11 changes: 11 additions & 0 deletions manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@
recurse => $purge_config_dir,
}

# arch package comes with a separate template directory
if $facts['os']['name'] == 'Archlinux' {
file { "${config_dir}/template":
ensure => 'directory',
owner => 'root',
group => $group,
purge => $purge_config_dir,
recurse => $purge_config_dir,
}
}

if (( versioncmp($version, '0.10.0') >= 0 ) and ( $install_method == 'url' )) {
# If version >= 0.10.0 then install amtool - Alertmanager validation tool
file { "${bin_dir}/amtool":
Expand Down
14 changes: 10 additions & 4 deletions spec/acceptance/node_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

require 'spec_helper_acceptance'

service_name = if host_inventory['facter']['os']['name'] == 'Archlinux'
'prometheus-node-exporter'

Check failure on line 6 in spec/acceptance/node_exporter_spec.rb

View workflow job for this annotation

GitHub Actions / Setup Test Matrix

Layout/IndentationWidth: Use 2 (not -13) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
else

Check failure on line 7 in spec/acceptance/node_exporter_spec.rb

View workflow job for this annotation

GitHub Actions / Setup Test Matrix

Layout/ElseAlignment: Align `else` with `if`.
'node_exporter'
end

Check failure on line 9 in spec/acceptance/node_exporter_spec.rb

View workflow job for this annotation

GitHub Actions / Setup Test Matrix

Layout/EndAlignment: `end` at 9, 0 is not aligned with `if` at 5, 15.

describe 'prometheus node_exporter' do
it 'node_exporter works idempotently with no errors' do
pp = 'include prometheus::node_exporter'
Expand All @@ -10,7 +16,7 @@
apply_manifest(pp, catch_changes: true)
end

describe service('node_exporter') do
describe service(service_name.to_s) do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
Expand All @@ -28,7 +34,7 @@
apply_manifest(pp, catch_changes: true)
end

describe service('node_exporter') do
describe service(service_name.to_s) do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
Expand All @@ -44,7 +50,7 @@
apply_manifest(pp, catch_changes: true)
end

describe service('node_exporter') do
describe service(service_name.to_s) do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
Expand All @@ -63,7 +69,7 @@
apply_manifest(pp, catch_changes: true)
end

describe service('node_exporter') do
describe service(service_name.to_s) do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
Expand Down
26 changes: 16 additions & 10 deletions spec/classes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
facts.merge(os_specific_facts(facts))
end

config_file = if facts[:os]['family'] == 'Archlinux'
'/etc/alertmanager/alertmanager.yml'
else
'/etc/alertmanager/alertmanager.yaml'
end

context 'with version specified' do
let(:params) do
{
Expand Down Expand Up @@ -36,12 +42,12 @@

describe 'config file contents' do
it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Service[alertmanager]')
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', ['---', 'global:', ' smtp_smarthost: localhost:25', ' smtp_from: alertmanager@localhost'])
expect(subject).to contain_file(config_file.to_s).with_notify('Service[alertmanager]')
verify_contents(catalogue, config_file.to_s, ['---', 'global:', ' smtp_smarthost: localhost:25', ' smtp_from: alertmanager@localhost'])
}

it {
expect(subject).not_to contain_file('/etc/alertmanager/alertmanager.yaml').with_content(%r{mute_time_intervals})
expect(subject).not_to contain_file(config_file.to_s).with_content(%r{mute_time_intervals})
}
end

Expand Down Expand Up @@ -71,7 +77,7 @@
end

it {
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', [
verify_contents(catalogue, config_file.to_s, [
'mute_time_intervals:',
'- name: weekend',
' time_intervals:',
Expand Down Expand Up @@ -99,10 +105,10 @@
}
end

it { is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').without(content: %r{mute_time_intervals}) }
it { is_expected.to contain_file(config_file.to_s).without(content: %r{mute_time_intervals}) }

it {
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', [
verify_contents(catalogue, config_file.to_s, [
'time_intervals:',
'- name: weekend',
' time_intervals:',
Expand All @@ -117,7 +123,7 @@
let(:params) { { reload_on_change: true } }

it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Exec[alertmanager-reload]')
expect(subject).to contain_file(config_file.to_s).with_notify('Exec[alertmanager-reload]')
}
end

Expand All @@ -138,7 +144,7 @@
end

it {
expect(subject).not_to contain_file('/etc/alertmanager/alertmanager.yaml')
expect(subject).not_to contain_file(config_file.to_s)
}
end
end
Expand All @@ -154,7 +160,7 @@
end

it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').without_validate_cmd
expect(subject).to contain_file(config_file.to_s).without_validate_cmd
}
end

Expand All @@ -169,7 +175,7 @@
end

it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').with_validate_cmd('/bin/amtool check-config --alertmanager.url=\'\' %')
expect(subject).to contain_file(config_file.to_s).with_validate_cmd('/bin/amtool check-config --alertmanager.url=\'\' %')
}
end
end
Expand Down
Loading