Skip to contentSkip to conversation

mg-hosts mknetbootdir: Improve sub-option parser

PATCH New Ian Jackson 1 participant 3 messages Aug 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 mg-hosts mknetbootdir: Improve sub-option parser

No semantic change.

---
 mg-hosts | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
mg-hosts +8 -1
index 58b4acc3..d68f7b4e 100755
@@ -121,7 +121,14 @@ sub l ($) { return split /,/, $_[0]; }
 
 sub cmd_mknetbootdir () {
     my $dryrun = 0;
-    if (@ARGV && $ARGV[0] eq '-n') { shift @ARGV; $dryrun= 1; }
+    while (@ARGV && $ARGV[0] =~ m/^-/) {
+	$_ = shift @ARGV;
+	last if $_ =~ m/^--?$/;
+	while (m/^-./) {
+	    if (s/^-n/-/) { $dryrun= 1; }
+	    else { die "unknown mknetbootdir option $_"; }
+	}
+    }
     die unless @ARGV>=1;
     my $sudo = $ENV{'OSSTEST_SUDO'} // 'sudo';
     foreach my $hn (@ARGV) {
Signature · 7 lines
2.11.0


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

PATCH 2/3 host properties: Firmware: Move default to selecthost

Drop the explicit default from all the call sites. This centralises the default. This is going to be the new scheme for host properties in general.

(Two of the call sites had a different default, "", which in their context was semantically equivalent to "bios".)

---
 Osstest/Debian.pm      |  4 ++--
 Osstest/TestSupport.pm | 13 +++++++++----
 ts-xen-install         |  2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)
Osstest/Debian.pm +2 -2
index 911d8905..79aa2d24 100644
@@ -443,7 +443,7 @@ sub setupboot_grub2 ($$$$) {
 
     # Grub2 on jessie/stretch ARM* doesn't do multiboot, so we must chainload.
     my $need_uefi_chainload =
-        get_host_property($ho, "firmware", "") eq "uefi" &&
+        get_host_property($ho, "firmware") eq "uefi" &&
         $ho->{Suite} =~ m/jessie|stretch/ && $ho->{Arch} =~ m/^arm/;
 
     my $parsemenu= sub {
@@ -1498,7 +1498,7 @@ END
 
     preseed_microcode($ho,$sfx);
 
-    if (get_host_property($ho, "firmware",'') eq "uefi") {
+    if (get_host_property($ho, "firmware") eq "uefi") {
 	die unless $ho->{Suite} =~ m/jessie|stretch/;
 	# Prevent grub-install from making a new Debian boot entry, so
 	# we always reboot from the network. Debian bug #789798 proposes a
Osstest/TestSupport.pm +9 -4
index e554af38..b629fb7d 100644
@@ -1218,7 +1218,10 @@ sub selecthost ($;$) {
 
     #----- calculation of the host's properties -----
 
-    $ho->{Properties} = { };
+    # Firstly, hardcoded defaults
+    $ho->{Properties} = {
+        Firmware => 'bios',
+    };
     my $setprop = sub {
 	my ($pn,$val) = @_;
 	$ho->{Properties}{$pn} = $val;
@@ -1363,6 +1366,8 @@ sub propname_check ($) {
 
 # It is fine to call this on a guest object too, in which case it will
 # always return $defval.
+# Ideally all uses of $defval would be replaced by defaults in the
+# initial array in selecthost.
 sub get_host_property ($$;$) {
     my ($ho, $prop, $defval) = @_;
     return $defval unless $ho->{Properties};
@@ -2811,7 +2816,7 @@ sub host_netboot_file ($;$) {
     # in array context, returns (dir, pathtail)
     #  where dir does not depend on $templatekeytail
     my %v = %r;
-    my $firmware = get_host_property($ho, "firmware", "bios");
+    my $firmware = get_host_property($ho, "firmware");
     my $templatekeybase = $firmware eq 'uefi' ? 'NetGrub' : 'Pxe';
     $templatekeytail //= 'Templates';
     my $templatekey = $templatekeybase.$templatekeytail;
@@ -2937,7 +2942,7 @@ END
 
 sub setup_netboot_local ($) {
     my ($ho) = @_;
-    my $firmware = get_host_property($ho, "firmware", "bios");
+    my $firmware = get_host_property($ho, "firmware");
     $firmware =~ s/-/_/g;
     no strict qw(refs);
     return &{"setup_netboot_local_${firmware}"}($ho);
@@ -2945,7 +2950,7 @@ sub setup_netboot_local ($) {
 
 sub setup_netboot_di ($$$$$;%) {
     my ($ho,$kern,$initrd,$dicmd,$hocmd,%xopts) = @_;
-    my $firmware = get_host_property($ho, "firmware", "bios");
+    my $firmware = get_host_property($ho, "firmware");
     $firmware =~ s/-/_/g;
     no strict qw(refs);
     return &{"setup_netboot_di_${firmware}"}($ho,$kern,$initrd,
ts-xen-install +1 -1
index 2d3c644d..154f78c7 100755
@@ -114,7 +114,7 @@ sub extradebs () {
     some_extradebs([ 'DebianExtraPackages', $suite ]);
 
     # $c{ DebianExtraPackages_<firmware>_<arch>_<suite> }
-    my $firmware = get_host_property($ho, "firmware", "bios");
+    my $firmware = get_host_property($ho, "firmware");
     some_extradebs([ 'DebianExtraPackages', $firmware, $ho->{Arch}, $suite ]);
 }
 
Signature · 7 lines
2.11.0


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

PATCH 3/3 mg-hosts mknetbootdir: Introduce and require -F<firmware>

In reply to Ian Jackson

If one runs
./mg-hosts mknetbootdir HOST
before having sorted out all the host configuration, it uses the default configuration value for the host's firmware kind, which is "bios". If the configuration is then changed, things don't work. This is confusing.

So ask the user to specify one or more -F<firmware>, or -Fany.

CC Dominic Brekau <[email protected]>
---
 mg-hosts | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
mg-hosts +11 -1
index d68f7b4e..14f816ae 100755
@@ -19,7 +19,7 @@
 
 # Usages:
 #
-#  ./mg-hosts mknetbootdir HOST...
+#  ./mg-hosts mknetbootdir -Fany | -F<firmware>... HOST...
 #               Create directories for netboot as expected by the rest
 #               of osstest.  Will use "sudo". The HOST(s) must be
 #               allocated (via mg-allocate HOST).
@@ -121,19 +121,29 @@ sub l ($) { return split /,/, $_[0]; }
 
 sub cmd_mknetbootdir () {
     my $dryrun = 0;
+    my %expect_firmware;
     while (@ARGV && $ARGV[0] =~ m/^-/) {
 	$_ = shift @ARGV;
 	last if $_ =~ m/^--?$/;
 	while (m/^-./) {
 	    if (s/^-n/-/) { $dryrun= 1; }
+	    elsif (s/^-F(.*)//) { $expect_firmware{$1} = 1 }
 	    else { die "unknown mknetbootdir option $_"; }
 	}
     }
+    die "need at least one -F<firmware> or -Fany option"
+	unless %expect_firmware;
     die unless @ARGV>=1;
     my $sudo = $ENV{'OSSTEST_SUDO'} // 'sudo';
     foreach my $hn (@ARGV) {
         my $ho= selecthost("host=$hn");
 	my ($dir, $file) = host_netboot_file($ho);
+	if (!$expect_firmware{any}) {
+	    my $got_firmware = get_host_property($ho, "firmware");
+	    die
+ "host $hn configuration says firmware \`$got_firmware', not as expected\n"
+		unless $expect_firmware{$got_firmware};
+	}
         die unless defined $dir;
 	my ($rdir, $realfile) = host_netboot_file($ho, 'TemplatesReal');
 	$realfile //= $file;
Signature · 7 lines
2.11.0


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