@@ -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) {
@@ -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);
}
@@ -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) {
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@eu.citrix.com> --- Osstest.pm | 10 +++++++++- Osstest/HostDB/Executive.pm | 4 ++-- ts-examine-hostprops-save | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-)