|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'mysql::backup::xtrabackup' do |
| 4 | + on_supported_os.each do |os, facts| |
| 5 | + context "on #{os}" do |
| 6 | + let(:pre_condition) do |
| 7 | + <<-EOF |
| 8 | + class { 'mysql::server': } |
| 9 | + EOF |
| 10 | + end |
| 11 | + let(:facts) do |
| 12 | + facts.merge(root_home: '/root') |
| 13 | + end |
| 14 | + |
| 15 | + let(:default_params) do |
| 16 | + { 'backupdir' => '/tmp' } |
| 17 | + end |
| 18 | + |
| 19 | + context 'with defaults' do |
| 20 | + let(:params) do |
| 21 | + default_params |
| 22 | + end |
| 23 | + |
| 24 | + it 'contains the wrapper script' do |
| 25 | + is_expected.to contain_file('xtrabackup.sh').with_content( |
| 26 | + %r{(\n*^xtrabackup\s+.*\$@)}, |
| 27 | + ) |
| 28 | + end |
| 29 | + |
| 30 | + it 'contains the weekly cronjob' do |
| 31 | + is_expected.to contain_cron('xtrabackup-weekly') |
| 32 | + .with( |
| 33 | + ensure: 'present', |
| 34 | + command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp --backup', |
| 35 | + user: 'root', |
| 36 | + hour: '23', |
| 37 | + minute: '5', |
| 38 | + weekday: '0', |
| 39 | + ) |
| 40 | + .that_requires('Package[percona-xtrabackup]') |
| 41 | + end |
| 42 | + |
| 43 | + it 'contains the daily cronjob for weekdays 1-6' do |
| 44 | + is_expected.to contain_cron('xtrabackup-daily') |
| 45 | + .with( |
| 46 | + ensure: 'present', |
| 47 | + command: '/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp --target-dir=/tmp/`date +%F_%H-%M-%S` --backup', |
| 48 | + user: 'root', |
| 49 | + hour: '23', |
| 50 | + minute: '5', |
| 51 | + weekday: '1-6', |
| 52 | + ) |
| 53 | + .that_requires('Package[percona-xtrabackup]') |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context 'with backupuser and backuppassword' do |
| 58 | + let(:params) do |
| 59 | + { backupuser: 'backupuser', |
| 60 | + backuppassword: 'backuppassword' }.merge(default_params) |
| 61 | + end |
| 62 | + |
| 63 | + it 'contains the defined mysql user' do |
| 64 | + is_expected.to contain_mysql_user('backupuser@localhost') |
| 65 | + .with( |
| 66 | + ensure: 'present', |
| 67 | + password_hash: '*4110E08DF51E70A4BA1D4E33A84205E38CF3FE58', |
| 68 | + ) |
| 69 | + .that_requires('Class[mysql::server::root_password]') |
| 70 | + |
| 71 | + is_expected.to contain_mysql_grant('backupuser@localhost/*.*') |
| 72 | + .with( |
| 73 | + ensure: 'present', |
| 74 | + user: 'backupuser@localhost', |
| 75 | + table: '*.*', |
| 76 | + privileges: ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT'], |
| 77 | + ) |
| 78 | + .that_requires('Mysql_user[backupuser@localhost]') |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + context 'with additional cron args' do |
| 83 | + let(:params) do |
| 84 | + { additional_cron_args: '--backup --skip-ssl' }.merge(default_params) |
| 85 | + end |
| 86 | + |
| 87 | + it 'contains the weekly cronjob' do |
| 88 | + is_expected.to contain_cron('xtrabackup-weekly') |
| 89 | + .with( |
| 90 | + ensure: 'present', |
| 91 | + command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp --backup --skip-ssl', |
| 92 | + user: 'root', |
| 93 | + hour: '23', |
| 94 | + minute: '5', |
| 95 | + weekday: '0', |
| 96 | + ) |
| 97 | + .that_requires('Package[percona-xtrabackup]') |
| 98 | + end |
| 99 | + |
| 100 | + it 'contains the daily cronjob for weekdays 1-6' do |
| 101 | + is_expected.to contain_cron('xtrabackup-daily') |
| 102 | + .with( |
| 103 | + ensure: 'present', |
| 104 | + command: '/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp --target-dir=/tmp/`date +%F_%H-%M-%S` --backup --skip-ssl', |
| 105 | + user: 'root', |
| 106 | + hour: '23', |
| 107 | + minute: '5', |
| 108 | + weekday: '1-6', |
| 109 | + ) |
| 110 | + .that_requires('Package[percona-xtrabackup]') |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + context 'with deactivated incremental backups' do |
| 115 | + let(:params) do |
| 116 | + { incremental_backups: false }.merge(default_params) |
| 117 | + end |
| 118 | + |
| 119 | + it 'not contains the weekly cronjob' do |
| 120 | + is_expected.not_to contain_cron('xtrabackup-weekly') |
| 121 | + end |
| 122 | + |
| 123 | + it 'contains the daily cronjob with all weekdays' do |
| 124 | + is_expected.to contain_cron('xtrabackup-daily').with( |
| 125 | + ensure: 'present', |
| 126 | + command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp --backup', |
| 127 | + user: 'root', |
| 128 | + hour: '23', |
| 129 | + minute: '5', |
| 130 | + weekday: '*', |
| 131 | + ) |
| 132 | + end |
| 133 | + end |
| 134 | + |
| 135 | + context 'with prescript defined' do |
| 136 | + let(:params) do |
| 137 | + { prescript: ['rsync -a /tmp backup01.local-lan:', |
| 138 | + 'rsync -a /tmp backup02.local-lan:'] }.merge(default_params) |
| 139 | + end |
| 140 | + |
| 141 | + it 'contains the prescript' do |
| 142 | + is_expected.to contain_file('xtrabackup.sh').with_content( |
| 143 | + %r{.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*}, |
| 144 | + ) |
| 145 | + end |
| 146 | + end |
| 147 | + |
| 148 | + context 'with postscript defined' do |
| 149 | + let(:params) do |
| 150 | + { postscript: ['rsync -a /tmp backup01.local-lan:', |
| 151 | + 'rsync -a /tmp backup02.local-lan:'] }.merge(default_params) |
| 152 | + end |
| 153 | + |
| 154 | + it 'contains the prostscript' do |
| 155 | + is_expected.to contain_file('xtrabackup.sh').with_content( |
| 156 | + %r{.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*}, |
| 157 | + ) |
| 158 | + end |
| 159 | + end |
| 160 | + |
| 161 | + context 'with mariabackup' do |
| 162 | + let(:params) do |
| 163 | + { backupmethod: 'mariabackup' }.merge(default_params) |
| 164 | + end |
| 165 | + |
| 166 | + it 'contain the mariabackup executor' do |
| 167 | + is_expected.to contain_file('xtrabackup.sh').with_content( |
| 168 | + %r{(\n*^mariabackup\s+.*\$@)}, |
| 169 | + ) |
| 170 | + end |
| 171 | + end |
| 172 | + end |
| 173 | + end |
| 174 | + # rubocop:enable RSpec/NestedGroups |
| 175 | +end |
0 commit comments