[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 3/6] osstest: allow to perform multiple anoints in the same transaction



In the same way allow to perform several fetches in the same retrieve
transaction.

Further patches will anoint a FreeBSD image and a binary ports tree
in the same transaction, and it's required to do it in the same
transaction in order to avoid inconsistencies when fetching them.

Note that most of the changes in this patch is code movement in order
to place the database accessors inside of a loop that iterates over
the input parameters.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 mg-anoint | 167 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 88 insertions(+), 79 deletions(-)

diff --git a/mg-anoint b/mg-anoint
index d09124b3..08447b8e 100755
--- a/mg-anoint
+++ b/mg-anoint
@@ -10,12 +10,12 @@
 #
 #  ./mg-anoint destroy REFKEY
 #
-#  ./mg-anoint anoint [ANOINT-OPTION...] REFKEY FLIGHT JOB
+#  ./mg-anoint anoint [ANOINT-OPTION...] REFKEY FLIGHT JOB [REFKEY FLIGHT 
JOB...]
 #     ANOINT-OPTIONs are:
 #        --allow-blessed=BLESSING,...       default is from `prepare'
 #        --allow-job-status=STATUS,...      default is only `pass'
 #
-#  ./mg-anoint retrieve [--tolerate-unprepared] REFKEY
+#  ./mg-anoint retrieve [--tolerate-unprepared] REFKEY [REFKEY...]
 #      => FLIGHT JOB
 #         if nothing anointed yet, prints nothing and exits 0
 #         if anointment not prepared, fails
@@ -189,8 +189,7 @@ sub cmd_anoint {
            die "unknown option $_ ?";
        }
     }
-    die unless @ARGV==3;
-    my ($refkey, $flight, $job) = @ARGV;
+    die unless @ARGV%3==0;
 
     fail_unless_can_anoint();
     prep_queries();
@@ -228,69 +227,74 @@ END
 
     db_retry($dbh_tests, [], sub {
        @o = ();
-        $task_q->execute($refkey);
-
-       # find the task row (ie, the anointment kind)
-       my ($task, $refinfo) = $task_q->fetchrow_array();
-       die "no such anointment kind \`$refkey' (no prepare?)\n"
-           unless defined $task;
-       my %params;
-       foreach (split /\s+/, $refinfo) {
-           die unless m/=/;
-           $params{$`} = $';
-       }
-       my %blessings;
-       $blessings{$_}++ foreach
-           grep /./,
-           (split /,/, $params{blessings}),
-           (split /,/, $allow_blessed);
-
-       my %jobstatus;
-       $jobstatus{pass}++;
-       $jobstatus{$_}++ foreach grep /./, split /,/, $allow_jobstatus;
-
-       # check the to-be-anointed flight's blessing
-       $newflight_q->execute($flight);
-       my $frow = $newflight_q->fetchrow_hashref();
-       die "flight $flight missing" unless $frow;
-       die "flight $flight not started" unless defined $frow->{started};
-
-       # check the job status
-       $newjob_q->execute($flight, $job);
-       my ($jstatus) = $newjob_q->fetchrow_array();
-       die "job $flight.$job missing" unless defined $jstatus;
-       die "job $flight.$job status $jstatus" unless $jobstatus{$jstatus};
-
-       push @o, "flight $flight blessed $frow->{blessing}".
-                " started ".show_abs_time($frow->{started});
-
-       die "flight $flight blessing $frow->{blessing}".
-           " (not $params{blessings} / $allow_blessed)"
-           unless $blessings{ $frow->{blessing} };
-
-       # check to-be-annointed flight is most recent
-       $mostrecent_q->execute($task);
-       my $mostrecent = $mostrecent_q->fetchrow_hashref();
-       die "flight $flight not newer than $mostrecent->{flight}"
-           unless $frow->{started} > ($mostrecent->{started} // 0);
-
-       # expire old anointments
-       $count_q->execute($task);
-       my ($current) = $count_q->fetchrow_array();
-       my $want_delete = ($current+1) - $params{keep};
-       push @o, "anointment $refkey: currently $current anointed";
-       if ($want_delete > 0) {
-           $todelete_q->execute($task, $want_delete);
-           while (my $d = $todelete_q->fetchrow_hashref()) {
-               push @o, " expiring $d->{flight}.$d->{job} [/$d->{shareix}]".
-                   " started ".show_abs_time($d->{started});
-               $delete_res_q->execute($task, $d->{flight}, $d->{shareix});
-           }
-       }
 
-       # at last!
-       $insert_q->execute($flight,$task,$task,$job);
-       push @o, "anointed $flight.$job";
+       for (my $i=0; $i < @ARGV; $i+=3) {
+               my ($refkey, $flight, $job) = @ARGV[$i..$i+2];
+
+               $task_q->execute($refkey);
+
+               # find the task row (ie, the anointment kind)
+               my ($task, $refinfo) = $task_q->fetchrow_array();
+               die "no such anointment kind \`$refkey' (no prepare?)\n"
+                   unless defined $task;
+               my %params;
+               foreach (split /\s+/, $refinfo) {
+                   die unless m/=/;
+                   $params{$`} = $';
+               }
+               my %blessings;
+               $blessings{$_}++ foreach
+                   grep /./,
+                   (split /,/, $params{blessings}),
+                   (split /,/, $allow_blessed);
+
+               my %jobstatus;
+               $jobstatus{pass}++;
+               $jobstatus{$_}++ foreach grep /./, split /,/, $allow_jobstatus;
+
+               # check the to-be-anointed flight's blessing
+               $newflight_q->execute($flight);
+               my $frow = $newflight_q->fetchrow_hashref();
+               die "flight $flight missing" unless $frow;
+               die "flight $flight not started" unless defined 
$frow->{started};
+
+               # check the job status
+               $newjob_q->execute($flight, $job);
+               my ($jstatus) = $newjob_q->fetchrow_array();
+               die "job $flight.$job missing" unless defined $jstatus;
+               die "job $flight.$job status $jstatus" unless 
$jobstatus{$jstatus};
+
+               push @o, "flight $flight blessed $frow->{blessing}".
+                        " started ".show_abs_time($frow->{started});
+
+               die "flight $flight blessing $frow->{blessing}".
+                   " (not $params{blessings} / $allow_blessed)"
+                   unless $blessings{ $frow->{blessing} };
+
+               # check to-be-annointed flight is most recent
+               $mostrecent_q->execute($task);
+               my $mostrecent = $mostrecent_q->fetchrow_hashref();
+               die "flight $flight not newer than $mostrecent->{flight}"
+                   unless $frow->{started} > ($mostrecent->{started} // 0);
+
+               # expire old anointments
+               $count_q->execute($task);
+               my ($current) = $count_q->fetchrow_array();
+               my $want_delete = ($current+1) - $params{keep};
+               push @o, "anointment $refkey: currently $current anointed";
+               if ($want_delete > 0) {
+                   $todelete_q->execute($task, $want_delete);
+                   while (my $d = $todelete_q->fetchrow_hashref()) {
+                       push @o, " expiring $d->{flight}.$d->{job} 
[/$d->{shareix}]".
+                           " started ".show_abs_time($d->{started});
+                       $delete_res_q->execute($task, $d->{flight}, 
$d->{shareix});
+                   }
+               }
+
+               # at last!
+               $insert_q->execute($flight,$task,$task,$job);
+               push @o, "anointed $flight.$job";
+       }
     });
     pr_o();
 }    
@@ -301,26 +305,31 @@ sub cmd_retrieve {
        shift @ARGV;
        $tolerate_unprepared = 1;
     }
-    die unless @ARGV==1;
+    die unless @ARGV>=1;
     die if $ARGV[0] =~ m/^-/;
-    my ($refkey) = @ARGV;
 
     empty_unless_can_anoint();
     prep_queries();
 
     db_retry($dbh_tests, [], sub {
         @o = ();
-        $task_q->execute($refkey);
-       my ($task) = $task_q->fetchrow_array();
-       die "no such anointment kind \`$refkey'"
-           unless defined $task or $tolerate_unprepared;
-
-       $mostrecent_q->execute($task);
-       my $row = $mostrecent_q->fetchrow_hashref();
-       if ($row) {
-           push @o, "$row->{flight} $row->{job}";
-       } else {
-           print STDERR "warning: nothing anointed $refkey\n";
+
+       foreach my $refkey (@ARGV) {
+               $task_q->execute($refkey);
+               my ($task) = $task_q->fetchrow_array();
+               die "no such anointment kind \`$refkey'"
+                   unless defined $task or $tolerate_unprepared;
+
+               $mostrecent_q->execute($task);
+               my $row = $mostrecent_q->fetchrow_hashref();
+               if ($row) {
+                   push @o, "$row->{flight} $row->{job}";
+               } else {
+                   # Push an error line so the number of output lines
+                   # matches the number of REFKEYs requested.
+                   push @o, "ERROR";
+                   print STDERR "warning: nothing anointed $refkey\n";
+               }
        }
     });
     pr_o();
-- 
2.17.2 (Apple Git-113)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.