Revision 46118ed2 test/ganeti-cleaner_unittest.bash

b/test/ganeti-cleaner_unittest.bash
1 1
#!/bin/bash
2 2
#
3 3

  
4
# Copyright (C) 2010 Google Inc.
4
# Copyright (C) 2010, 2012 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 19
# 02110-1301, USA.
20 20

  
21
set -e
21
set -e -u
22 22
set -o pipefail
23 23

  
24 24
export PYTHON=${PYTHON:=python}
25 25

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

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

  
47 46
check_logfiles() {
48 47
  local n=$1 p=$2 path
49
  if [[ "$p2" = master ]]; then
50
    path=$tmpls/log/ganeti/mastercleaner
48
  if [[ "$p" = master ]]; then
49
    path=$tmpls/log/ganeti/master-cleaner
51 50
  else
52 51
    path=$tmpls/log/ganeti/cleaner
53 52
  fi
53

  
54
  test -d $path || \
55
    err "Log file directory '$path' not created"
56

  
54 57
  [[ "$(find $path -mindepth 1 | wc -l)" -le "$n" ]] || \
55 58
    err "Found more than $n logfiles"
56 59
}
......
83 86
}
84 87

  
85 88
run_cleaner() {
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
89
  CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $GNTC $1
95 90
}
96 91

  
97 92
create_archived_jobs() {
......
172 167
test -d $tmpls/log/ganeti || err 'log/ganeti does not exist'
173 168
test -d $tmpls/log/ganeti/cleaner && \
174 169
  err 'log/ganeti/cleaner should not exist yet'
175
run_cleaner
176
test -d $tmpls/log/ganeti/cleaner || err 'log/ganeti/cleaner should exist'
177
check_logfiles 1
170
run_cleaner node
171
check_logfiles 1 node
178 172

  
179 173
test -d $tmpls/log/ganeti/master-cleaner && \
180 174
  err 'log/ganeti/master-cleaner should not exist yet'
181 175
run_cleaner master
182
test -d $tmpls/log/ganeti/master-cleaner || \
183
  err 'log/ganeti/master-cleaner should exist'
184 176
check_logfiles 1 master
185 177

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

  
193 185
upto 'Checking number of retained log files (node)'
194 186
for (( i=0; i < (maxlog + 10); ++i )); do
195
  run_cleaner
196
  check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) ))
187
  run_cleaner node
188
  check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) )) node
197 189
  check_logfiles $maxlog master
198 190
done
199 191

  
......
202 194
count_jobs 55
203 195
test -f $tmpls/lib/ganeti/ssconf_master_node && \
204 196
  err 'ssconf_master_node should not exist'
205
run_cleaner
197
run_cleaner node
206 198
count_jobs 55
207 199
run_cleaner master
208 200
count_jobs 55
......
211 203
create_archived_jobs
212 204
count_jobs 55
213 205
echo $HOSTNAME > $tmpls/lib/ganeti/ssconf_master_node
214
run_cleaner
206
run_cleaner node
215 207
count_jobs 55
216 208
run_cleaner master
217 209
count_jobs 31
......
226 218
count_and_check_certs 10
227 219
run_cleaner master
228 220
count_and_check_certs 10
229
run_cleaner
221
run_cleaner node
230 222
count_and_check_certs 5
231 223

  
232
check_logfiles $maxlog
224
check_logfiles $maxlog node
233 225
check_logfiles $maxlog master
234 226
count_jobs 31
235 227

  
......
240 232
run_cleaner master
241 233
count_watcher data 10
242 234
count_watcher instance-status 10
243
run_cleaner
235
run_cleaner node
244 236
count_watcher data 5
245 237
count_watcher instance-status 5
246 238

  

Also available in: Unified diff