From a5b44c812b3ddc03086d60d36835d261554d7244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Tue, 25 Aug 2020 14:13:57 -0300 Subject: [PATCH] fix(archive): add config file to service only if defined --- prometheus/archive/install.sls | 2 +- .../default/controls/archive_spec.rb | 4 +- .../default/controls/service_spec.rb | 44 ++++++++----------- test/salt/pillar/default.sls | 9 ---- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 64dfb7b..abef357 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -103,7 +103,7 @@ prometheus-archive-install-{{ name }}-managed-service: group: {{ name }} workdir: {{ p.dir.var }}/{{ name }} stop: '' - {%- if name in ('node_exporter', 'consul_exporter') %} + {%- if name in ('node_exporter', 'consul_exporter') or 'config_file' not in p.pkg.component[name] %} start: {{ p.pkg.component[name]['path'] }}/{{ name }} {%- else %} start: {{ p.pkg.component[name]['path'] }}/{{ name }} --config.file {{ p.pkg.component[name]['config_file'] }} # noqa 204 diff --git a/test/integration/default/controls/archive_spec.rb b/test/integration/default/controls/archive_spec.rb index f12d61c..613307f 100644 --- a/test/integration/default/controls/archive_spec.rb +++ b/test/integration/default/controls/archive_spec.rb @@ -7,9 +7,11 @@ control 'prometheus components' do when 'debian' service_dir = '/lib/systemd/system' alert_manager_service = 'prometheus-alertmanager' + node_exporter_service = 'prometheus-node-exporter' else service_dir = '/usr/lib/systemd/system' alert_manager_service = 'alertmanager' + node_exporter_service = 'node_exporter' end # describe package('cron') do @@ -82,7 +84,7 @@ control 'prometheus components' do it { should exist } its('group') { should eq 'node_exporter' } end - describe file("#{service_dir}/node_exporter.service") do + describe file("#{service_dir}/#{node_exporter_service}.service") do it { should exist } its('group') { should eq 'root' } its('mode') { should cmp '0644' } diff --git a/test/integration/default/controls/service_spec.rb b/test/integration/default/controls/service_spec.rb index 8a57f63..24178ff 100644 --- a/test/integration/default/controls/service_spec.rb +++ b/test/integration/default/controls/service_spec.rb @@ -1,39 +1,31 @@ # frozen_string_literal: true -control 'services with a consistent service name across distros' do - title 'should be running' - - # we forced node_exporter's service name to `node_exporter` in the pillar, - # so its name will be the same across distros for this test - describe service('node_exporter') do - it { should be_enabled } - it { should be_running } - end - - # node_exporter port - describe port(9100) do - it { should be_listening } - end -end - control 'services with a consistent service name on each distro' do title 'should be running' - # if we don't set a service name in the pillar, - # its name will be the same on each distro, no matter what the - # install method we choose - - distro_service = + distro_services = case platform[:family] when 'debian' - 'prometheus-blackbox-exporter' + %w[ + prometheus + prometheus-alertmanager + prometheus-node-exporter + prometheus-blackbox-exporter + ] else - 'blackbox_exporter' + %w[ + prometheus + alertmanager + node_exporter + blackbox_exporter + ] end - describe service(distro_service) do - it { should be_enabled } - it { should be_running } + distro_services.each do |service| + describe service(service) do + it { should be_enabled } + it { should be_running } + end end # blackbox_exporter port diff --git a/test/salt/pillar/default.sls b/test/salt/pillar/default.sls index 0d60991..f481219 100644 --- a/test/salt/pillar/default.sls +++ b/test/salt/pillar/default.sls @@ -81,15 +81,6 @@ prometheus: email_configs: - to: 'team-X+alerts@example.org' - inhibit_rules: - - name: opsGenie-receiver - opsgenie_configs: - - api_key: mysecret - - name: slack-receiver - slack_configs: - - channel: '#my-channel' - image_url: 'http://some.img.com/img.png' - node_exporter: version: v0.18.1 archive: