Skip to contentSkip to conversation

dmrestrict audit: Preparatory fixes

PATCH New Ian Jackson 1 participant 12 messages Jun 12, 2018

lore
Share & tools
lore
#0 lore raw

cover dmrestrict audit: Preparatory fixes

From: Ian Jackson <[email protected]>

While working on auditing dm restriction, I came up with these miscellaneous improvements, bugfixes, slightly refactorings, and minor new features. I intend to push them to osstest pretest soon to get them out of my queue.

Ian Jackson (11):
ts-xen-install: Drop obsolete --check and $checkmode
cs-adjust-flight: Allow adjusting play flights after start
sg-run-job: Allow suppression of consequences of per-host-ts fail
TestSupport: Break out target_extract_distpart
ResourceCondition: Break out PropCompareBase
ResourceCondition: Provide PropEq
config: ExtraDebs: replace with DebianExtraPackages
ts-xen-install: DebianExtraPackages: call apt-get -f install
sg-run-job: add some comments about guest state
TestSupport: substeps: work if steps in ad-hoc tests take >1s
TestSupport: guest_var_boolean: Understand y' and 1' as well

 Osstest/ResourceCondition/PropCompareBase.pm | 66 +++++++++++++++++++
 Osstest/ResourceCondition/PropEq.pm          | 38 +++++++++++
 Osstest/ResourceCondition/PropMinVer.pm      | 45 ++-----------
 Osstest/TestSupport.pm                       | 14 +++-
 README                                       |  9 +++
 cs-adjust-flight                             |  6 +-
 production-config                            |  8 +--
 sg-run-job                                   | 15 ++++-
 ts-xen-install                               | 97 +++++++++++++++++-----------
 9 files changed, 212 insertions(+), 86 deletions(-)
 create mode 100644 Osstest/ResourceCondition/PropCompareBase.pm
 create mode 100644 Osstest/ResourceCondition/PropEq.pm
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/11 ts-xen-install: Drop obsolete --check and $checkmode

Since 5edec3222ff14b8200d5b41ed9af3c8d04c27314
ts-xen-build-check: reimplementation ...
in 2011 we have a fully general version, and the --check option is no longer used.

And since 467d6239daa352483ec8fef003bd4fc723702b77
pygrub: guest kernel install: move target_extract_jobdist_path into Osstest
also in 2011, --check has not worked properly, because that commit moved the relevant code somewhere where $checkmode was
not available and simply dropped the check.

So remove the vestigial code in ts-xen-build. As for @ARGV, we simply die if we see something that looks like an option.

---
 ts-xen-install | 46 ++++++++++++++++++----------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)
ts-xen-install +18 -28
index a9f8631..fcbb697 100755
@@ -26,23 +26,17 @@ use Osstest::TestSupport;
 use Data::Dumper;
 use Osstest::CXFabric;
 
-my $checkmode= 0;
-
 tsreadconfig();
 
 our @hos;
 
-if (@ARGV and $ARGV[0] eq '--check') {
-    $checkmode= 1;
-    shift @ARGV;
-    logm("checking builds are done...");
-} else {
-    if (!@ARGV) {
-	push @ARGV, 'host';
-    }
-    foreach my $k (@ARGV) {
-        push @hos, selecthost($k);
-    }
+die if @ARGV && $ARGV[0] =~ m/^-/;
+
+if (!@ARGV) {
+    push @ARGV, 'host';
+}
+foreach my $k (@ARGV) {
+    push @hos, selecthost($k);
 }
 
 our $ho;
@@ -372,19 +366,15 @@ sub forbidden () {
 END
 }
 
-if ($checkmode) {
-    extract();
-} else {
-    die if @hos > 1;
-    $ho= $hos[0];
+die if @hos > 1;
+$ho= $hos[0];
     
-    packages();
-    extradebs();
-    extract();
-    forbidden();
-    adjustconfig();
-    setupboot();
-    setupinitd();
-    ensurebridge();
-    hosts();
-}
+packages();
+extradebs();
+extract();
+forbidden();
+adjustconfig();
+setupboot();
+setupinitd();
+ensurebridge();
+hosts();
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH 2/11 cs-adjust-flight: Allow adjusting play flights after start

In reply to Ian Jackson

Specifically, rather than simply bombing out, if the flight already has steps, we call dbfl_check again with an empty list of OK blessings. dbfl_check will then bomb out, unless the flight's blessing or intended blessing is `play'. If it doesn't bomb out, we print a message.

---
 cs-adjust-flight | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
cs-adjust-flight +5 -1
index afb81cb..4f036f4 100755
@@ -465,7 +465,11 @@ sub changes () {
 	    $dbh_tests->prepare("SELECT * FROM steps WHERE flight = ?");
 	$steps_q->execute($dstflight);
 	my $step = $steps_q->fetchrow_hashref();
-	die "$dstflight already has steps\n".Dumper($step) if $step;
+	if ($step) {
+	    warn "$dstflight already has steps\n".Dumper($step) if $step;
+	    $mjobdb->dbfl_check($dstflight,[]);
+	    print STDERR "changing flight $dstflight anyway\n";
+	}
     }
 
     @changes = @org_changes;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH 3/11 sg-run-job: Allow suppression of consequences of per-host-ts fail

In reply to Ian Jackson
---
 sg-run-job | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
sg-run-job +10 -3
index aa97ee6..e1dc2d2 100755
@@ -216,7 +216,8 @@ proc testid_matches_globs {testid globs} {
 #       where STATUS is the job/step status to be used if the step
 #       status is not as expected, and the special meanings are:
 #
-#           -      Only for run-ts; suprresses exception on failure.
+#           -      for run-ts; suprresses exception on failure.
+#                  for per-host-ts; suppresses consequences of failure.
 #           !      Run this even if the job is being truncated.
 #                  (for per-host-ts, even if the job is no longer $ok)
 #           .      Shorthand for "fail"
@@ -286,6 +287,10 @@ proc iffail-check {iffail okexpr iffail_status_var} {
     global ok
     upvar 1 $iffail_status_var iffail_status
 
+    if {[regexp {^-} $iffail]} {
+	# move - to the end, since docs say it should have come first
+	regsub {^-} "$iffail-" {} iffail
+    }
     if {[regexp {^!?\.$} $iffail]} {
         regsub {\.$} $iffail fail iffail
     }
@@ -444,8 +449,10 @@ proc per-host-ts {iffail ident script args} {
     foreach host $need_xen_hosts await $awaitl {
         if {![reap-ts $await]} {
             jobdb::logputs stderr "$flight.$jobinfo(job) @$host $args failed"
-            set failed 1
-            set ok 0
+	    if {[string compare - $iffail_status]} {
+		set failed 1
+		set ok 0
+	    }
         }
     }
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

PATCH 4/11 TestSupport: Break out target_extract_distpart

In reply to Ian Jackson

No functional change.

---
 Osstest/TestSupport.pm | 10 +++++++++-
 ts-xen-install         |  4 +---
 2 files changed, 10 insertions(+), 4 deletions(-)
Osstest/TestSupport.pm +9 -1
index cebeb0d..6de566c 100644
@@ -70,7 +70,8 @@ BEGIN {
                       target_run_apt
                       target_install_packages target_install_packages_norec
                       target_jobdir target_extract_jobdistpath_subdir
-                      target_extract_jobdistpath target_tftp_prefix
+                      target_extract_jobdistpath target_extract_distpart
+		      target_tftp_prefix
                       lv_create lv_dev_mapper
 
                       poll_loop tcpconnect await_tcp
@@ -2343,6 +2344,13 @@ sub target_extract_jobdistpath ($$$$$) {
     target_cmd_root($ho, "cd / && tar -hzxf $distcopy", 300);
 }
 
+sub target_extract_distpart ($$;$) {
+    my ($ho, $part, $distpath_r) = @_;
+    target_extract_jobdistpath($ho, $part, "path_${part}dist",
+		$r{"$ho->{Ident}_${part}buildjob"} // $r{"${part}buildjob"},
+		$distpath_r);
+}
+
 sub target_tftp_prefix ($) {
     my ($ho) = @_;
 
ts-xen-install +1 -3
index fcbb697..17f7662 100755
@@ -81,9 +81,7 @@ sub extract () {
     push @parts, 'libvirt' if $r{toolstack} eq "libvirt";
 
     foreach my $part (@parts) {
-        target_extract_jobdistpath($ho, $part, "path_${part}dist",
-		$r{"$ho->{Ident}_${part}buildjob"} // $r{"${part}buildjob"},
-		\%distpath);
+	target_extract_distpart($ho, $part, \%distpath);
     }
     if (target_file_exists($ho, "/usr/lib64/efi/xen.efi")) {
 	target_cmd_root($ho,<<END);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

PATCH 5/11 ResourceCondition: Break out PropCompareBase

In reply to Ian Jackson

Make a base class so we can easily invent other kinds of resource property condition. The child is responsible only for stringification and the actual comparison.

These classes does not need Exporter, so drop all that. Use `use parent' to import the base class.

---
 Osstest/ResourceCondition/PropCompareBase.pm | 66 ++++++++++++++++++++++++++++
 Osstest/ResourceCondition/PropMinVer.pm      | 45 +++----------------
 2 files changed, 73 insertions(+), 38 deletions(-)
 create mode 100644 Osstest/ResourceCondition/PropCompareBase.pm
Osstest/ResourceCondition/PropCompareBase.pm new file +66 -0
new file mode 100644
index 0000000..5306bb8
@@ -0,0 +1,66 @@
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2015 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/>.
+
+package Osstest::ResourceCondition::PropCompareBase;
+
+use strict;
+use warnings;
+
+use Osstest;
+use Osstest::TestSupport;
+
+BEGIN {
+    use Exporter ();
+    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+    $VERSION     = 1.00;
+    @ISA         = qw(Exporter);
+    @EXPORT      = qw();
+    %EXPORT_TAGS = ( );
+
+    @EXPORT_OK   = qw();
+}
+
+sub new {
+    my ($class, $name, $prop, $val) = @_;
+
+    die "propname: $prop?" unless propname_check($prop);
+
+    return bless {
+	Prop => $prop,
+	Val => $val
+    }, $class;
+}
+
+sub check {
+    my ($pc, $restype, $resname) = @_;
+
+    # Using _cached avoids needing to worry about $dbh_tests being
+    # closed/reopened between invocations
+    my $hpropq = $dbh_tests->prepare_cached(<<END);
+       SELECT val FROM resource_properties
+	WHERE restype = ? AND resname = ? AND name = ?
+END
+    $hpropq->execute($restype, $resname, $pc->{Prop});
+
+    my $row= $hpropq->fetchrow_arrayref();
+    $hpropq->finish();
+
+    my $propval = $row->[0];
+
+    return $pc->_check($propval);
+}
+
+1;
Osstest/ResourceCondition/PropMinVer.pm +7 -38

65 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

PATCH 6/11 ResourceCondition: Provide PropEq

In reply to Ian Jackson

This can be used, for example, with the following entry in a hostflags runvar:
PropEq:Firmware:uefi

---
 Osstest/ResourceCondition/PropEq.pm | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Osstest/ResourceCondition/PropEq.pm
Osstest/ResourceCondition/PropEq.pm new file +38 -0
new file mode 100644
index 0000000..cf70994
@@ -0,0 +1,38 @@
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2015 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/>.
+
+package Osstest::ResourceCondition::PropEq;
+
+use strict;
+use warnings;
+
+use parent 'Osstest::ResourceCondition::PropCompareBase';
+
+use Osstest;
+use Osstest::TestSupport;
+
+sub stringify {
+    my ($pe) = @_;
+    return "'$pe->{Val}' eq property $pe->{Prop}";
+}
+
+sub _check {
+    my ($pe, $propval) = @_;
+    $propval //= '';
+    return $pe->{Val} eq $propval;
+}
+
+1;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

PATCH 7/11 config: ExtraDebs: replace with DebianExtraPackages

In reply to Ian Jackson

`ExtraDebs' is a silly name. Also the semantics are rather inflexible; we might want to install specific packages rather than the contents of a whole directory.

And, document it.

This variable has only just been introduced, so hopefully it is OK to replace and rename it now without causing too much disruption.

(osstest's own production runs each use their own copy of the config, so they will be fine. It's just downstreams, or users whose config is set up to use one not in their own tree, who will be affected.)

------------------------------

---
 README            |  9 +++++++++
 production-config |  8 ++++----
 ts-xen-install    | 46 ++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 53 insertions(+), 10 deletions(-)
README +9 -0
index 7b7bc52..2dfd4de 100644
@@ -537,6 +537,15 @@ DebianNonfreeFirmware
   grep-dctrl (for example because it's not Debian) then you must set
   this to the empty string, by writing  DebianNonfreeFirmware=''
 
+DebianExtraPackages_<firmware>_<arch>_<suite> [<item>... ]
+  Extra packages, or directories of them, to install on every Debian
+  host (dom0).  Each variable is a space-separated list of items.
+  Each <item> is relative to Images unless it starts with `/' or `./'.
+  It should be one of the following:
+    <directory-name>/                        update packages, dpkg -iGROEB
+    [.../]<package>_<version>_<pkgarch>.deb  install package, dpkg -iB
+    [.../]<package>_<version>_.deb           install _<hostarch>.deb
+
 Tftp*
    Settings related to the tftp server:
 
production-config +4 -4
index aa414d0..d89e89a 100644
@@ -106,10 +106,10 @@ MicrocodeUpdateI386 microcode.x86.2015-06-12.cpio
 # Update with ./mg-netgrub-loader-update
 TftpGrubVersion XXXX-XX-XX
 
-ExtraDebs_uefi_i386_jessie   2018-04-01
-ExtraDebs_uefi_amd64_jessie  2018-04-01
-ExtraDebs_uefi_i386_stretch  2018-04-01
-ExtraDebs_uefi_amd64_stretch 2018-04-01
+DebianExtraPackages_uefi_i386_jessie   extradebs-uefi-i386-2018-04-01/
+DebianExtraPackages_uefi_amd64_jessie  extradebs-uefi-amd64-2018-04-01/
+DebianExtraPackages_uefi_i386_stretch  extradebs-uefi-i386-2018-04-01/
+DebianExtraPackages_uefi_amd64_stretch extradebs-uefi-amd64-2018-04-01/
 
 XenUsePath /usr/groups/xencore/systems/bin/xenuse
 XenUseUser osstest
ts-xen-install +40 -6

60 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

PATCH 8/11 ts-xen-install: DebianExtraPackages: call apt-get -f install

In reply to Ian Jackson

Currently this is just a precaution.

---
 ts-xen-install | 1 +
 1 file changed, 1 insertion(+)
ts-xen-install +1 -0
index d3a9d11..9913e85 100755
@@ -99,6 +99,7 @@ sub some_extradebs ($) {
 	target_cmd_root($ho,
 			"dpkg --force-confold $dpkgopts $ontarget </dev/null",
 			300);
+	target_run_apt($ho, qw(-f install));
     }
 }
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

PATCH 9/11 sg-run-job: add some comments about guest state

In reply to Ian Jackson
---
 sg-run-job | 2 ++
 1 file changed, 2 insertions(+)
sg-run-job +2 -0
index e1dc2d2..0a3f688 100755
@@ -604,11 +604,13 @@ proc test-guest-migr {g} {
 }
 
 proc test-guest {g} {
+    # guest is expected to be running, and ends up stopped
     test-guest-migr $g
     test-guest-nomigr $g
 }
 
 proc test-guest-nomigr {g} {
+    # guest is expected to be running and ends up stopped
     run-ts . =   ts-guest-stop    + host $g
 
     repeat-ts 10 =.repeat \
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#10 lore raw

PATCH 10/11 TestSupport: substeps: work if steps in ad-hoc tests take >1s

In reply to Ian Jackson

When running by hand, OSSTEST_TESTID is not set. We provide a value with the time and the pid in it, so that rerunning the script by hand works, even though in production this would result in multiple identically-named substeps.

But we need to fix this value for the duration of the script. Otherwise when it calls substep_finish, if the time has moved on, it computes a different OSSTEST_TESTID and therefore a different substep name, and then the substep machinery smells a rat and bombs out.

---
 Osstest/TestSupport.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest/TestSupport.pm +1 -1
index 6de566c..7bc40f3 100644
@@ -245,7 +245,7 @@ END
 sub complete_testid ($) {
     my ($testidr) = @_;
     $$testidr =~ s{^(?=/)}{
-	$ENV{OSSTEST_TESTID} // sprintf('SUBSTEP-%s-%s', time, $$)
+	$ENV{OSSTEST_TESTID} //= sprintf('SUBSTEP-%s-%s', time, $$)
     }e;
 }
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

PATCH 11/11 TestSupport: guest_var_boolean: Understand `y' and `1' as well

In reply to Ian Jackson

Previously this would treat y' and 1' as false, which is very confusing.

---
 Osstest/TestSupport.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest/TestSupport.pm +1 -1
index 7bc40f3..d8ed02d 100644
@@ -1825,7 +1825,7 @@ sub guest_var ($$$) {
 
 sub guest_var_boolean ($$) {
     my ($gho, $runvartail) = @_;
-    return guest_var($gho, $runvartail, 'false') =~ m/true/;
+    return guest_var($gho, $runvartail, 'false') =~ m/true|y|1/;
 }
 
 sub guest_var_commalist ($$) {
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel