Mercurial > repos > other > Puppet
comparison modules/mysql/spec/classes/mysql_server_backup_spec.rb @ 0:956e484adc12
Initial public release of Puppet configs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Aug 2014 19:47:38 +0000 |
parents | |
children | 58d1818c2ded |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:956e484adc12 |
---|---|
1 require 'spec_helper' | |
2 | |
3 describe 'mysql::server::backup' do | |
4 | |
5 let(:default_params) { | |
6 { 'backupuser' => 'testuser', | |
7 'backuppassword' => 'testpass', | |
8 'backupdir' => '/tmp', | |
9 'backuprotate' => '25', | |
10 'delete_before_dump' => true, | |
11 'execpath' => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', | |
12 } | |
13 } | |
14 context 'standard conditions' do | |
15 let(:params) { default_params } | |
16 | |
17 it { should contain_mysql_user('testuser@localhost').with( | |
18 :require => 'Class[Mysql::Server::Root_password]' | |
19 )} | |
20 | |
21 it { should contain_mysql_grant('testuser@localhost/*.*').with( | |
22 :privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW", "PROCESS"] | |
23 )} | |
24 | |
25 it { should contain_cron('mysql-backup').with( | |
26 :command => '/usr/local/sbin/mysqlbackup.sh', | |
27 :ensure => 'present' | |
28 )} | |
29 | |
30 it { should contain_file('mysqlbackup.sh').with( | |
31 :path => '/usr/local/sbin/mysqlbackup.sh', | |
32 :ensure => 'present' | |
33 ) } | |
34 | |
35 it { should contain_file('mysqlbackupdir').with( | |
36 :path => '/tmp', | |
37 :ensure => 'directory' | |
38 )} | |
39 | |
40 it 'should have compression by default' do | |
41 verify_contents(subject, 'mysqlbackup.sh', [ | |
42 ' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2', | |
43 ]) | |
44 end | |
45 it 'should skip backing up events table by default' do | |
46 verify_contents(subject, 'mysqlbackup.sh', [ | |
47 'EVENTS="--ignore-table=mysql.event"', | |
48 ]) | |
49 end | |
50 | |
51 it 'should have 25 days of rotation' do | |
52 # MySQL counts from 0 I guess. | |
53 should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) | |
54 end | |
55 | |
56 it 'should have a standard PATH' do | |
57 should contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin}) | |
58 end | |
59 end | |
60 | |
61 context 'custom ownership and mode for backupdir' do | |
62 let(:params) do | |
63 { :backupdirmode => '0750', | |
64 :backupdirowner => 'testuser', | |
65 :backupdirgroup => 'testgrp', | |
66 }.merge(default_params) | |
67 end | |
68 | |
69 it { should contain_file('mysqlbackupdir').with( | |
70 :path => '/tmp', | |
71 :ensure => 'directory', | |
72 :mode => '0750', | |
73 :owner => 'testuser', | |
74 :group => 'testgrp' | |
75 ) } | |
76 end | |
77 | |
78 context 'with compression disabled' do | |
79 let(:params) do | |
80 { :backupcompress => false }.merge(default_params) | |
81 end | |
82 | |
83 it { should contain_file('mysqlbackup.sh').with( | |
84 :path => '/usr/local/sbin/mysqlbackup.sh', | |
85 :ensure => 'present' | |
86 ) } | |
87 | |
88 it 'should be able to disable compression' do | |
89 verify_contents(subject, 'mysqlbackup.sh', [ | |
90 ' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql', | |
91 ]) | |
92 end | |
93 end | |
94 | |
95 context 'with mysql.events backedup' do | |
96 let(:params) do | |
97 { :ignore_events => false }.merge(default_params) | |
98 end | |
99 | |
100 it { should contain_file('mysqlbackup.sh').with( | |
101 :path => '/usr/local/sbin/mysqlbackup.sh', | |
102 :ensure => 'present' | |
103 ) } | |
104 | |
105 it 'should be able to backup events table' do | |
106 verify_contents(subject, 'mysqlbackup.sh', [ | |
107 'EVENTS="--events"', | |
108 ]) | |
109 end | |
110 end | |
111 | |
112 | |
113 context 'with database list specified' do | |
114 let(:params) do | |
115 { :backupdatabases => ['mysql'] }.merge(default_params) | |
116 end | |
117 | |
118 it { should contain_file('mysqlbackup.sh').with( | |
119 :path => '/usr/local/sbin/mysqlbackup.sh', | |
120 :ensure => 'present' | |
121 ) } | |
122 | |
123 it 'should have a backup file for each database' do | |
124 content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content] | |
125 content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') | |
126 # verify_contents(subject, 'mysqlbackup.sh', [ | |
127 # ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql', | |
128 # ]) | |
129 end | |
130 end | |
131 | |
132 context 'with file per database' do | |
133 let(:params) do | |
134 default_params.merge({ :file_per_database => true }) | |
135 end | |
136 | |
137 it 'should loop through backup all databases' do | |
138 verify_contents(subject, 'mysqlbackup.sh', [ | |
139 'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname', | |
140 'do', | |
141 ' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\', | |
142 ' ${EVENTS} \\', | |
143 ' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2', | |
144 'done', | |
145 ]) | |
146 end | |
147 | |
148 context 'with compression disabled' do | |
149 let(:params) do | |
150 default_params.merge({ :file_per_database => true, :backupcompress => false }) | |
151 end | |
152 | |
153 it 'should loop through backup all databases without compression' do | |
154 verify_contents(subject, 'mysqlbackup.sh', [ | |
155 ' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql', | |
156 ]) | |
157 end | |
158 end | |
159 end | |
160 | |
161 context 'with postscript' do | |
162 let(:params) do | |
163 default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' }) | |
164 end | |
165 | |
166 it 'should be add postscript' do | |
167 verify_contents(subject, 'mysqlbackup.sh', [ | |
168 'rsync -a /tmp backup01.local-lan:', | |
169 ]) | |
170 end | |
171 end | |
172 | |
173 context 'with postscripts' do | |
174 let(:params) do | |
175 default_params.merge({ :postscript => [ | |
176 'rsync -a /tmp backup01.local-lan:', | |
177 'rsync -a /tmp backup02.local-lan:', | |
178 ]}) | |
179 end | |
180 | |
181 it 'should be add postscript' do | |
182 verify_contents(subject, 'mysqlbackup.sh', [ | |
183 'rsync -a /tmp backup01.local-lan:', | |
184 'rsync -a /tmp backup02.local-lan:', | |
185 ]) | |
186 end | |
187 end | |
188 end |