]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
wip reorg new style pxe
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 18 Oct 2012 17:19:34 +0000 (18:19 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 18 Oct 2012 17:19:34 +0000 (18:19 +0100)
Osstest.pm
Osstest/TestSupport.pm
README
mg-debian-installer-update
mg-hosts
production-config
standalone-config-example
standalone-reset
ts-host-install

index 1b5c725f25733d0f507a72c2b62bb993ab04f14c..e54eca3cde307a34ef04d8b2101be96b9090b604 100644 (file)
@@ -55,8 +55,6 @@ our %c = qw(
 
     Baud  115200
 
-    Tftp  /tftpboot/pxe
-
     DebianNonfreeFirmware firmware-bnx2
 );
 
@@ -133,20 +131,27 @@ sub readglobalconfig () {
     my $whoami = `whoami` or die $!;
     chomp($whoami) or die;
 
+    my $nodename = `uname -n` or die $!;
+    chomp($nodename) or die;
+    my $myfqdn = "$nodename.$c{DnsDomain}";
+
+    $c{TftpPath} ||= "/tftpboot/";
+    $c{TftpHost} ||= $myfqdn;
+    $c{TftpPxeDir} ||= "pxelinux.cfg/";
+    $c{TftpPxeTemplates} ||= '%ipaddrhex% 01-%etherhyph%';
+    $c{TftpPlayDir} ||= "$whoami/osstest/";
+    $c{TftpTmpDir} ||= "$c{TftpPlayDir}tmp/";
+
+    $c{TftpDiBase} ||= "$c{TftpPlayDir}debian-installer";
+    $c{TftpDiVersion} ||= 'current';
+
     $c{WebspaceFile} ||= "$ENV{'HOME'}/public_html/";
-    if (!$c{WebspaceUrl}) {
-       my $nodename = `uname -n` or die $!;
-       chomp($nodename) or die;
-       $c{WebspaceUrl} = "http://$nodename.$c{DnsDomain}/~$whoami/";
-    }
+    $c{WebspaceUrl} ||= "http://$myfqdn/~$whoami/";
     $c{WebspaceCommon} ||= 'osstest/';
     $c{WebspaceLog} ||= '/var/log/apache2/access.log';
 
     $c{OverlayLocal} ||= "overlay-local";
     $c{GuestDebianSuite} ||= $c{DebianSuite};
-    
-    $c{PxeDiBase} ||= "$whoami/osstest/debian-installer";
-    $c{PxeDiVersion} ||= 'current';
 }
 
 sub augmentconfigdefaults {
index 598c20e7e7af21ba7cead0dd8ddaf35ecccd5f46..c1c4f25f16ee764244d79ed416b2781b20efcdb0 100644 (file)
@@ -73,7 +73,7 @@ BEGIN {
 
                       await_webspace_fetch_byleaf create_webfile
                       file_link_contents get_timeout
-                      setup_pxeboot setup_pxeboot_local host_pxedir 
+                      setup_pxeboot setup_pxeboot_local host_pxefile
                       );
     %EXPORT_TAGS = ( );
 
@@ -698,10 +698,14 @@ sub selecthost ($) {
     my $serialmeth = get_host_property($ho,'serial','noop');
     $ho->{SerialMethobj} = get_host_method_object($ho,'Serial',$serialmeth);
 
-    my $ip_packed= gethostbyname($ho->{Fqdn});
-    die "$ho->{Fqdn} ?" unless $ip_packed;
-    $ho->{Ip}= inet_ntoa($ip_packed);
-    die "$ho->{Fqdn} ?" unless defined $ho->{Ip};
+    $ho->{IpStatic} = get_host_property($ho,'ip-addr');
+    if (!defined $ho->{IpStatic}) {
+       my $ip_packed= gethostbyname($ho->{Fqdn});
+       die "$ho->{Fqdn} ?" unless $ip_packed;
+       $ho->{IpStatic}= inet_ntoa($ip_packed);
+       die "$ho->{Fqdn} ?" unless defined $ho->{IpStatic};
+    }
+    $ho->{Ip}= $ho->{IpStatic};
 
     $mjobdb->host_check_allocated($ho);
 
@@ -1665,21 +1669,42 @@ sub file_link_contents ($$) {
     logm("wrote $fn");
 }
 
-sub host_pxedir ($) {
+sub host_pxefile ($) {
     my ($ho) = @_;
-    my $dir= $ho->{Ether};
-    $dir =~ y/A-Z/a-z/;
-    $dir =~ y/0-9a-f//cd;
-    length($dir)==12 or die "$dir";
-    $dir =~ s/../$&-/g;
-    $dir =~ s/\-$//;
-    return $dir;
+    my %v = %r;
+    if (defined $ho->{Ether}) {
+       my $eth = $v{'ether'} = $ho->{Ether};
+       $eth =~ y/A-Z/a-z/;
+       $eth =~ y/0-9a-f//cd;
+       length($eth)==12 or die "$eth ?";
+       $eth =~ s/../$&-/g;
+       $eth =~ s/\-$//;
+       $v{'etherhyph'} = $eth;
+    }
+    if (defined $ho->{IpStatic}) {
+       my $ip = $ho->{IpStatic};
+       $ip =~ s/\b0+//g;
+       $v{'ipaddr'} = $ip;
+       $v{'ipaddrhex'} = sprintf "%02X%02X%02X%02X", split /\./, $ip;
+    }
+    foreach my $pat (split /\s+/, $c{TftpPxeTemplates}) {
+       # we skip patterns that contain any references to undefined %var%s
+       $pat =~ s{\%(\w*)\%}{
+                   $1 eq '' ? '%' :
+                   defined($v{$1}) ? $v{$1} :
+                   next;
+                }ge;
+       # and return the first pattern we managed to completely substitute
+        return $pat;
+    }
+    die "no pxe template matched $c{TftpPxeTemplates} ".
+        (join ",", sort keys %v)." ?";
 }
 
 sub setup_pxeboot ($$) {
     my ($ho, $bootfile) = @_;
-    my $dir= host_pxedir($ho);
-    file_link_contents($c{Tftp}."/$dir/pxelinux.cfg", $bootfile);
+    my $f= host_pxefile($ho);
+    file_link_contents("$c{TftpPath}$c{TftpPxeDir}$f", $bootfile);
 }
 
 sub setup_pxeboot_local ($) {
diff --git a/README b/README
index de80536f94e608b1985cee8ecadb8f29a5982a9c..5808266047572e49e9c3919237ea0ef21499c825 100644 (file)
--- a/README
+++ b/README
@@ -4,6 +4,7 @@ To run osstest in standalone mode:
      sqlite3
      tcl8.4 tclx8.4 libsqlite3-tcl
      libdbi-perl libdbd-sqlite3-perl
+     pax rsync
 
  - Write a config file
     ~/.xen-osstest/config
@@ -130,6 +131,19 @@ GuestDebianSuite   defaults to DebianSuite
 
 DebianPreseed      added to existing preseed file
 
+TftpPxeTemplates
+    List (space-separated) of template filenames for writing
+    The templates contain variable substitutions %var%
+    The variables are the runvars plus
+        ether         host/guest mac address
+        etherhyp      ... in lowercase hyphen-separated form (for pxelinux)
+       ipaddr        host/guest static ip address
+       ipaddrhex     ... in uppercase hex form (for pxelinux)
+    Templates containing references to unknown %var%s - particularly,
+    the host mac address when not known, or the guest's dynamic
+    ip address - are skipped.  The first template all of whose ingredients
+    are known is used, with TftpPath and TftpPxeDir prepended.
+
 ========================================
 
 Host-specific config settigs
index 916620c7be0cfafb26091c49427c9855c06f000b..d8bac2a8dc02c7c154af486d49ec497c5492ddbb 100755 (executable)
@@ -18,7 +18,7 @@ src=$sbase/main/installer-$arch/current/images/netboot/debian-installer/$arch
 pfile=$sbase/non-free/binary-$arch/Packages.bz2
 files='initrd.gz linux'
 
-dstroot=`getconfig Tftp`/`getconfig PxeDiBase`/
+dstroot=`getconfig TftpPath`/`getconfig TftpDiBase`/
 date=`date +%Y-%m-%d`-$suite
 dst=$arch/$date
 
index deb1cde0c824b639fd5999289e64c849328143f0..63cf01acfdb8f9d5c4187dc6efc6de68f5275347 100755 (executable)
--- a/mg-hosts
+++ b/mg-hosts
@@ -27,7 +27,7 @@ sub cmd_mkpxedir () {
         $macdir =~ s/\:/-/g;
         system_checked(<<END);
             set -e
-            cd $c{Tftp}
+           cd $c{TftpPath}$c{TftpPxeDir}
             sudo chown root.$c{TftpPxeGroup} $macdir
             sudo chmod 2775 $macdir
             sudo rm -f $hn
index a52e5342dd9c679e9a1ff558b140d20a5ccfa2c7..4099457746fb8dc60b18c8ee686aa5849670612f 100644 (file)
@@ -47,9 +47,10 @@ END
 
 PlanRogueAllocationDuration= 86400*7
 
+TftpPath /usr/groups/netboot/
+
 TftpPxeGroup osstest
-PxeDiBase osstest/debian-installer
-PxeDiVersion 2012-01-30-squeeze
+TftpDiVersion 2012-01-30-squeeze
 
 # We use the IP address because Citrix can't manage reliable nameservice
 #DebianMirrorHost debian.uk.xensource.com
index 67882d43bad68190345680928c19a0b5325c9dc2..4f4fe425f85f09b429a6cb499e3085b17e7221f4 100644 (file)
@@ -1,11 +1,13 @@
-DnsDomain cam.xci-test.com
+DnsDomain uk.xensource.com
 NetNameservers 10.80.248.2 10.80.16.28 10.80.16.67
 
-TestHost bedbug
-HostProp_bedbug_Ether 00:13:72:14:c0:51
+TestHost calder
+#HostProp_bedbug_Ether 00:13:72:14:c0:51
 
-HostProp_DhcpWatchMethod leases dhcp3 woking.cam.xci-test.com:5556
-#HostProp_DhcpWatchMethod leases dhcp3 dhcp.uk.xensource.com:5556
+#HostProp_DhcpWatchMethod leases dhcp3 woking.cam.xci-test.com:5556
+HostProp_DhcpWatchMethod leases dhcp3 dhcp.uk.xensource.com:5556
+
+TftpPath /usr/groups/netboot/
 
 DebianMirrorHost debian.uk.xensource.com
 
index d709af959ca1b6cd481013bcd43f59c0dddc41fa..64a94fe1a125af7df79136a762211f66bd9578ce 100755 (executable)
@@ -57,14 +57,17 @@ ensure_key "$overlay"/etc/ssh/ssh_host_dsa_key -t dsa
 
 #---------- ensuring we can update pxe files and have d-i ----------
 
-tftp=`getconfig Tftp`
+tftp=`getconfig TftpPath`
 if ! test -d "$tftp"; then
        echo >&2 \
-'Warning, Tftp variable pointing to tftp server needed to do host installs &c'
+'Warning, TftpPath variable would be needed for host installs &c'
 else
 
-       dibase=`getconfig PxeDiBase`
-       diver=`getconfig PxeDiVersion`
+       tftptmp=`getconfig TftpTmpDir`
+       ensure_dir "$tftp$tftptmp"
+
+       dibase=`getconfig TftpDiBase`
+       diver=`getconfig TftpDiVersion`
        suite=`getconfig DebianSuite`
        firmware=`getconfig DebianNonfreeFirmware`
 
index 834ba627f69cd47d0d36c3478e7f791d93779b2c..60285265951528a571269341f3c084ab9daa11b5 100755 (executable)
@@ -106,17 +106,17 @@ END
 sub setup_pxeboot_firstboot($) {
     my ($ps_url) = @_;
     
-    my $d_i= $c{PxeDiBase}.'/'.$r{arch}.'/'.$c{PxeDiVersion};
+    my $d_i= $c{TftpDiBase}.'/'.$r{arch}.'/'.$c{TftpDiVersion};
     
     my @installcmdline= qw(vga=normal);
     push @installcmdline, di_installcmdline_core($ho, $ps_url, %xopts);
 
     my $src_initrd= "$d_i/initrd.gz";
-    my @initrds= "$c{Tftp}/$src_initrd";
+    my @initrds= "$c{TftpPath}/$src_initrd";
 
     foreach my $fp (keys %{ $ho->{Flags} }) {
         $fp =~ s/^need-firmware-deb-// or next;
-        my $cpio= "$c{Tftp}/$d_i/$fp.cpio.gz";
+        my $cpio= "$c{TftpPath}/$d_i/$fp.cpio.gz";
         if (stat $cpio) {
             logm("using firmware from: $cpio");
             push @initrds, $cpio;
@@ -133,6 +133,8 @@ sub setup_pxeboot_firstboot($) {
 
     my $wantphysif= get_host_property($ho,'interface force','auto');
     if ($wantphysif ne 'auto') {
+       die "need Ether for $ho->{Name} ($wantphysif)"
+           unless defined $ho->{Ether};
         system_checked(qw(mkdir -p --), "$initrd_overlay.d/etc/udev/rules.d");
         file_simple_write_contents
             ("$initrd_overlay.d/etc/udev/rules.d/70-persistent-net.rules",
@@ -149,10 +151,10 @@ END
     push @initrds, "$initrd_overlay.cpio.gz";
 
     logm("using initrds: @initrds");
-    my $initrd= host_pxedir($ho)."/initrd.gz";
-    system_checked("cat -- @initrds >$c{Tftp}/$initrd");
+    my $initrd= "$c{TftpTmpDir}$ho->{Name}--initrd.gz";
+    system_checked("cat -- @initrds >$c{TftpPath}$initrd");
     
-    push @installcmdline, ("initrd=$initrd",
+    push @installcmdline, ("initrd=/$initrd",
                            "domain=$c{TestHostDomain}",
                            );
     push @installcmdline,
@@ -169,7 +171,7 @@ timeout 5
 label overwrite
        menu label ^Overwrite
        menu default
-       kernel $d_i/linux
+       kernel /$d_i/linux
        append $installcmdline
 default overwrite
 END