|
| 1 | +require 'spec_helper_acceptance' |
| 2 | + |
| 3 | +describe 'system class' do |
| 4 | + context 'sysstat not installed and not managed' do |
| 5 | + before(:all) do |
| 6 | + run_shell('puppet resource package sysstat ensure=absent') |
| 7 | + pp = <<-MANIFEST |
| 8 | + include puppet_metrics_collector::system |
| 9 | + MANIFEST |
| 10 | + # The notify makes this non idempotent |
| 11 | + expect(apply_manifest(pp).exit_code).not_to eq(1) |
| 12 | + expect(apply_manifest(pp).exit_code).not_to eq(1) |
| 13 | + end |
| 14 | + |
| 15 | + context 'postgres timers are running' do |
| 16 | + it { expect(service('puppet_postgres-metrics.timer')).to be_running } |
| 17 | + it { expect(service('puppet_postgres-tidy.timer')).to be_running } |
| 18 | + end |
| 19 | + |
| 20 | + it 'creates tidy service file for postgres' do |
| 21 | + files = run_shell('ls /etc/systemd/system/puppet_postgres-tidy.service').stdout |
| 22 | + expect(files.split("\n")).not_to be_empty |
| 23 | + end |
| 24 | + |
| 25 | + it 'creates the service file for postgres' do |
| 26 | + files = run_shell('ls /etc/systemd/system/puppet_postgres-metrics.service').stdout |
| 27 | + expect(files.split("\n")).not_to be_empty |
| 28 | + end |
| 29 | + |
| 30 | + it 'sysstat package is not installed by default' do |
| 31 | + expect(package('sysstat')).not_to be_installed |
| 32 | + end |
| 33 | + |
| 34 | + it 'have_sysstat is false without the package installed' do |
| 35 | + expect(host_inventory['facter']['puppet_metrics_collector']['have_sysstat']).to eq false |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context 'sysstat installed and not managed' do |
| 40 | + before(:all) do |
| 41 | + run_shell('puppet resource package sysstat ensure=installed') |
| 42 | + pp = <<-MANIFEST |
| 43 | + include puppet_metrics_collector::system |
| 44 | + MANIFEST |
| 45 | + expect(apply_manifest(pp).exit_code).not_to eq(1) |
| 46 | + expect(apply_manifest(pp).exit_code).not_to eq(1) |
| 47 | + end |
| 48 | + |
| 49 | + it 'system puppet_* metric services should be active or inactive' do |
| 50 | + run_shell('systemctl list-units --type=service | grep "puppet_system.*metrics"') do |r| |
| 51 | + expect(r.stdout).to match(%r{activ}) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + context 'system timers are running' do |
| 56 | + it { expect(service('puppet_system_cpu-metrics.timer')).to be_running } |
| 57 | + it { expect(service('puppet_system_cpu-tidy.timer')).to be_running } |
| 58 | + it { expect(service('puppet_system_memory-metrics.timer')).to be_running } |
| 59 | + it { expect(service('puppet_system_memory-tidy.timer')).to be_running } |
| 60 | + it { expect(service('puppet_system_processes-metrics.timer')).to be_running } |
| 61 | + it { expect(service('puppet_system_processes-tidy.timer')).to be_running } |
| 62 | + end |
| 63 | + |
| 64 | + it 'creates system tidy services files' do |
| 65 | + files = run_shell('ls /etc/systemd/system/puppet_system*-tidy.service').stdout |
| 66 | + expect(files.split("\n").count).to eq(3) |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + context 'managing sysstat' do |
| 71 | + before(:all) do |
| 72 | + pp = <<-MANIFEST |
| 73 | + class { 'puppet_metrics_collector::system': |
| 74 | + manage_sysstat => true, |
| 75 | + } |
| 76 | + MANIFEST |
| 77 | + expect(apply_manifest(pp).exit_code).not_to eq(1) |
| 78 | + expect(apply_manifest(pp).exit_code).not_to eq(1) |
| 79 | + end |
| 80 | + |
| 81 | + it 'sysstat package is installed' do |
| 82 | + expect(package('sysstat')).to be_installed |
| 83 | + end |
| 84 | + |
| 85 | + it 'system puppet_* metric services should be active or inactive' do |
| 86 | + run_shell('systemctl list-units --type=service | grep "puppet_system.*metrics"') do |r| |
| 87 | + expect(r.stdout).to match(%r{activ}) |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + context 'system timers are running' do |
| 92 | + it { expect(service('puppet_system_cpu-metrics.timer')).to be_running } |
| 93 | + it { expect(service('puppet_system_cpu-tidy.timer')).to be_running } |
| 94 | + it { expect(service('puppet_system_memory-metrics.timer')).to be_running } |
| 95 | + it { expect(service('puppet_system_memory-tidy.timer')).to be_running } |
| 96 | + it { expect(service('puppet_system_processes-metrics.timer')).to be_running } |
| 97 | + it { expect(service('puppet_system_processes-tidy.timer')).to be_running } |
| 98 | + end |
| 99 | + |
| 100 | + it 'creates system tidy services files' do |
| 101 | + files = run_shell('ls /etc/systemd/system/puppet_system*-tidy.service').stdout |
| 102 | + expect(files.split("\n").count).to eq(3) |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments