Skip to contentSkip to conversation

host props/flags: Break out blessing_must_not_modify_host

PATCH New Ian Jackson 1 participant 2 messages Mar 31, 2020

lore
Share & tools
lore
#0 lore raw

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.

---
 Osstest.pm                  | 10 +++++++++-
 Osstest/HostDB/Executive.pm |  4 ++--
 ts-examine-hostprops-save   |  4 ++--
 3 files changed, 13 insertions(+), 5 deletions(-)
Osstest.pm +9 -1
index 27136bc9..54f0085c 100644
@@ -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) {
Osstest/HostDB/Executive.pm +2 -2
index a6dc4462..41cce046 100644
@@ -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);
 }
ts-examine-hostprops-save +2 -2
index e50ea7fb..0c39b864 100755
@@ -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) {
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 2/2 host props/flags: Save for commissioning flights too

Obviously we want this!

---
 Osstest.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest.pm +1 -1
index 54f0085c..1e381d8f 100644
@@ -411,7 +411,7 @@ 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 '' if $intended_blessing =~ qr{^real$|^commission-};
     return "intended blessing $intended_blessing != real";
 }
 
Signature · 1 line
2.11.0