From 7dc25e7aeb306efea98717a8e4cfac0f0ba13ca4 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Thu, 3 Dec 2020 11:12:57 +0100 Subject: [PATCH 1/2] Add Ubuntu 20.04 support --- metadata.json | 3 ++- spec/classes/prometheus_spec.rb | 2 +- spec/classes/server_spec.rb | 2 +- spec/defines/daemon_spec.rb | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/metadata.json b/metadata.json index cde58f659..41ee0833c 100644 --- a/metadata.json +++ b/metadata.json @@ -53,7 +53,8 @@ "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", - "18.04" + "18.04", + "20.04" ] }, { diff --git a/spec/classes/prometheus_spec.rb b/spec/classes/prometheus_spec.rb index 14cf74b97..87d33dc9d 100644 --- a/spec/classes/prometheus_spec.rb +++ b/spec/classes/prometheus_spec.rb @@ -106,7 +106,7 @@ ) } - if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'virtuozzolinux-7-x86_64'].include?(os) + if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64', 'virtuozzolinux-7-x86_64'].include?(os) # 'archlinux-5-x86_64' got removed from that list. It has systemd, but we use the repo packages and their shipped unit files. # init_style = 'systemd' diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 1024fec88..cf17540d3 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -13,7 +13,7 @@ parameters end - if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64'].include?(os) + if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64'].include?(os) prom_version = parameters[:version] || '1.5.2' prom_major = prom_version[0] it { diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb index 38159face..8e536cc8b 100644 --- a/spec/defines/daemon_spec.rb +++ b/spec/defines/daemon_spec.rb @@ -91,7 +91,7 @@ it { is_expected.to contain_archive("/tmp/smurf_exporter-#{parameters[:version]}.tar.gz").with_extract_path('/opt/foo') } end - if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'archlinux-5-x86_64', 'virtuozzolinux-7-x86_64'].include?(os) + if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64', 'archlinux-5-x86_64', 'virtuozzolinux-7-x86_64'].include?(os) # init_style = 'systemd' it { is_expected.to contain_class('systemd') } From ecab404473d535ca034ef63af7934ae9f27b3af0 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Thu, 3 Dec 2020 23:12:38 +0100 Subject: [PATCH 2/2] cleanup unit test files --- spec/classes/prometheus_spec.rb | 13 ++--- spec/classes/server_spec.rb | 58 +++++++++++----------- spec/defines/daemon_spec.rb | 85 ++++++++------------------------- 3 files changed, 52 insertions(+), 104 deletions(-) diff --git a/spec/classes/prometheus_spec.rb b/spec/classes/prometheus_spec.rb index 87d33dc9d..fbdae06da 100644 --- a/spec/classes/prometheus_spec.rb +++ b/spec/classes/prometheus_spec.rb @@ -106,10 +106,10 @@ ) } - if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64', 'virtuozzolinux-7-x86_64'].include?(os) - # 'archlinux-5-x86_64' got removed from that list. It has systemd, but we use the repo packages and their shipped unit files. - # init_style = 'systemd' + if facts[:os]['name'] == 'Archlinux' + it { is_expected.not_to contain_systemd__unit_file('prometheus.service') } + else it { is_expected.to contain_class('systemd') } @@ -137,13 +137,6 @@ } end end - elsif os == 'archlinux-5-x86_64' - - it { is_expected.not_to contain_systemd__unit_file('prometheus.service') } - else - it { - is_expected.to raise_error(Puppet::Error, %r{I don't know how to create an init script for style}) - } end it { diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index cf17540d3..d9252a5f7 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -7,42 +7,40 @@ facts.merge(os_specific_facts(facts)) end - [{ version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url' }].each do |parameters| - context "with parameters #{parameters}" do - let(:params) do - parameters - end + parameters = { version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url', init_style: 'systemd', configname: 'prometheus.yaml' } + + context "with parameters #{parameters}" do + let(:params) do + parameters + end + + prom_version = parameters[:version] || '1.5.2' + prom_major = prom_version[0] + it { is_expected.to contain_class('systemd') } + + it { + is_expected.to contain_systemd__unit_file('prometheus.service').with( + 'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd")) + ) + } - if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64'].include?(os) - prom_version = parameters[:version] || '1.5.2' - prom_major = prom_version[0] + describe 'max_open_files' do + context 'by default' do it { - is_expected.to contain_class('systemd') + content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content] + expect(content).not_to include('LimitNOFILE') } + end + + context 'when set to 1000000' do + let(:params) do + super().merge('max_open_files' => 1_000_000) + end it { - is_expected.to contain_systemd__unit_file('prometheus.service').with( - 'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd")) - ) + content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content] + expect(content).to include('LimitNOFILE=1000000') } - describe 'max_open_files' do - context 'by default' do - it { - content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content] - expect(content).not_to include('LimitNOFILE') - } - end - context 'when set to 1000000' do - let(:params) do - parameters.merge('max_open_files' => 1_000_000) - end - - it { - content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content] - expect(content).to include('LimitNOFILE=1000000') - } - end - end end end end diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb index 8e536cc8b..cb9f8f502 100644 --- a/spec/defines/daemon_spec.rb +++ b/spec/defines/daemon_spec.rb @@ -91,77 +91,32 @@ it { is_expected.to contain_archive("/tmp/smurf_exporter-#{parameters[:version]}.tar.gz").with_extract_path('/opt/foo') } end - if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64', 'archlinux-5-x86_64', 'virtuozzolinux-7-x86_64'].include?(os) - # init_style = 'systemd' + it { is_expected.to contain_class('systemd') } - it { is_expected.to contain_class('systemd') } - - it { - is_expected.to contain_systemd__unit_file('smurf_exporter.service').that_notifies( - 'Service[smurf_exporter]' - ).with_content( - %r{User=smurf_user\n} - ).with_content( - %r{ExecStart=/usr/local/bin/smurf_exporter\n\nExecReload=} - ) - } - - if Gem::Version.new(facts[:puppetversion]) < Gem::Version.new('6.1.0') - it { is_expected.to contain_class('systemd::systemctl::daemon_reload').that_comes_before('Service[smurf_exporter]') } - end + it { + is_expected.to contain_systemd__unit_file('smurf_exporter.service').that_notifies( + 'Service[smurf_exporter]' + ).with_content( + %r{User=smurf_user\n} + ).with_content( + %r{ExecStart=/usr/local/bin/smurf_exporter\n\nExecReload=} + ) + } - context 'with overidden bin_name' do - let(:params) do - parameters.merge(bin_name: 'notsmurf_exporter') - end + if Gem::Version.new(facts[:puppetversion]) < Gem::Version.new('6.1.0') + it { is_expected.to contain_class('systemd::systemctl::daemon_reload').that_comes_before('Service[smurf_exporter]') } + end - it { - is_expected.to contain_systemd__unit_file('smurf_exporter.service').with_content( - %r{ExecStart=/usr/local/bin/notsmurf_exporter} - ) - } + context 'with overidden bin_name' do + let(:params) do + super().merge(bin_name: 'notsmurf_exporter') end - elsif ['ubuntu-14.04-x86_64'].include?(os) - # init_style = 'upstart' - it { - is_expected.to contain_file('/etc/init/smurf_exporter.conf').with( - 'mode' => '0444', - 'owner' => 'root', - 'group' => 'root' - ).with_content( - %r{env USER=smurf_user\n} - ).with_content( - %r{exec start-stop-daemon -c \$USER -g \$GROUP -p \$PID_FILE -x \$DAEMON -S -- \n\nend script} - ) - } - - it { - is_expected.to contain_file('/etc/init.d/smurf_exporter').with( - 'ensure' => 'link', - 'target' => '/lib/init/upstart-job', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0755' + is_expected.to contain_systemd__unit_file('smurf_exporter.service').with_content( + %r{ExecStart=/usr/local/bin/notsmurf_exporter} ) } - - context 'with overidden bin_name' do - let(:params) do - parameters.merge(bin_name: 'notsmurf_exporter') - end - - it { - is_expected.to contain_file('/etc/init/smurf_exporter.conf').with_content( - %r{env DAEMON=/usr/local/bin/notsmurf_exporter} - ) - } - end - else - it { - is_expected.to raise_error(Puppet::Error, %r{I don't know how to create an init script for style}) - } end if os == 'ubuntu-16.04-x86_64' @@ -174,7 +129,7 @@ %r{SOMEVAR="42"\n} ) } - elsif ['centos-6-x86_64', 'redhat-6-x86_64', 'centos-7-x86_64', 'redhat-7-x86_64'].include?(os) + elsif ['centos-7-x86_64', 'redhat-7-x86_64'].include?(os) it { is_expected.to contain_file('/etc/sysconfig/smurf_exporter').with( 'mode' => '0644', @@ -193,6 +148,7 @@ 'enable' => true ) } + context 'exported resources' do subject { exported_resources } @@ -206,6 +162,7 @@ end end end + context 'with scrape_job_labels specified' do let(:params) do {