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 GNTMC=daemons/ganeti-master-cleaner
28 CCE=tools/check-cert-expired
37 echo "$(date '+%F %T'):" "$@" '...'
41 local path=$1 validity=$2
42 VALIDITY=$validity $PYTHON \
43 ${TOP_SRCDIR:-.}/test/import-export_unittest-helper \
49 if [[ "$p2" = master ]]; then
50 path=$tmpls/log/ganeti/mastercleaner
52 path=$tmpls/log/ganeti/cleaner
54 [[ "$(find $path -mindepth 1 | wc -l)" -le "$n" ]] || \
55 err "Found more than $n logfiles"
60 local count=$(find $queuedir -mindepth 1 -type f | wc -l)
61 [[ "$count" -eq "$n" ]] || err "Found $count jobs instead of $n"
65 local suffix="$1" n=$2
66 local count=$(find $watcherdir -maxdepth 1 -type f \
67 -name "watcher.*-*-*-*.$suffix" | wc -l)
68 [[ "$count" -eq "$n" ]] || \
69 err "Found $count watcher files with suffix '$suffix' instead of $n"
72 count_and_check_certs() {
74 local count=$(find $cryptodir -mindepth 1 -type f -name cert | wc -l)
75 [[ "$count" -eq "$n" ]] || err "Found $count certificates instead of $n"
77 find $cryptodir -mindepth 1 -type d | \
79 [[ ( -e $dir/key && -e $dir/cert ) ||
80 ( ! -e $dir/cert && ! -e $dir/key ) ]] || \
81 err 'Inconsistent cert/key directory found'
88 if [[ "$1" = master ]]; then
94 CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $cmd
97 create_archived_jobs() {
98 local i jobdir touchargs
99 local jobarchive=$queuedir/archive
100 local old_ts=$(date -d '25 days ago' +%Y%m%d%H%M)
102 # Remove jobs from previous run
103 find $jobarchive -mindepth 1 -type f | xargs -r rm
106 for job_id in {1..50} 469581574 19857 1420164 494433 2448521
108 jobdir=$jobarchive/$(( job_id / 10 ))
109 test -d $jobdir || mkdir $jobdir
111 if (( i % 3 == 0 || i % 7 == 0 )); then
112 touchargs="-t $old_ts"
116 touch $touchargs $jobdir/job-$job_id
122 create_watcher_state() {
124 6792a0d5-f8b6-4531-8d8c-3680c86b8a53
125 ab74da37-f5f7-44c4-83ad-074159772593
126 fced2e48-ffff-43ae-919e-2b77d37ecafa
127 6e89ac57-2eb1-4a16-85a1-94daa815d643
128 8714e8f5-59c4-47db-b2cb-196ec37978e5
129 91763d73-e1f3-47c7-a735-57025d4e2a7d
130 e27d3ff8-9546-4e86-86a4-04151223e140
131 aa3f63dd-be17-4ac8-bd01-d71790e124cb
132 05b6d7e2-003b-40d9-a6d6-ab61bf123a15
133 54c93e4c-61fe-40de-b47e-2a8e6c805d02
137 for uuid in ${uuids[@]}; do
138 touch -d "$(( 5 * i )) days ago" \
139 $watcherdir/watcher.$uuid.{data,instance-status}
149 certdir=$cryptodir/$name
151 if [[ -n "$cert" ]]; then
152 cp $cert $certdir/cert
153 cp $cert $certdir/key
159 trap "rm -rf $tmpdir" EXIT
161 # Temporary localstatedir
163 queuedir=$tmpls/lib/ganeti/queue
164 cryptodir=$tmpls/run/ganeti/crypto
165 watcherdir=$tmpls/lib/ganeti
167 mkdir -p $tmpls/{lib,log,run}/ganeti $queuedir/archive $cryptodir
171 upto 'Checking log directory creation'
172 test -d $tmpls/log/ganeti || err 'log/ganeti does not exist'
173 test -d $tmpls/log/ganeti/cleaner && \
174 err 'log/ganeti/cleaner should not exist yet'
176 test -d $tmpls/log/ganeti/cleaner || err 'log/ganeti/cleaner should exist'
179 test -d $tmpls/log/ganeti/master-cleaner && \
180 err 'log/ganeti/master-cleaner should not exist yet'
182 test -d $tmpls/log/ganeti/master-cleaner || \
183 err 'log/ganeti/master-cleaner should exist'
184 check_logfiles 1 master
186 upto 'Checking number of retained log files (master)'
187 for (( i=0; i < (maxlog + 10); ++i )); do
190 check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) )) master
193 upto 'Checking number of retained log files (node)'
194 for (( i=0; i < (maxlog + 10); ++i )); do
196 check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) ))
197 check_logfiles $maxlog master
200 upto 'Removal of archived jobs (non-master)'
203 test -f $tmpls/lib/ganeti/ssconf_master_node && \
204 err 'ssconf_master_node should not exist'
210 upto 'Removal of archived jobs (master node)'
213 echo $HOSTNAME > $tmpls/lib/ganeti/ssconf_master_node
219 upto 'Certificate expiration'
220 gencert $tmpdir/validcert 30 & vcpid=${!}
221 gencert $tmpdir/expcert -30 & ecpid=${!}
223 create_certdirs $tmpdir/validcert foo{a,b,c}123 trvRMH4Wvt OfDlh6Pc2n
224 create_certdirs $tmpdir/expcert bar{x,y,z}999 fx0ljoImWr em3RBC0U8c
225 create_certdirs '' empty{1,2,3} gd2HCvRc iFG55Z0a PP28v5kg
226 count_and_check_certs 10
228 count_and_check_certs 10
230 count_and_check_certs 5
232 check_logfiles $maxlog
233 check_logfiles $maxlog master
236 upto 'Watcher status files'
238 count_watcher data 10
239 count_watcher instance-status 10
241 count_watcher data 10
242 count_watcher instance-status 10
245 count_watcher instance-status 5