]> xenbits.xensource.com Git - people/royger/osstest.git/commitdiff
HostDB: introduce set_property
authorRoger Pau Monne <roger.pau@citrix.com>
Mon, 23 Oct 2017 09:57:00 +0000 (10:57 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 24 Oct 2017 11:04:31 +0000 (12:04 +0100)
And provide a helper in TestSupport to use it. This allows osstest to
set host properties from test script themselves (instead of using
the mg-hosts clu).

Note that the setting of host properties is limited to flights with
intended blessing real, and it will fail for any other blessing.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
Changes since v12:
 - Use intended blessing in the error message.

Changes since v2:
 - Die if attempting to modify a host prop with intended blessing !=
   real.

Osstest/HostDB/Executive.pm
Osstest/HostDB/Static.pm
Osstest/TestSupport.pm

index 300178bbf742419b8d542a8086bf94730d48ca81..d42250f664d8b2c5644535b512e342ff290afd20 100644 (file)
@@ -51,6 +51,29 @@ END
     }
 }
 
+sub set_property($$$$) {
+    my ($hd, $ho, $prop, $val) = @_;
+    my $rmq = $dbh_tests->prepare(<<END);
+        DELETE FROM resource_properties
+               WHERE restype='host' and resname=? AND name=?
+END
+    my $addq = $dbh_tests->prepare(<<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 {
+        $rmq->execute($ho->{Name}, $prop);
+        if (length $val) {
+            $addq->execute($ho->{Name}, $prop, $val);
+       }
+    });
+}
+
 sub get_flags ($$) {
     my ($hd, $ho) = @_;
 
index 60f5d3c219df971a388b3f1c84ab5e016ca08e43..3191c56562a2abb96c3088f0d613309ecbfdf554 100644 (file)
@@ -40,6 +40,13 @@ sub get_properties ($$$) { #method
     my ($hd, $name, $hp) = @_;
 }
 
+sub set_property($$$$) {
+    my ($hd, $ho, $prop, $val) = @_;
+
+    die
+    "Cannot set property in standalone mode for $ho->{Name} $prop = $val\n";
+}
+
 sub get_flags ($$) { #method
     my ($hd, $ho) = @_;
 
index bdfabc8bd6d0000ff609bad70977c4bd2ac9e9b1..4ca19d41c2b517f7531e53f52198b20ab0981d29 100644 (file)
@@ -80,7 +80,7 @@ BEGIN {
                       get_target_property get_host_native_linux_console
                       hostnamepath hostnamepath_list
                       power_state power_cycle power_cycle_sleep
-                      serial_fetch_logs
+                      serial_fetch_logs set_host_property
                       propname_massage propname_check
          
                       get_stashed open_unique_stashfile compress_stashed
@@ -1150,6 +1150,12 @@ sub get_host_property ($$;$) {
     return defined($val) ? $val : $defval;
 }
 
+sub set_host_property ($$$) {
+    my ($ho,$prop,$val) = @_;
+
+    $mhostdb->set_property($ho, $prop, $val);
+}
+
 sub get_target_property ($$;$);
 sub get_target_property ($$;$) {
     my ($ho, $prop, $defval) = @_;