]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
ts-hosts-allocate-Executive: Honour hostalloc_maxwait_max
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 16 May 2017 13:34:25 +0000 (14:34 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Wed, 17 May 2017 22:53:57 +0000 (23:53 +0100)
No functional change with existing flights.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
ts-hosts-allocate-Executive

index 0987e2b5ed7010464c8646375eabe585910c1f88..9955cbadd73f046d9bd6a7f5355998ddb196436a 100755 (executable)
@@ -56,6 +56,7 @@ if ($ENV{'OSSTEST_NOALLOCATE'}) {
 }
 
 # initialised by setup:
+our $alloc_start_time;
 our $taskid;
 our %magictaskid;
 our $fi;
@@ -109,6 +110,8 @@ END
              WHERE type='magic' AND refkey=?
 END
     }
+
+    $alloc_start_time = time // die $!;
 }
 
 #---------- prepared sql statements ----------
@@ -748,6 +751,16 @@ sub attempt_allocation {
        logm("host allocation: successful, reporting to planner.");
     } else {
        logm("host allocation: planned start in $best->{Start} seconds.");
+       my $maxwait = $r{hostalloc_maxwait_max};
+       if (defined $maxwait) {
+           # We quit if:
+           #  * we have been waiting at least $maxwait/2
+           #  * we estimate it will take at least $maxwait overall
+           my $wait_sofar = (time // die $!) - $alloc_start_time;
+           die "timed out: $wait_sofar, $best->{Start}, $maxwait"
+                if $wait_sofar > $maxwait/2
+               && $wait_sofar + $best->{Start} > $maxwait;
+       }
     }
 
     if ($fake) {