diff --git a/.sync.yml b/.sync.yml index b735cc0b0..0c20c9621 100644 --- a/.sync.yml +++ b/.sync.yml @@ -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'" diff --git a/manifests/params.pp b/manifests/params.pp index 7af18acce..5faf14df7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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' @@ -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') } } diff --git a/spec/classes/alertmanager_spec.rb b/spec/classes/alertmanager_spec.rb index 2076e547a..87d3e58b0 100644 --- a/spec/classes/alertmanager_spec.rb +++ b/spec/classes/alertmanager_spec.rb @@ -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 diff --git a/spec/classes/beanstalkd_exporter_spec.rb b/spec/classes/beanstalkd_exporter_spec.rb index 591c77972..39639492a 100644 --- a/spec/classes/beanstalkd_exporter_spec.rb +++ b/spec/classes/beanstalkd_exporter_spec.rb @@ -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 diff --git a/spec/classes/blackbox_exporter_spec.rb b/spec/classes/blackbox_exporter_spec.rb index aabe786d9..38429b617 100644 --- a/spec/classes/blackbox_exporter_spec.rb +++ b/spec/classes/blackbox_exporter_spec.rb @@ -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 diff --git a/spec/classes/consul_exporter_spec.rb b/spec/classes/consul_exporter_spec.rb index 92161374a..f79494ab8 100644 --- a/spec/classes/consul_exporter_spec.rb +++ b/spec/classes/consul_exporter_spec.rb @@ -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 diff --git a/spec/classes/elasticsearch_exporter_spec.rb b/spec/classes/elasticsearch_exporter_spec.rb index 520a64ace..28f99d907 100644 --- a/spec/classes/elasticsearch_exporter_spec.rb +++ b/spec/classes/elasticsearch_exporter_spec.rb @@ -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 diff --git a/spec/classes/haproxy_exporter_spec.rb b/spec/classes/haproxy_exporter_spec.rb index 051ce9d2e..6b533fd02 100644 --- a/spec/classes/haproxy_exporter_spec.rb +++ b/spec/classes/haproxy_exporter_spec.rb @@ -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 diff --git a/spec/classes/mongodb_exporter_spec.rb b/spec/classes/mongodb_exporter_spec.rb index 4abc1098a..51c9247dd 100644 --- a/spec/classes/mongodb_exporter_spec.rb +++ b/spec/classes/mongodb_exporter_spec.rb @@ -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 diff --git a/spec/classes/nginx_vts_exporter_spec.rb b/spec/classes/nginx_vts_exporter_spec.rb index 7cec68198..386da428d 100644 --- a/spec/classes/nginx_vts_exporter_spec.rb +++ b/spec/classes/nginx_vts_exporter_spec.rb @@ -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 diff --git a/spec/classes/node_exporter_spec.rb b/spec/classes/node_exporter_spec.rb index 618164a2f..02490031d 100644 --- a/spec/classes/node_exporter_spec.rb +++ b/spec/classes/node_exporter_spec.rb @@ -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 diff --git a/spec/classes/prometheus_spec.rb b/spec/classes/prometheus_spec.rb index 55ef905db..d19c75526 100644 --- a/spec/classes/prometheus_spec.rb +++ b/spec/classes/prometheus_spec.rb @@ -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| diff --git a/spec/classes/pushgateway_spec.rb b/spec/classes/pushgateway_spec.rb index ef7dd69f9..daa8fdcdb 100644 --- a/spec/classes/pushgateway_spec.rb +++ b/spec/classes/pushgateway_spec.rb @@ -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 diff --git a/spec/classes/rabbitmq_exporter_spec.rb b/spec/classes/rabbitmq_exporter_spec.rb index 4aeef756d..548367d4d 100644 --- a/spec/classes/rabbitmq_exporter_spec.rb +++ b/spec/classes/rabbitmq_exporter_spec.rb @@ -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 diff --git a/spec/classes/redis_exporter_spec.rb b/spec/classes/redis_exporter_spec.rb index 93be13b5b..284426b09 100644 --- a/spec/classes/redis_exporter_spec.rb +++ b/spec/classes/redis_exporter_spec.rb @@ -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 diff --git a/spec/classes/snmp_exporter_spec.rb b/spec/classes/snmp_exporter_spec.rb index da10b25fd..50599eafc 100644 --- a/spec/classes/snmp_exporter_spec.rb +++ b/spec/classes/snmp_exporter_spec.rb @@ -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 diff --git a/spec/defines/alerts_spec.rb b/spec/defines/alerts_spec.rb index 6abbb4185..a578f964e 100644 --- a/spec/defines/alerts_spec.rb +++ b/spec/defines/alerts_spec.rb @@ -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 diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb index 6d76d2995..2da50e866 100644 --- a/spec/defines/daemon_spec.rb +++ b/spec/defines/daemon_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cdd493591..95902045c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,4 +28,5 @@ c.default_facts = default_facts end +require 'spec_helper_methods' # vim: syntax=ruby diff --git a/spec/spec_helper_methods.rb b/spec/spec_helper_methods.rb new file mode 100644 index 000000000..0e8617dee --- /dev/null +++ b/spec/spec_helper_methods.rb @@ -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: 'sysv' } + when '9' + { service_provider: 'systemd' } + when '14.04' + { service_provider: 'upstart' } + when '16.04' + { service_provider: 'sysv' } + end + when 'RedHat' + case facts[:os]['release']['major'] + when '6' + { service_provider: 'sysv' } + when '7' + { service_provider: 'systemd' } + end + end +end