[OSSTEST,v5,2/5] host: introduce a helper to modify hostflags
diff mbox series

Message ID 20200311172010.7777-2-roger.pau@citrix.com
State New
Headers show
Series
  • Untitled series #254925
Related show

Commit Message

Roger Pau Monné March 11, 2020, 5:20 p.m. UTC
Add a generic function to perform database changes related to a host
flag and add a wrapper to TestSupport.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v4:
 - Move addition of hostflag_putative_record to a different patch.
 - Introduce a single helper in TestSupport: modify_host_flag.

Changes since v3:
 - Introduce modify_flag instead of {set/remove}_flag.
 - Introduce a generic modify_host helper.
 - Split from patch 1.
---
Requested on IRC:
17:08:58 Diziet royger: I think your ts-examine-hostprops-save hunk in 2/ belongs in 1/ ?  (Or in
                a separate 1.5/ along with hostflag_putative_record.)
---
 Osstest/HostDB/Executive.pm | 17 +++++++++++++++++
 Osstest/HostDB/Static.pm    |  7 +++++++
 Osstest/TestSupport.pm      |  8 +++++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

Comments

Ian Jackson March 12, 2020, 10:57 a.m. UTC | #1
Roger Pau Monne writes ("[PATCH OSSTEST v5 2/5] host: introduce a helper to modify hostflags"):
> Add a generic function to perform database changes related to a host
> flag and add a wrapper to TestSupport.

Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>

Patch
diff mbox series

diff --git a/Osstest/HostDB/Executive.pm b/Osstest/HostDB/Executive.pm
index d402bcac..a6dc4462 100644
--- a/Osstest/HostDB/Executive.pm
+++ b/Osstest/HostDB/Executive.pm
@@ -96,6 +96,23 @@  END
     return $flags;
 }
 
+sub modify_flag ($$$$) {
+    my ($hd, $ho, $flag, $set) = @_;
+    my $rmq = $dbh_tests->prepare(<<END);
+        DELETE FROM hostflags WHERE hostname=? AND hostflag=?
+END
+    my $addq = $dbh_tests->prepare(<<END);
+        INSERT INTO hostflags (hostname,hostflag) VALUES (?,?)
+END
+
+    modify_host($hd, $ho, sub {
+        $rmq->execute($ho->{Name}, $flag);
+        if ($set) {
+            $addq->execute($ho->{Name}, $flag);
+        }
+    });
+}
+
 sub get_arch_platforms ($$$) {
     my ($hd, $blessing, $arch, $suite) = @_;
 
diff --git a/Osstest/HostDB/Static.pm b/Osstest/HostDB/Static.pm
index 0c6be3ee..d0669fb2 100644
--- a/Osstest/HostDB/Static.pm
+++ b/Osstest/HostDB/Static.pm
@@ -72,6 +72,13 @@  sub get_flags ($$) { #method
     return $flags;
 }
 
+sub modify_flag ($$$$) {
+    my ($hd, $ho, $flag, $set) = @_;
+
+    die
+    "Cannot modify flags in standalone mode for $ho->{Name} $flag set: $set\n";
+}
+
 sub get_arch_platforms ($$$) {
     my ($hd, $blessing, $arch, $suite) = @_;
 
diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index f49ed529..ceb6bb7b 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -84,7 +84,7 @@  BEGIN {
                       get_target_property get_host_native_linux_console
                       hostnamepath hostnamepath_list set_runtime_hostflag
                       power_state power_cycle power_reboot_attempts
-                      serial_fetch_logs set_host_property
+                      serial_fetch_logs set_host_property modify_host_flag
                       propname_massage propname_check
                       hostprop_putative_record
          
@@ -1411,6 +1411,12 @@  sub hostprop_putative_record ($$$) {
     store_runvar("hostprop/$ho->{Ident}/$prop", $val);
 }
 
+sub modify_host_flag ($$$) {
+    my ($ho, $flag, $set) = @_;
+
+    $mhostdb->modify_flag($ho, $flag, $set);
+}
+
 sub get_target_property ($$;$);
 sub get_target_property ($$;$) {
     my ($ho, $prop, $defval) = @_;