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"
58 count_and_check_certs() {
60 local count=$(find $cryptodir -mindepth 1 -type f -name cert | wc -l)
61 [[ "$count" -eq "$n" ]] || err "Found $count certificates instead of $n"
63 find $cryptodir -mindepth 1 -type d | \
65 [[ ( -e $dir/key && -e $dir/cert ) ||
66 ( ! -e $dir/cert && ! -e $dir/key ) ]] || \
67 err 'Inconsistent cert/key directory found'
72 CHECK_CERT_EXPIRED=$CCE LOCALSTATEDIR=$tmpls $GNTC
75 create_archived_jobs() {
76 local i jobdir touchargs
77 local jobarchive=$queuedir/archive
78 local large=$(( RANDOM * RANDOM ))
79 local old_ts=$(date -d '25 days ago' +%Y%m%d%H%M)
81 # Remove jobs from previous run
82 find $jobarchive -mindepth 1 -type f | xargs -r rm
85 for job_id in {1..50} $(( large % RANDOM )) $RANDOM \
86 $(( large - 1 )) $large $(( large + 1 ))
88 jobdir=$jobarchive/$(( job_id / 10 ))
89 test -d $jobdir || mkdir $jobdir
91 if (( i % 3 == 0 || i % 7 == 0 )); then
92 touchargs="-t $old_ts"
96 touch $touchargs $jobdir/job-$job_id
106 certdir=$cryptodir/$name
108 if [[ -n "$cert" ]]; then
109 cp $cert $certdir/cert
110 cp $cert $certdir/key
116 trap "rm -rf $tmpdir" EXIT
118 # Temporary localstatedir
120 queuedir=$tmpls/lib/ganeti/queue
121 cryptodir=$tmpls/run/ganeti/crypto
123 mkdir -p $tmpls/{lib,log,run}/ganeti $queuedir/archive $cryptodir
127 upto 'Checking log directory creation'
128 test -d $tmpls/log/ganeti || err 'log/ganeti does not exist'
129 test -d $tmpls/log/ganeti/cleaner && \
130 err 'log/ganeti/cleaner should not exist yet'
132 test -d $tmpls/log/ganeti/cleaner || err 'log/ganeti/cleaner should exist'
135 upto 'Checking number of retained log files'
136 for (( i=0; i < (maxlog + 10); ++i )); do
138 check_logfiles $(( (i + 2) > $maxlog?$maxlog:(i + 2) ))
141 upto 'Removal of archived jobs (non-master)'
144 test -f $tmpls/lib/ganeti/ssconf_master_node && \
145 err 'ssconf_master_node should not exist'
149 upto 'Removal of archived jobs (master node)'
152 echo $HOSTNAME > $tmpls/lib/ganeti/ssconf_master_node
156 upto 'Certificate expiration'
157 gencert $tmpdir/validcert 30 & vcpid=${!}
158 gencert $tmpdir/expcert -30 & ecpid=${!}
160 create_certdirs $tmpdir/validcert foo{a,b,c}123 trvRMH4Wvt OfDlh6Pc2n
161 create_certdirs $tmpdir/expcert bar{x,y,z}999 fx0ljoImWr em3RBC0U8c
162 create_certdirs '' empty{1,2,3} gd2HCvRc iFG55Z0a PP28v5kg
163 count_and_check_certs 10
165 count_and_check_certs 5
167 check_logfiles $maxlog