*** empty log message ***
authorAleš Křenek <ljocha@ics.muni.cz>
Fri, 20 May 2005 13:18:44 +0000 (13:18 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Fri, 20 May 2005 13:18:44 +0000 (13:18 +0000)
org.glite.lb.client/examples/purge_test [new file with mode: 0644]

diff --git a/org.glite.lb.client/examples/purge_test b/org.glite.lb.client/examples/purge_test
new file mode 100644 (file)
index 0000000..c9f05c1
--- /dev/null
@@ -0,0 +1,189 @@
+#!/usr/bin/perl 
+
+
+
+BEGIN{
+$inst = $ENV{GLITE_PREFIX};
+$inst = "/opt/glite" unless $inst;
+$sbin = "$inst/sbin";
+$bin = "$inst/bin";
+$test = "$inst/examples";
+$purge = "$sbin/glite-lb-purge";
+$status = "$test/glite-lb-job_status";
+$log = "$test/glite-lb-job_log";
+$prefix = "/tmp/purge_test_$$";
+$delay = 60;
+
+$ENV{PATH} .= ":$bin";
+}
+
+$option = shift;
+$server = shift;
+
+die qq{
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+   This script will DESTROY ALL DATA in the specified bookkeeping server.
+
+Don't run it unless you are absolutely sure what you are doing.
+If you really mean it, the magic usage is:
+
+   $0 --i-want-to-purge server:port
+
+Good luck!
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+       
+} unless $option eq '--i-want-to-purge';
+
+die "usage: $0 --i-want-to-purge server:port\n" unless $server;
+
+sub logit {
+       my $ids = shift;
+       my $prefix = shift;
+       my $failed = 0;
+
+       for (qw/aborted cleared cancelled waiting/) {
+               my $key = $_ eq waiting ? 'other' : $_;
+               $id = `$test/glite-lb-$_.sh -m $server`;
+               chomp $id;
+               die "$test/glite-lb-$_.sh" if $?;
+               $id =~ s/EDG_JOBID=//;
+               $ids->{$key} = $id;
+#print "$status $id | head -1\n";
+               $stat = `$status $id | head -2 | tail -1`;
+               chomp $stat;
+               $stat =~ s/state :\s*//;
+#print "$id: ".uc($stat)." ".uc($_)."\n";
+               $failed = 1 if uc($stat) ne uc($_);
+
+               system "$log $id | grep -v '^[  ]*\$' | grep -v '^Found' >${prefix}_$_";
+       }
+
+       !$failed;
+}
+       
+print "** Hey, purging the whole database\n";
+system "$purge --server $server --return-list --aborted=0 --cleared=0 --cancelled=0 --other=0";
+die "$purge: $!\n" if $!;
+
+print "** Logging test jobs\n";
+
+die "!! failed\n" if !logit \%old,"${prefix}_old";
+print "** So far good, sleeping $delay seconds\n";
+sleep $delay;
+print "** OK, another set of jobs\n";
+die "!! failed\n" if !logit \%new,"${prefix}_new";
+
+print "** Dry run\n";
+$failed = 0;
+
+$half = $delay/2;
+for (qw/aborted cleared cancelled other/) {
+       open LIST,"$purge --server $server --dry-run --return-list --$_=${half}s| grep '^https://'|" or die "!! run $purge\n"; 
+
+       $id = <LIST>; chomp $id;
+       if ($old{$_} ne $id) {
+               $failed = 1;
+               print "!! $old{$_} (old $_) is not there\n";
+       }
+       else {
+               print "$_ $id OK\n";
+       }
+       $id = <LIST>;
+       if ($id) {
+               $failed = 1;
+               chomp $id;
+               print "!! $id should not be there\n";
+       }
+       close LIST;
+
+       open LIST,"$purge --server $server --dry-run --return-list --$_=0s | grep '^https://'|" or die "!! run $purge\n"; 
+
+       $cnt = 0;
+       while ($id = <LIST>) {
+               chomp $id;
+               if ($old{$_} ne $id && $new{$_} ne $id) {
+                       $failed = 1;
+                       print "!! $id should not be there\n";
+               }
+               else {
+                       print "$_ $id OK\n";
+               }
+               $cnt++;
+       }
+       
+       close LIST;
+       if ($cnt != 2) {
+               $failed = 1;
+               print "!! bad number of $_ jobs ($cnt)\n";
+       }
+}
+
+die "!! aborting\n" if $failed;
+
+print "** Server defaults\n";
+
+open LIST,"$purge --server $server --dry-run --return-list | grep '^https://'|" or die "!! run $purge\n";
+
+$failed = 0;
+while ($id = <LIST>) {
+       $failed = 1;
+       print "$id\n";
+}
+
+die "!! Oops, should not do anything, too short defaults?\n" if $failed;
+
+print "Nothing purged as expected\n";
+
+print "** Purge the first set of jobs\n";
+
+open DUMP,"$purge --server $server --server-dump --aborted=${half}s --cleared=${half}s --cancelled=${half}s --other=${half}s | grep '^Server dump:'|"
+       or die "!! run $purge\n";
+
+$dump = <DUMP>; chomp $dump; $dump =~ s/Server dump: //;
+close DUMP;
+
+die "!! no dump file reported\n" unless $dump;
+@list = glob "${prefix}_old*";
+system "cat @list | sort >${prefix}_old_all";
+system "cat $dump | sed -e s/^.*DATE/DATE/ | sort >${prefix}_old_dump";
+sleep 60;
+system "diff ${prefix}_old_all ${prefix}_old_dump >/dev/null";
+
+die "!! aggregate log and dump differ\n" if $? & 0xff00;
+
+print "diff OK\n";
+
+print "** Purge the rest\n";
+open DUMP,"$purge --server $server --server-dump --aborted=0 --cleared=0 --cancelled=0 --other=0 | grep '^Server dump:'|"
+       or die "!! run $purge\n";
+
+$dump = <DUMP>; chomp $dump; $dump =~ s/Server dump: //;
+close DUMP;
+
+die "!! no dump file reported\n" unless $dump;
+@list = glob "${prefix}_new*";
+system "cat @list | sort >${prefix}_new_all";
+system "cat $dump | sed -e s/^.*DATE/DATE/ | sort >${prefix}_new_dump";
+system "diff ${prefix}_new_all ${prefix}_new_dump >/dev/null";
+
+die "!! aggregate log and dump differ\n" if $? & 0xff00;
+
+print "diff OK\n";
+
+
+print "** Anything left?\n";
+open LIST,"$purge --server $server --return-list --dry-run --aborted=0 --cleared=0 --cancelled=0 --other=0 | grep '^https://'|" or die "!! $purge\n";
+
+$id = <LIST>;
+close LIST;
+die "!! Yes, but should not\n" if $id;
+print "No, OK\n";
+
+print "\n** All tests passed **\n";
+exit 0;
+
+END{ unlink glob "${prefix}*" if $prefix; }