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

[OSSTEST PATCH v2 1/2] host props/flags: Break out blessing_must_not_modify_host



This return value convention is convenient for the callers, since they
want to print a message when we mayn't modify.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 Osstest.pm                  | 10 +++++++++-
 Osstest/HostDB/Executive.pm |  4 ++--
 ts-examine-hostprops-save   |  4 ++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Osstest.pm b/Osstest.pm
index 27136bc9..54f0085c 100644
--- a/Osstest.pm
+++ b/Osstest.pm
@@ -40,7 +40,7 @@ BEGIN {
                       $dbh_tests db_retry db_retry_retry db_retry_abort
                      db_readonly_report
                       db_begin_work db_prepare
-                      get_harness_rev
+                      get_harness_rev blessing_must_not_modify_host
                       ensuredir get_filecontents_core_quiet system_checked
                       nonempty visible_undef show_abs_time
                       %arch_debian2xen %arch_xen2debian
@@ -407,6 +407,14 @@ sub get_harness_rev () {
     return $rev;
 }
 
+sub blessing_must_not_modify_host ($) {
+    # returns '' (falseish) if we may modify a host's props etc.,
+    # or a trueish string message if may not
+    my ($intended_blessing) = @_;
+    return '' if $intended_blessing eq "real";
+    return "intended blessing $intended_blessing != real";
+}
+
 sub get_filecontents_core_quiet ($) { # ENOENT => undef
     my ($path) = @_;
     if (!open GFC, '<', $path) {
diff --git a/Osstest/HostDB/Executive.pm b/Osstest/HostDB/Executive.pm
index a6dc4462..41cce046 100644
--- a/Osstest/HostDB/Executive.pm
+++ b/Osstest/HostDB/Executive.pm
@@ -55,8 +55,8 @@ 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";
+    my $wrong = blessing_must_not_modify_host($blessing);
+    die "Attempting to modify host but $wrong" if $wrong;
 
     db_retry($dbh_tests, [qw(resources)], $query);
 }
diff --git a/ts-examine-hostprops-save b/ts-examine-hostprops-save
index e50ea7fb..0c39b864 100755
--- a/ts-examine-hostprops-save
+++ b/ts-examine-hostprops-save
@@ -31,8 +31,8 @@ logm("setting host properties and flags");
 
 # NB: in order to aid debug only attempt to save the host props on flights
 # with intended real blessing, for the rest just do a dry run.
-our $dry_run = $blessing ne "real";
-logm("not saving host props/flags with intended blessing $blessing != real")
+our $dry_run = blessing_must_not_modify_host($blessing);
+logm("not saving host props/flags ($dry_run)")
     if $dry_run;
 
 foreach my $k (sort keys %r) {
-- 
2.11.0




 


Rackspace

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