4 # Copyright (C) 2010, 2012 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 export PYTHON=${PYTHON:=python}
26 GNTC=daemons/ganeti-cleaner
27 CCE=tools/check-cert-expired
36 echo "$(date '+%F %T'):" "$@" '...'
40 local path=$1 validity=$2
41 VALIDITY=$validity $PYTHON \
42 ${TOP_SRCDIR:-.}/test/import-export_unittest-helper \
48 if [[ "$p" = master ]]; then
49 path=$tmpls/log/ganeti/master-cleaner
51 path=$tmpls/log/ganeti/cleaner
55 err "Log file directory '$path' not created"
57 [[ "$(find $path -mindepth 1 | wc -l)" -le "$n" ]] || \
58 err "Found more than $n logfiles"
63 local count=$(find $queuedir -mindepth 1 -type f | wc -l)
64 [[ "$count" -eq "$n" ]] || err "Found $count jobs instead of $n"
68 local suffix="$1" n=$2
69 local count=$(find $watcherdir -maxdepth 1 -type f \
70 -name "watcher.*-*-*-*.$suffix" | wc -l)
71 [[ "$count" -eq "$n" ]] || \
72 err "Found $count watcher files with suffix '$suffix' instead of $n"
75 count_and_check_certs() {
77 local count=$(find $cryptodir -mindepth 1 -type f -name cert | wc -l)
78 [[ "$count" -eq "$n" ]] || err "Found $count certificates instead of $n"
80 find $cryptodir -mindepth 1 -type d | \
82 [[ ( -e $dir/key && -e $dir/cert ) ||
83 ( ! -e $dir/cert && ! -e $dir/key ) ]] || \
84 err 'Inconsistent cert/key directory found'
89 CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $GNTC $1
92 create_archived_jobs() {
93 local i jobdir touchargs
94 local jobarchive=$queuedir/archive
95 local old_ts=$(date -d '25 days ago' +%Y%m%d%H%M)
97 # Remove jobs from previous run
98 find $jobarchive -mindepth 1 -type f | xargs -r rm
101 for job_id in {1..50} 469581574 19857 1420164 494433 2448521
103 jobdir=$jobarchive/$(( job_id / 10 ))
104 test -d $jobdir || mkdir $jobdir
106 if (( i % 3 == 0 || i % 7 == 0 )); then
107 touchargs="-t $old_ts"
111 touch $touchargs $jobdir/job-$job_id
117 create_watcher_state() {
119 6792a0d5-f8b6-4531-8d8c-3680c86b8a53
120 ab74da37-f5f7-44c4-83ad-074159772593
121 fced2e48-ffff-43ae-919e-2b77d37ecafa
122 6e89ac57-2eb1-4a16-85a1-94daa815d643
123 8714e8f5-59c4-47db-b2cb-196ec37978e5
124 91763d73-e1f3-47c7-a735-57025d4e2a7d
125 e27d3ff8-9546-4e86-86a4-04151223e140
126 aa3f63dd-be17-4ac8-bd01-d71790e124cb
127 05b6d7e2-003b-40d9-a6d6-ab61bf123a15
128 54c93e4c-61fe-40de-b47e-2a8e6c805d02
132 for uuid in ${uuids[@]}; do
133 touch -d "$(( 5 * i )) days ago" \
134 $watcherdir/watcher.$uuid.{data,instance-status}
144 certdir=$cryptodir/$name
146 if [[ -n "$cert" ]]; then
147 cp $cert $certdir/cert
148 cp $cert $certdir/key
154 trap "rm -rf $tmpdir" EXIT
156 # Temporary localstatedir
158 queuedir=$tmpls/lib/ganeti/queue
159 cryptodir=$tmpls/run/ganeti/crypto
160 watcherdir=$tmpls/lib/ganeti
162 mkdir -p $tmpls/{lib,log,run}/ganeti $queuedir/archive $cryptodir
166 upto 'Checking log directory creation'
167 test -d $tmpls/log/ganeti || err 'log/ganeti does not exist'
168 test -d $tmpls/log/ganeti/cleaner && \
169 err 'log/ganeti/cleaner should not exist yet'
171 check_logfiles 1 node
173 test -d $tmpls/log/ganeti/master-cleaner && \
174 err 'log/ganeti/master-cleaner should not exist yet'
176 check_logfiles 1 master
178 upto 'Checking number of retained log files (master)'
179 for (( i=0; i < (maxlog + 10); ++i )); do
181 check_logfiles 1 node
182 check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) )) master
185 upto 'Checking number of retained log files (node)'
186 for (( i=0; i < (maxlog + 10); ++i )); do
188 check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) )) node
189 check_logfiles $maxlog master
192 upto 'Removal of archived jobs (non-master)'
195 test -f $tmpls/lib/ganeti/ssconf_master_node && \
196 err 'ssconf_master_node should not exist'
202 upto 'Removal of archived jobs (master node)'
205 echo $HOSTNAME > $tmpls/lib/ganeti/ssconf_master_node
211 upto 'Certificate expiration'
212 gencert $tmpdir/validcert 30 & vcpid=${!}
213 gencert $tmpdir/expcert -30 & ecpid=${!}
215 create_certdirs $tmpdir/validcert foo{a,b,c}123 trvRMH4Wvt OfDlh6Pc2n
216 create_certdirs $tmpdir/expcert bar{x,y,z}999 fx0ljoImWr em3RBC0U8c
217 create_certdirs '' empty{1,2,3} gd2HCvRc iFG55Z0a PP28v5kg
218 count_and_check_certs 10
220 count_and_check_certs 10
222 count_and_check_certs 5
224 check_logfiles $maxlog node
225 check_logfiles $maxlog master
228 upto 'Watcher status files'
230 count_watcher data 10
231 count_watcher instance-status 10
233 count_watcher data 10
234 count_watcher instance-status 10
237 count_watcher instance-status 5