4 # Copyright (C) 2010 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 [[ "$(find $tmpls/log/ganeti/cleaner -mindepth 1 | wc -l)" -le "$n" ]] || \
49 err "Found more than $n logfiles"
54 local count=$(find $queuedir -mindepth 1 -type f | wc -l)
55 [[ "$count" -eq "$n" ]] || err "Found $count jobs instead of $n"
59 local suffix="$1" n=$2
60 local count=$(find $watcherdir -maxdepth 1 -type f \
61 -name "watcher.*-*-*-*.$suffix" | wc -l)
62 [[ "$count" -eq "$n" ]] || \
63 err "Found $count watcher files with suffix '$suffix' instead of $n"
66 count_and_check_certs() {
68 local count=$(find $cryptodir -mindepth 1 -type f -name cert | wc -l)
69 [[ "$count" -eq "$n" ]] || err "Found $count certificates instead of $n"
71 find $cryptodir -mindepth 1 -type d | \
73 [[ ( -e $dir/key && -e $dir/cert ) ||
74 ( ! -e $dir/cert && ! -e $dir/key ) ]] || \
75 err 'Inconsistent cert/key directory found'
80 CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $GNTC
83 create_archived_jobs() {
84 local i jobdir touchargs
85 local jobarchive=$queuedir/archive
86 local old_ts=$(date -d '25 days ago' +%Y%m%d%H%M)
88 # Remove jobs from previous run
89 find $jobarchive -mindepth 1 -type f | xargs -r rm
92 for job_id in {1..50} 469581574 19857 1420164 494433 2448521
94 jobdir=$jobarchive/$(( job_id / 10 ))
95 test -d $jobdir || mkdir $jobdir
97 if (( i % 3 == 0 || i % 7 == 0 )); then
98 touchargs="-t $old_ts"
102 touch $touchargs $jobdir/job-$job_id
108 create_watcher_state() {
110 6792a0d5-f8b6-4531-8d8c-3680c86b8a53
111 ab74da37-f5f7-44c4-83ad-074159772593
112 fced2e48-ffff-43ae-919e-2b77d37ecafa
113 6e89ac57-2eb1-4a16-85a1-94daa815d643
114 8714e8f5-59c4-47db-b2cb-196ec37978e5
115 91763d73-e1f3-47c7-a735-57025d4e2a7d
116 e27d3ff8-9546-4e86-86a4-04151223e140
117 aa3f63dd-be17-4ac8-bd01-d71790e124cb
118 05b6d7e2-003b-40d9-a6d6-ab61bf123a15
119 54c93e4c-61fe-40de-b47e-2a8e6c805d02
123 for uuid in ${uuids[@]}; do
124 touch -d "$(( 5 * i )) days ago" \
125 $watcherdir/watcher.$uuid.{data,instance-status}
135 certdir=$cryptodir/$name
137 if [[ -n "$cert" ]]; then
138 cp $cert $certdir/cert
139 cp $cert $certdir/key
145 trap "rm -rf $tmpdir" EXIT
147 # Temporary localstatedir
149 queuedir=$tmpls/lib/ganeti/queue
150 cryptodir=$tmpls/run/ganeti/crypto
151 watcherdir=$tmpls/lib/ganeti
153 mkdir -p $tmpls/{lib,log,run}/ganeti $queuedir/archive $cryptodir
157 upto 'Checking log directory creation'
158 test -d $tmpls/log/ganeti || err 'log/ganeti does not exist'
159 test -d $tmpls/log/ganeti/cleaner && \
160 err 'log/ganeti/cleaner should not exist yet'
162 test -d $tmpls/log/ganeti/cleaner || err 'log/ganeti/cleaner should exist'
165 upto 'Checking number of retained log files'
166 for (( i=0; i < (maxlog + 10); ++i )); do
168 check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) ))
171 upto 'Removal of archived jobs (non-master)'
174 test -f $tmpls/lib/ganeti/ssconf_master_node && \
175 err 'ssconf_master_node should not exist'
179 upto 'Removal of archived jobs (master node)'
182 echo $HOSTNAME > $tmpls/lib/ganeti/ssconf_master_node
186 upto 'Certificate expiration'
187 gencert $tmpdir/validcert 30 & vcpid=${!}
188 gencert $tmpdir/expcert -30 & ecpid=${!}
190 create_certdirs $tmpdir/validcert foo{a,b,c}123 trvRMH4Wvt OfDlh6Pc2n
191 create_certdirs $tmpdir/expcert bar{x,y,z}999 fx0ljoImWr em3RBC0U8c
192 create_certdirs '' empty{1,2,3} gd2HCvRc iFG55Z0a PP28v5kg
193 count_and_check_certs 10
195 count_and_check_certs 5
197 check_logfiles $maxlog
200 upto 'Watcher status files'
202 count_watcher data 10
203 count_watcher instance-status 10
206 count_watcher instance-status 5