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

[Xen-devel] [PATCH OSSTEST 04/11] TestSupport: introduce set_host_prop



This is from the code in mg-hosts. Switch cmd_setprops to use the
newly introduced function.

No functional change.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 Osstest/TestSupport.pm | 31 ++++++++++++++++++++++++++++++-
 mg-hosts               | 31 +------------------------------
 2 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index c24146c0..ff0de14b 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -80,7 +80,7 @@ BEGIN {
                       get_target_property get_host_native_linux_console
                       hostnamepath hostnamepath_list set_runtime_hostflag
                       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
@@ -1183,6 +1183,35 @@ sub get_host_property ($$;$) {
     return defined($val) ? $val : $defval;
 }
 
+sub set_host_property {
+    my $oldvalq = $dbh_tests->prepare(<<END);
+       SELECT val FROM resource_properties
+             WHERE restype='host' and resname=? AND name=?
+END
+    my $rmvalq = $dbh_tests->prepare(<<END);
+       DELETE FROM resource_properties
+             WHERE restype='host' and resname=? AND name=?
+END
+    my $newvalq = $dbh_tests->prepare(<<END);
+       INSERT INTO resource_properties (restype,resname,name,val)
+                                VALUES ('host', ?,?,?)
+END
+    my ($host,$name,$oldval,$val) = @_;
+
+    if (defined $oldval) {
+        $oldvalq->execute($host,$name);
+        my $row = $oldvalq->fetchrow_hashref();
+        die if $row && !length $row->{'val'};
+        my $gotoldval = $row ? $row->{'val'} : '';
+        die "$host $name = '$gotoldval' != '$oldval'"
+        unless ($gotoldval eq $oldval || $gotoldval eq $val);
+    }
+    $rmvalq->execute($host,$name);
+    if (length $val) {
+        $newvalq->execute($host,$name,$val);
+    }
+}
+
 sub get_target_property ($$;$);
 sub get_target_property ($$;$) {
     my ($ho, $prop, $defval) = @_;
diff --git a/mg-hosts b/mg-hosts
index 5cdece56..3d1321a5 100755
--- a/mg-hosts
+++ b/mg-hosts
@@ -292,35 +292,6 @@ END
 }
 
 sub cmd_setprops () {
-    my $oldvalq = $dbh_tests->prepare(<<END);
-       SELECT val FROM resource_properties
-             WHERE restype='host' and resname=? AND name=?
-END
-    my $rmvalq = $dbh_tests->prepare(<<END);
-       DELETE FROM resource_properties
-             WHERE restype='host' and resname=? AND name=?
-END
-    my $newvalq = $dbh_tests->prepare(<<END);
-       INSERT INTO resource_properties (restype,resname,name,val)
-                                VALUES ('host', ?,?,?)
-END
-
-    my $update = sub {
-       my ($host,$name,$oldval,$val) = @_;
-       if (defined $oldval) {
-           $oldvalq->execute($host,$name);
-           my $row = $oldvalq->fetchrow_hashref();
-           die if $row && !length $row->{'val'};
-           my $gotoldval = $row ? $row->{'val'} : '';
-           die "$host $name = '$gotoldval' != '$oldval'"
-               unless ($gotoldval eq $oldval || $gotoldval eq $val);
-       }
-       $rmvalq->execute($host,$name);
-       if (length $val) {
-           $newvalq->execute($host,$name,$val);
-       }
-    };
-
     update_hosts([qw(resources)], sub {
        my ($host,$section) = @_;
        my ($name,$oldval,$val);
@@ -331,7 +302,7 @@ END
        } else {
            die "@$section ?";
        }
-       $update->($host,$name,$oldval,$val);
+       set_host_property($host,$name,$oldval,$val);
     });
 }
 
-- 
2.11.0 (Apple Git-81)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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