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

[Xen-devel] [PATCH OSSTEST v4 1/3] host: introduce helpers to modify hostflags


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 11 Mar 2020 17:00:18 +0100
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@xxxxxxxxxx; spf=Pass smtp.mailfrom=roger.pau@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Cc: ian.jackson@xxxxxxxxxxxxx, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 11 Mar 2020 16:01:21 +0000
  • Ironport-sdr: MeoXjyiJpX9QkyeEmcPwKDpczg+c/GPzvkMOIwJwTKr9pHOwHKOOmYt1K+IK5RUoeJ9bk+dmr/ +ltO7uoRCg/8ZT9crxrAwEsCFqT/RKYeo7oWwdz2uZTrShFKwDv0hohhD8tPCqe/q+JnXxoHAP uKAP82lzexAHvFpKiKm7csxYmoPz85QG87UZiohGvdeo7B0pCVIqw/0mliruLqE8JwWzc3tUKw MxTf+d8dn4i3v2/2kY4L1C257vz8cZjfXhrCPnb8o3bsfTqV5hB9QT8CuAWxW1H0kfy/vg55n2 ldM=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add a generic function to perform database changes related to a host
and use it to implement set_property and and {set/remove}_flag.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v3:
 - Introduce modify_flag instead of {set/remove}_flag.
 - Introduce a generic modify_host helper.
 - Split from patch 1.
---
 Osstest/HostDB/Executive.pm | 33 ++++++++++++++++++++++++++++-----
 Osstest/HostDB/Static.pm    |  7 +++++++
 Osstest/TestSupport.pm      | 21 ++++++++++++++++++++-
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/Osstest/HostDB/Executive.pm b/Osstest/HostDB/Executive.pm
index 7ffca6c4..a6dc4462 100644
--- a/Osstest/HostDB/Executive.pm
+++ b/Osstest/HostDB/Executive.pm
@@ -51,6 +51,16 @@ END
     }
 }
 
+sub modify_host ($$$) {
+    my ($hd, $ho, $query) = @_;
+    my $blessing = intended_blessing();
+
+    die "Attempting to modify host with intended blessing $blessing != real"
+        if $blessing ne "real";
+
+    db_retry($dbh_tests, [qw(resources)], $query);
+}
+
 sub set_property($$$$) {
     my ($hd, $ho, $prop, $val) = @_;
     my $rmq = $dbh_tests->prepare(<<END);
@@ -61,12 +71,8 @@ END
         INSERT INTO resource_properties (restype,resname,name,val)
                VALUES ('host', ?,?,?)
 END
-    my $blessing = intended_blessing();
-
-    die "Attempting to modify host props with intended blessing $blessing != 
real"
-        if $blessing ne "real";
 
-    db_retry($dbh_tests, [qw(resources)], sub {
+    modify_host($hd, $ho, sub {
         $rmq->execute($ho->{Name}, $prop);
         if (length $val) {
             $addq->execute($ho->{Name}, $prop, $val);
@@ -90,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..b80e89bc 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -85,8 +85,9 @@ BEGIN {
                       hostnamepath hostnamepath_list set_runtime_hostflag
                       power_state power_cycle power_reboot_attempts
                       serial_fetch_logs set_host_property
+                      set_host_flag remove_host_flag
                       propname_massage propname_check
-                      hostprop_putative_record
+                      hostprop_putative_record hostflag_putative_record
          
                       get_stashed open_unique_stashfile compress_stashed
                       dir_identify_vcs
@@ -1411,6 +1412,24 @@ sub hostprop_putative_record ($$$) {
     store_runvar("hostprop/$ho->{Ident}/$prop", $val);
 }
 
+sub set_host_flag ($$) {
+    my ($ho,$flag) = @_;
+
+    $mhostdb->modify_flag($ho, $flag, 1);
+}
+
+sub remove_host_flag ($$) {
+    my ($ho,$flag) = @_;
+
+    $mhostdb->modify_flag($ho, $flag, 0);
+}
+
+sub hostflag_putative_record ($$$) {
+    my ($ho, $prop, $set) = @_;
+
+    store_runvar("hostflag/$ho->{Ident}/$prop", !!$set);
+}
+
 sub get_target_property ($$;$);
 sub get_target_property ($$;$) {
     my ($ho, $prop, $defval) = @_;
-- 
2.25.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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