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

[OSSTEST PATCH 42/82] host allocation: selecthost(): Support @IDENT for reuse



From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>

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 <ian.jackson@xxxxxxxxxxxxx>
---
 Osstest/TestSupport.pm | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index 3d5f0be3..be6b7119 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 <identspec>
+    # $ident is [@]<identspec>
     #
     # <identspec> can be <ident>, typically "host" or "xxx_host"
     # which means look up the runvar $r{$ident} which
@@ -1191,8 +1191,16 @@ sub selecthost ($;$$) {
     # <hostspec> can be <parent_identspec>:<domname> meaning use the
     # Xen domain name <domname> on the host specified by
     # <parent_identspec>, which is an <identspec> 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} : '<unknown-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.20.1




 


Rackspace

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