From 6890cf2e53099db5e6c446ee4846d565b921c58b Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 4 Aug 2011 18:31:51 +0200
Subject: [PATCH] cleaner: Remove watcher's instance status file after 21 days

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 daemons/ganeti-cleaner.in         |  3 ++-
 test/ganeti-cleaner_unittest.bash | 16 ++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/daemons/ganeti-cleaner.in b/daemons/ganeti-cleaner.in
index ec5d8f7cb..0d93a6a1c 100644
--- a/daemons/ganeti-cleaner.in
+++ b/daemons/ganeti-cleaner.in
@@ -55,7 +55,8 @@ cleanup_watcher() {
 
   # Remove old watcher files
   find $DATA_DIR -maxdepth 1 -type f -mtime +$REMOVE_AFTER \
-    -name 'watcher.*-*-*-*.data' -print0 | \
+    \( -name 'watcher.*-*-*-*.data' -or \
+       -name 'watcher.*-*-*-*.instance-status' \) -print0 | \
   xargs -r0 rm -vf
 }
 
diff --git a/test/ganeti-cleaner_unittest.bash b/test/ganeti-cleaner_unittest.bash
index 367a27c3b..93bf5f4e4 100755
--- a/test/ganeti-cleaner_unittest.bash
+++ b/test/ganeti-cleaner_unittest.bash
@@ -56,10 +56,11 @@ count_jobs() {
 }
 
 count_watcher() {
-  local n=$1
+  local suffix="$1" n=$2
   local count=$(find $watcherdir -maxdepth 1 -type f \
-                  -name 'watcher.*.data' | wc -l)
-  [[ "$count" -eq "$n" ]] || err "Found $count watcher files instead of $n"
+                  -name "watcher.*-*-*-*.$suffix" | wc -l)
+  [[ "$count" -eq "$n" ]] || \
+    err "Found $count watcher files with suffix '$suffix' instead of $n"
 }
 
 count_and_check_certs() {
@@ -120,7 +121,8 @@ create_watcher_state() {
 
   i=0
   for uuid in ${uuids[@]}; do
-    touch -d "$(( 5 * i )) days ago" $watcherdir/watcher.$uuid.data
+    touch -d "$(( 5 * i )) days ago" \
+      $watcherdir/watcher.$uuid.{data,instance-status}
 
     let ++i
   done
@@ -197,8 +199,10 @@ count_jobs 31
 
 upto 'Watcher status files'
 create_watcher_state
-count_watcher 10
+count_watcher data 10
+count_watcher instance-status 10
 run_cleaner
-count_watcher 5
+count_watcher data 5
+count_watcher instance-status 5
 
 exit 0
-- 
GitLab