diff mbox series

[OSSTEST,24/82] host allocation: *_shared_mark_ready: Allow other states

Message ID 20201007180024.7932-25-iwj@xenproject.org (mailing list archive)
State New, archived
Headers show
Series Reuse test hosts | expand

Commit Message

Ian Jackson Oct. 7, 2020, 5:59 p.m. UTC
From: Ian Jackson <ian.jackson@eu.citrix.com>

Generalise these functions so they can set the state to something
other than `ready', and so that they can expect a state other than
`prep'.

No functional change with existing callers.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 Osstest/Executive.pm       | 19 +++++++++++--------
 Osstest/JobDB/Executive.pm |  5 +++--
 Osstest/TestSupport.pm     |  6 +++---
 3 files changed, 17 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/Osstest/Executive.pm b/Osstest/Executive.pm
index 703f3d85..f0038f6b 100644
--- a/Osstest/Executive.pm
+++ b/Osstest/Executive.pm
@@ -1050,11 +1050,14 @@  END
     return $shared;
 }
 
-sub executive_resource_shared_mark_ready ($$$) {
-    my ($restype, $resname, $sharetype) = @_;
+sub executive_resource_shared_mark_ready ($$$;$$) {
+    my ($restype, $resname, $sharetype, $oldstate, $newstate) = @_;
     # must run outside transaction
 
     my $oldshr;
+    $oldstate //= 'prep';
+    $newstate //= 'ready';
+
     my $what= "resource $restype $resname";
     $sharetype .= ' '.get_harness_rev();
 
@@ -1063,11 +1066,11 @@  sub executive_resource_shared_mark_ready ($$$) {
         if (defined $oldshr) {
             die "$what shared $oldshr->{Type} not $sharetype"
                 unless $oldshr->{Type} eq $sharetype;
-            die "$what shared state $oldshr->{State} not prep"
-                unless $oldshr->{State} eq 'prep';
-            my $nrows= $dbh_tests->do(<<END,{}, $restype,$resname,$sharetype);
+            die "$what shared state $oldshr->{State} not $oldstate"
+                unless $oldshr->{State} eq $oldstate;
+            my $nrows= $dbh_tests->do(<<END,{}, $newstate, $restype,$resname,$sharetype);
                 UPDATE resource_sharing
-                   SET state='ready'
+                   SET state=?
                  WHERE restype=? AND resname=? AND sharetype=?
 END
             die "unexpected not updated state $what $sharetype $nrows"
@@ -1092,9 +1095,9 @@  END
        logm("post-mark-ready queue daemon prod failed: $@");
     }
     if ($oldshr) {
-	logm("$restype $resname shared $sharetype marked ready");
+	logm("$restype $resname shared $sharetype marked $newstate");
     } else {
-	logm("$restype $resname (not shared, $sharetype) is ready");
+	logm("$restype $resname (not shared, $sharetype) is $newstate");
     }
 }
 
diff --git a/Osstest/JobDB/Executive.pm b/Osstest/JobDB/Executive.pm
index 39deb8a2..30629572 100644
--- a/Osstest/JobDB/Executive.pm
+++ b/Osstest/JobDB/Executive.pm
@@ -352,8 +352,9 @@  sub gen_ether_offset ($$) { #method
 }
 
 sub jobdb_resource_shared_mark_ready { #method
-    my ($mo, $restype, $resname, $sharetype) = @_;
-    executive_resource_shared_mark_ready($restype, $resname, $sharetype);
+    my ($mo, $restype, $resname, $sharetype, $oldstate, $newstate) = @_;
+    executive_resource_shared_mark_ready
+	($restype, $resname, $sharetype, $oldstate,$newstate);
 }
 
 sub jobdb_check_other_job { #method
diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index 99c7654d..7292a329 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -3106,11 +3106,11 @@  sub sha256file ($;$) {
     return $truncate ? substr($digest, 0, $truncate) : $digest;
 }
 
-sub host_shared_mark_ready($$) {
-    my ($ho,$sharetype) = @_;
+sub host_shared_mark_ready($$;$$) {
+    my ($ho,$sharetype, $oldstate, $newstate) = @_;
 
     $mjobdb->jobdb_resource_shared_mark_ready('host', $ho->{Name},
-                                              $sharetype);
+        $sharetype, $oldstate, $newstate);
 }
 
 sub gitcache_setup ($) {