Revision 2958c56e test/ganeti-cleaner_unittest.bash

b/test/ganeti-cleaner_unittest.bash
24 24
export PYTHON=${PYTHON:=python}
25 25

  
26 26
GNTC=daemons/ganeti-cleaner
27
GNTMC=daemons/ganeti-master-cleaner
27 28
CCE=tools/check-cert-expired
28 29

  
29 30
err() {
......
44 45
}
45 46

  
46 47
check_logfiles() {
47
  local n=$1
48
  [[ "$(find $tmpls/log/ganeti/cleaner -mindepth 1 | wc -l)" -le "$n" ]] || \
48
  local n=$1 p=$2 path
49
  if [[ "$p2" = master ]]; then
50
    path=$tmpls/log/ganeti/mastercleaner
51
  else
52
    path=$tmpls/log/ganeti/cleaner
53
  fi
54
  [[ "$(find $path -mindepth 1 | wc -l)" -le "$n" ]] || \
49 55
    err "Found more than $n logfiles"
50 56
}
51 57

  
......
77 83
}
78 84

  
79 85
run_cleaner() {
80
  CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $GNTC
86
  local cmd
87

  
88
  if [[ "$1" = master ]]; then
89
    cmd=$GNTMC
90
  else
91
    cmd=$GNTC
92
  fi
93

  
94
  CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $cmd
81 95
}
82 96

  
83 97
create_archived_jobs() {
......
162 176
test -d $tmpls/log/ganeti/cleaner || err 'log/ganeti/cleaner should exist'
163 177
check_logfiles 1
164 178

  
165
upto 'Checking number of retained log files'
179
test -d $tmpls/log/ganeti/master-cleaner && \
180
  err 'log/ganeti/master-cleaner should not exist yet'
181
run_cleaner master
182
test -d $tmpls/log/ganeti/master-cleaner || \
183
  err 'log/ganeti/master-cleaner should exist'
184
check_logfiles 1 master
185

  
186
upto 'Checking number of retained log files (master)'
187
for (( i=0; i < (maxlog + 10); ++i )); do
188
  run_cleaner master
189
  check_logfiles 1
190
  check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) )) master
191
done
192

  
193
upto 'Checking number of retained log files (node)'
166 194
for (( i=0; i < (maxlog + 10); ++i )); do
167 195
  run_cleaner
168 196
  check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) ))
197
  check_logfiles $maxlog master
169 198
done
170 199

  
171 200
upto 'Removal of archived jobs (non-master)'
......
175 204
  err 'ssconf_master_node should not exist'
176 205
run_cleaner
177 206
count_jobs 55
207
run_cleaner master
208
count_jobs 55
178 209

  
179 210
upto 'Removal of archived jobs (master node)'
180 211
create_archived_jobs
181 212
count_jobs 55
182 213
echo $HOSTNAME > $tmpls/lib/ganeti/ssconf_master_node
183 214
run_cleaner
215
count_jobs 55
216
run_cleaner master
184 217
count_jobs 31
185 218

  
186 219
upto 'Certificate expiration'
......
191 224
create_certdirs $tmpdir/expcert bar{x,y,z}999 fx0ljoImWr em3RBC0U8c
192 225
create_certdirs '' empty{1,2,3} gd2HCvRc iFG55Z0a PP28v5kg
193 226
count_and_check_certs 10
227
run_cleaner master
228
count_and_check_certs 10
194 229
run_cleaner
195 230
count_and_check_certs 5
196 231

  
197 232
check_logfiles $maxlog
233
check_logfiles $maxlog master
198 234
count_jobs 31
199 235

  
200 236
upto 'Watcher status files'
201 237
create_watcher_state
202 238
count_watcher data 10
203 239
count_watcher instance-status 10
240
run_cleaner master
241
count_watcher data 10
242
count_watcher instance-status 10
204 243
run_cleaner
205 244
count_watcher data 5
206 245
count_watcher instance-status 5

Also available in: Unified diff