Skip to content

Commit

Permalink
simplify init handling with service_provider fact
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Mar 18, 2018
1 parent a7439b6 commit 95bdf84
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- set: docker/ubuntu-16.04
- set: docker/debian-8
- set: docker/centos-7
spec/spec_helper.rb:
spec_overrides: "require 'spec_helper_methods'"
36 changes: 1 addition & 35 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Class prometheus::params
# Include default parameters for prometheus class
class prometheus::params {
$init_style = $facts['service_provider']
$alert_relabel_config = []
$alertmanagers_config = []
$alertmanager_config_dir = '/etc/alertmanager'
Expand Down Expand Up @@ -219,84 +220,49 @@
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/default'
if versioncmp($::operatingsystemrelease, '8.04') < 1 {
$init_style = 'debian'
} elsif versioncmp($::operatingsystemrelease, '15.04') < 0 {
$init_style = 'upstart'
} else {
$init_style = 'systemd'
}
} elsif $::operatingsystem =~ /Scientific|CentOS|RedHat|OracleLinux/ {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/sysconfig'
if versioncmp($::operatingsystemrelease, '7.0') < 0 {
$init_style = 'sysv'
} else {
$init_style = 'systemd'
}
} elsif $::operatingsystem == 'Fedora' {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/sysconfig'
if versioncmp($::operatingsystemrelease, '12') < 0 {
$init_style = 'sysv'
} else {
$init_style = 'systemd'
}
} elsif $::operatingsystem == 'Debian' {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/default'
if versioncmp($::operatingsystemrelease, '8.0') < 0 {
$init_style = 'debian'
} else {
$init_style = 'systemd'
}
} elsif $::operatingsystem == 'Archlinux' {
$version = '2.2.0'
$bin_dir = '/usr/bin'
$prometheus_install_method = 'package'
$env_file_path = '/etc/default'
$init_style = 'systemd'
} elsif $::operatingsystem == 'OpenSuSE' {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/sysconfig'
$init_style = 'systemd'
} elsif $::operatingsystem =~ /SLE[SD]/ {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/sysconfig'
if versioncmp($::operatingsystemrelease, '12.0') < 0 {
$init_style = 'sles'
} else {
$init_style = 'systemd'
}
} elsif $::operatingsystem == 'Darwin' {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = undef
$init_style = 'launchd'
} elsif $::operatingsystem == 'Amazon' {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$env_file_path = '/etc/sysconfig'
$init_style = 'sysv'
} else {
$version = '1.5.2'
$bin_dir = '/usr/local/bin'
$prometheus_install_method = 'url'
$init_style = undef
}
if $init_style == undef {
fail('Unsupported OS')
}
}
2 changes: 1 addition & 1 deletion spec/classes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/beanstalkd_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/blackbox_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/consul_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/elasticsearch_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/haproxy_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/mongodb_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/nginx_vts_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/node_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'without parameters' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

[{ version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url' }].each do |parameters|
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/pushgateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/rabbitmq_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/redis_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/snmp_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

let :pre_condition do
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
facts.merge(os_specific_facts(facts))
end

let :pre_condition do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
c.default_facts = default_facts
end

require 'spec_helper_methods'
# vim: syntax=ruby
26 changes: 26 additions & 0 deletions spec/spec_helper_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def os_specific_facts(facts)
case facts[:os]['family']
when 'Archlinux'
{ service_provider: 'systemd' }
when 'Debian'
case facts[:os]['release']['major']
when '7'
{ service_provider: 'sysv' }
when '8'
{ service_provider: 'systemd' }
when '9'
{ service_provider: 'systemd' }
when '14.04'
{ service_provider: 'upstart' }
when '16.04'
{ service_provider: 'systemd' }
end
when 'RedHat'
case facts[:os]['release']['major']
when '6'
{ service_provider: 'sysv' }
when '7'
{ service_provider: 'systemd' }
end
end
end

0 comments on commit 95bdf84

Please sign in to comment.