diff mbox

[v12,31/33] ts-examine-hostprops-save: introduce a script to save properties

Message ID 20171020134702.41255-4-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Pau Monné Oct. 20, 2017, 1:47 p.m. UTC
This script turns the properties stored in the runvars using the
format hostprop/$ident/$prop=$val into host properties stored in the
database.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v2:
 - Call selecthost based on the idents passed in the putative
   hostprops runvar.
 - Fix commit message.
 - Use '/' instead of '_' in the runvars.
 - Do a dry run if flight blessing != real.
 - Fix parentheses indentation.

Changes since v1:
 - Select a host for setting the properties.
 - Print a message before exiting if blessing != real.
 - Skip properties that don't contain the selected host.
---
 ts-examine-hostprops-save | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100755 ts-examine-hostprops-save

Comments

Ian Jackson Oct. 20, 2017, 3:04 p.m. UTC | #1
Roger Pau Monne writes ("[PATCH v12 31/33] ts-examine-hostprops-save: introduce a script to save properties"):
> This script turns the properties stored in the runvars using the
> format hostprop/$ident/$prop=$val into host properties stored in the
> database.

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

Although,

> +foreach my $k (sort keys %r) {
> +    next unless $k =~ m/^hostprop\/([^\/]*)\/([^\/]*)$/;
> +    my $ho = selecthost($1);
> +    my $prop = $2;
> +
> +    logm("recording for $ho->{Name} $prop=$r{$k}");
> +
> +    # NB: in order to aid debug only attempt to save the host props
> +    # on flights with real blessing, for the rest just do a dry run.
> +    if ($blessing eq "real") {
> +        set_host_property($ho, $prop, $r{$k});
> +    } else {
> +        logm("not saving host prop with blessing $blessing != real");

This will be annoyingly noisy in non-real flights with multiple
hostprops.

Better would be to move the $blessing eq "real" test to the outside of
the loop and have a variable to day whether to actually set things.
Then the log message about "not saving" could be printed once.

Ian.
diff mbox

Patch

diff --git a/ts-examine-hostprops-save b/ts-examine-hostprops-save
new file mode 100755
index 00000000..99a4627b
--- /dev/null
+++ b/ts-examine-hostprops-save
@@ -0,0 +1,46 @@ 
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2017 Citrix Inc.
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict qw(vars);
+use DBI;
+use POSIX;
+
+unshift @INC, qw(.);
+use Osstest;
+use Osstest::TestSupport;
+
+tsreadconfig();
+
+our $blessing = intended_blessing();
+
+logm("setting host properties");
+
+foreach my $k (sort keys %r) {
+    next unless $k =~ m/^hostprop\/([^\/]*)\/([^\/]*)$/;
+    my $ho = selecthost($1);
+    my $prop = $2;
+
+    logm("recording for $ho->{Name} $prop=$r{$k}");
+
+    # NB: in order to aid debug only attempt to save the host props
+    # on flights with real blessing, for the rest just do a dry run.
+    if ($blessing eq "real") {
+        set_host_property($ho, $prop, $r{$k});
+    } else {
+        logm("not saving host prop with blessing $blessing != real");
+    }
+}