Skip to content

Commit 19a613c

Browse files
committed
(SUP-2557) Ensure backup class is not included
Prior to this commit, by default the pe_databases::backup class would be included but not do anything. That was because the logic for the class parameter was correct disable_maintenance => ! $manage_database_backups But the logic to include the class was not if defined('$manage_database_backups') This commit fixes this logic and adds spec tests to cover it. I also moved the test for checking the cron resources from an acceptance test to spec.
1 parent 62c1e51 commit 19a613c

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

manifests/init.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
include pe_databases::postgresql_settings::table_settings
4444
}
4545
}
46-
if defined('$manage_database_backups') {
46+
# Because this parameter is a value of undef with a data type of Undef,
47+
# We can the NotUndef type to determine if the value has been set
48+
if $manage_database_backups =~ NotUndef {
4749
class { 'pe_databases::backup':
4850
disable_maintenance => ! $manage_database_backups,
4951
}

spec/acceptance/backup_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ class { 'pe_databases':
1111
# Run it twice and test for idempotency
1212
idempotent_apply(pp)
1313
end
14-
it 'checks if backup cron jobs are up' do
15-
run_shell('crontab -l -u pe-postgres') do |r|
16-
expect(r.stdout).to match(%r{pe-activity, pe-classifier, pe-inventory, pe-orchestrator, pe-postgres, pe-rbac})
17-
expect(r.stdout).to match(%r{pe-puppetdb})
18-
end
19-
end
2014
end

spec/classes/backup_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'spec_helper'
2+
3+
describe 'pe_databases::backup' do
4+
context 'when backing up tables' do
5+
let (:pre_condition) {'include pe_databases'}
6+
it {
7+
# I have no idea how this works, but these are the resources we should end up with
8+
is_expected.to contain_cron('puppet_enterprise_database_backup_[pe-activity, pe-classifier, pe-inventory, pe-orchestrator, pe-postgres, pe-rbac]')
9+
is_expected.to contain_cron('puppet_enterprise_database_backup_[pe-puppetdb]')
10+
}
11+
end
12+
end

spec/classes/init_spec.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
require 'spec_helper'
22

33
describe 'pe_databases' do
4-
let(:params) do
5-
{
6-
manage_database_backups: false,
7-
manage_postgresql_settings: false,
8-
manage_table_settings: false,
9-
}
10-
end
11-
124
on_supported_os.each do |os, os_facts|
135
context "on #{os}" do
146
let(:facts) { os_facts }
@@ -32,4 +24,13 @@
3224

3325
it { is_expected.to contain_notify('pe_databases_systemd_warn') }
3426
end
27+
28+
context 'backups are not included by default' do
29+
it { is_expected.to_not contain_class('pe_databases::backup') }
30+
end
31+
32+
context 'backups are included if configured' do
33+
let(:params) { {manage_database_backups: true} }
34+
it { is_expected.to contain_class('pe_databases::backup') }
35+
end
3536
end

0 commit comments

Comments
 (0)