From 5b0c02c668a2e0e58b88c865bde10e3a11b9adc6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 21 May 2019 17:30:43 +0100 Subject: [PATCH] host allocation: selecthost(): Support @IDENT for reuse This is the first part of a central way to control host reuse, rather than having to write code in each ts-* script to check Shared etc. No functional change with existing callers. Signed-off-by: Ian Jackson --- Osstest/TestSupport.pm | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 3d5f0be..be6b711 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -1175,7 +1175,7 @@ sub selecthost ($;$$) { my ($ident, $none_ok, $prospective) = @_; # must be run outside transaction - # $ident is + # $ident is [@] # # can be , typically "host" or "xxx_host" # which means look up the runvar $r{$ident} which @@ -1191,8 +1191,16 @@ sub selecthost ($;$$) { # can be : meaning use the # Xen domain name on the host specified by # , which is an as above. + # + # The leading @, if present, specifies that this script should be + # skipped if the host is being reused or shared. Specifically: + # if the host is shared and in sharing state `ready'. And, it is + # wrong to specify @ when multiple hosts are being selected. my $name; + + my $isprep = $ident =~ s/^\@//; + if ($ident =~ m/=/) { $ident= $`; $name= $'; #' @@ -1352,13 +1360,27 @@ sub selecthost ($;$$) { $mjobdb->host_check_allocated($ho); - logm("host $ho->{Ident}: selected $ho->{Name} ". + logm("host $ho->{Ident}". + ($isprep ? " (prep)" : ""). + ": selected $ho->{Name} ". (defined $ho->{Ether} ? $ho->{Ether} : ''). " $ho->{Ip}". (!$ho->{Shared} ? '' : sprintf(" - shared %s %s %d", $ho->{Shared}{Type}, $ho->{Shared}{State}, $ho->{Shared}{Others}+1))); + if ($isprep && $ho->{Shared}) { + my $st = $ho->{Shared}{State}; + if ($st eq 'ready') { + logm("host is ready, skipping step"); + exit 0; + } elsif ($st eq 'prep') { + # ok, we need to do it + } else { + die "host sharestate is $st but isprep (@ in ident)"; + } + } + return $ho; } -- 2.39.5