Skip to contentSkip to conversation

osstest: add native FreeBSD build tests

PATCH Superseded Roger Pau Monne 1 participant 7 messages Aug 14, 2014 – Sep 15, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover osstest: add native FreeBSD build tests

This series add support for bootstrapping a bare metal FreeBSD install using OSS Test and compiling Xen on it.

The first patch adds support for executing commands on remote boxes using ssh with password, which is needed in order to login into the installer. The rest of the patches focus on installing FreeBSD, the Xen build dependencies, and finally compiling the Xen kernel and tools.

I've been manually running the tests using the following runes:

OSSTEST_FLIGHT=standalone OSSTEST_JOB=build-amd64-freebsd OSSTEST_HOST=kodo4 ./ts-freebsd-host-install host=kodo4 OSSTEST_FLIGHT=standalone OSSTEST_JOB=build-amd64-freebsd OSSTEST_HOST=kodo4 ./ts-xen-build-prep-freebsd host=kodo4 OSSTEST_FLIGHT=standalone OSSTEST_JOB=build-amd64-freebsd OSSTEST_HOST=kodo4 ./ts-xen-build host=kodo4

Thanks, Roger.

#1 lore raw

PATCH v2 1/5 osstest: add routine to execute ssh with password

This is needed when bootstrapping FreeBSD, since the installer has ssh enabled with the root password set to 'root' by default.

---
Changes since RFC:
- Place the temp filename in a local variable.
- Add error checks.

---
 Osstest/TestSupport.pm |   43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)
Osstest/TestSupport.pm +38 -5
index fea54d5..1a6aec5 100644
@@ -60,6 +60,7 @@ BEGIN {
                       target_install_packages target_install_packages_norec
                       target_jobdir target_extract_jobdistpath_subdir
                       target_extract_jobdistpath target_guest_lv_name
+                      target_cmd_root_with_password
 
                       poll_loop tcpconnect await_tcp
                       contents_make_cpio file_simple_write_contents
@@ -313,12 +314,11 @@ END
 #---------- running commands eg on targets ----------
 
 sub cmd {
-    my ($timeout,$stdout,@cmd) = @_;
+    my ($timeout,$child_sub,@cmd) = @_;
     my $child= fork;  die $! unless defined $child;
     if (!$child) {
-        if (defined $stdout) {
-            open STDOUT, '>&', $stdout
-                or die "STDOUT $stdout $cmd[0] $!";
+        if (defined $child_sub) {
+            $child_sub->();
         }
         exec @cmd;
         die "$cmd[0]: $!";
@@ -573,9 +573,42 @@ sub tcmd { # $tcmd will be put between '' but not escaped
 sub target_cmd ($$;$) { tcmd(undef,'osstest',@_); }
 sub target_cmd_root ($$;$) { tcmd(undef,'root',@_); }
 
+sub target_cmd_root_with_password {
+    my ($ho,$tcmd,$timeout,$password) = @_;
+    my $temp_name = "tmp/t.ssh-password-helper.$flight.$job";
+
+    open(my $temp_fh, '>', $temp_name)
+      or die "Cannot open $temp_name: $!";
+    print $temp_fh "#!/bin/sh\n\necho \"$password\"\n"
+      or die "Cannot write to $temp_name: $!";
+    chmod 0755, $temp_name
+      or die "Cannot chmod $temp_name: $!";
+    close $temp_fh
+      or die "Cannot close $temp_name: $!";
+
+    my $child_sub = sub {
+                           $ENV{DISPLAY} = ":0";
+                           $ENV{SSH_ASKPASS} = "tmp/t.ssh-password-helper.$flight.$job";
+                           setsid or die "Can't start a new session: $!";
+                        };
+
+    my $ssh_opts = [qw(-o BatchMode=no
+                       -o PasswordAuthentication=yes
+                       -o ChallengeResponseAuthentication=yes),
+                    @{ sshopts() }];
+
+    tcmdex($timeout,$child_sub,
+           'ssh', $ssh_opts,
+           sshuho("root",$ho), $tcmd);
+
+    unlink $temp_fh;
+}
+
 sub tcmdout {
     my $stdout= IO::File::new_tmpfile();
-    tcmd($stdout,@_);
+    my $stdout_sub = sub { open STDOUT, '>&', $stdout
+                              or die "STDOUT $stdout $!"; };
+    tcmd($stdout_sub,@_);
     $stdout->seek(0,0) or die "$stdout $!";
     my $r;
     { local ($/) = undef;
Signature · 7 lines
1.7.7.5 (Apple Git-26)


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

PATCH v2 2/5 osstest: add support for installing bare metal FreeBSD

In reply to Roger Pau Monne

This is done using mfsBSD, which can be booted from pxelinux and contains a script to automatically install FreeBSD using ZFS on root. After the install the host is set to boot from the local disk.

---
Changes since RFC:
- Set the bridge to use the MAC from the first added interface instead of generating a random one.
- Launch DHCP on the bridge instead of the nic.
- Add a list of FreeBSD ftp mirrors and iterate over them in order to find a working one.
- Add support for finding the primary disk and nic automatically.
- Switch shell to sh (instead of the default csh), and use set -e in order to exit if a command fails.
- Replace echo "-Dh" with printf "%s" "-Dh".
- Copy installer keys into the installed system in order to prevent it from generating new keys on the first boot.

---
 ts-freebsd-host-install |  235 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 235 insertions(+), 0 deletions(-)
 create mode 100755 ts-freebsd-host-install
ts-freebsd-host-install new file +235 -0
new file mode 100755
index 0000000..06caeaa
@@ -0,0 +1,235 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2014 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/>.
+
+use strict qw(vars);
+use DBI;
+use POSIX;
+
+use Osstest;
+use Osstest::TestSupport;
+use Osstest::Logtailer;
+
+tsreadconfig();
+
+our ($whhost) = @ARGV;
+$whhost ||= 'host';
+our $ho= selecthost($whhost);
+exit 0 if $ho->{Flags}{'no-reinstall'};
+exit 0 if $ho->{SharedReady};
+
+our %timeout= qw(ReadPreseed  350
+                 Sshd        2400);
+
+# TODO: this should be runvars
+our $version = '10.0-RELEASE';
+
+# List of FreeBSD mirrors, obtained from:
+# http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/mirrors-ftp.html
+# 13/08/2014
+our @ftp_hosts = qw(ftp.freebsd.org ftp1.freebsd.org ftp2.freebsd.org
+                    ftp3.freebsd.org ftp4.freebsd.org ftp5.freebsd.org
+                    ftp6.freebsd.org ftp7.freebsd.org ftp10.freebsd.org
+                    ftp11.freebsd.org ftp13.freebsd.org ftp14.freebsd.org
+                    ftp1.am.freebsd.org ftp.au.freebsd.org ftp2.au.freebsd.org
+                    ftp3.au.freebsd.org ftp.at.freebsd.org ftp2.br.freebsd.org
+                    ftp3.br.freebsd.org ftp4.br.freebsd.org ftp.ca.freebsd.org
+                    ftp2.ca.freebsd.org ftp.cn.freebsd.org ftp.cz.freebsd.org
+                    ftp2.cz.freebsd.org ftp.dk.freebsd.org ftp.ee.freebsd.org
+                    ftp.fi.freebsd.org ftp.fr.freebsd.org ftp1.fr.freebsd.org
+                    ftp3.fr.freebsd.org ftp5.fr.freebsd.org ftp6.fr.freebsd.org
+                    ftp7.fr.freebsd.org ftp8.fr.freebsd.org ftp.de.freebsd.org
+                    ftp1.de.freebsd.org ftp2.de.freebsd.org ftp4.de.freebsd.org
+                    ftp5.de.freebsd.org ftp7.de.freebsd.org ftp8.de.freebsd.org
+                    ftp.gr.freebsd.org ftp2.gr.freebsd.org ftp.hk.freebsd.org
+                    ftp3.ie.freebsd.org ftp.jp.freebsd.org ftp2.jp.freebsd.org
+                    ftp3.jp.freebsd.org ftp4.jp.freebsd.org ftp5.jp.freebsd.org
+                    ftp6.jp.freebsd.org ftp7.jp.freebsd.org ftp8.jp.freebsd.org
+                    ftp9.jp.freebsd.org ftp.kr.freebsd.org ftp2.kr.freebsd.org
+                    ftp.nl.freebsd.org ftp2.nl.freebsd.org ftp.nz.freebsd.org
+                    ftp.no.freebsd.org ftp.pl.freebsd.org ftp.ru.freebsd.org
+                    ftp2.ru.freebsd.org ftp4.ru.freebsd.org ftp5.ru.freebsd.org
+                    ftp6.ru.freebsd.org ftp.si.freebsd.org ftp.za.freebsd.org
+                    ftp2.za.freebsd.org ftp4.za.freebsd.org ftp.es.freebsd.org
+                    ftp3.es.freebsd.org ftp.se.freebsd.org ftp2.se.freebsd.org
+                    ftp.ch.freebsd.org ftp.tw.freebsd.org ftp2.tw.freebsd.org
+                    ftp4.tw.freebsd.org ftp5.tw.freebsd.org ftp.ua.freebsd.org
+                    ftp6.ua.freebsd.org ftp7.ua.freebsd.org ftp.uk.freebsd.org
+                    ftp2.uk.freebsd.org ftp3.uk.freebsd.org ftp4.uk.freebsd.org
+                    ftp5.uk.freebsd.org ftp1.us.freebsd.org ftp2.us.freebsd.org
+                    ftp3.us.freebsd.org ftp4.us.freebsd.org ftp5.us.freebsd.org);
+
+# TODO: this has to be set on a per-host basis.
+# It should probably come from $ho?
+our @disk_names = qw(ada0 da0 ad0);
+
+sub install () {
+    my $authkeys= authorized_keys();
+    my $disk = "";
+    my $nic = "";
+    my $ftp = "";
+
+    power_state($ho, 0);
+
+    setup_pxeboot_firstboot();
+
+    logm('Booting into mfsBSD');
+
+    sleep(power_cycle_time($ho));
+
+    power_state($ho, 1);
+
+    logm('Waiting for host to boot');
+    await_tcp(get_timeout($ho,'boot',$timeout{Sshd}), 22, $ho);
+
+    logm('Setting host to boot from local disk on next boot');
+    setup_pxeboot_local($ho);
+
+    logm('Switching root shell to /bin/sh');
+    target_cmd_root_with_password($ho, 'chsh -s /bin/sh', 900, "root");
+
+    logm('Setting up ssh keys for remote access');
+    target_cmd_root_with_password($ho, <<END, 900, "root");
+        set -e
+        mkdir -p ~/.ssh
+        cat <<ENDKEYS >~/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+END
+
+    foreach my $test_disk (@disk_names) {
+        logm("Probing for $test_disk existence");
+        my $output = target_cmd_output_root($ho,
+            'test -c /dev/'.$test_disk.' >/dev/null 2>&1 && echo "yes" || echo "no"',
+            200);
+        if ($output eq "yes") {
+            logm("Found a valid disk device: $test_disk");
+            $disk = $test_disk;
+            last;
+        }
+    }
+    length($disk) or die "Unable to find a valid disk, exiting";
+
+    logm("Searching for a mirror");
+    foreach my $test_ftp (@ftp_hosts) {
+        logm("Probing mirror $test_ftp");
+        # Test from the target system.
+        my $output = target_cmd_output_root($ho,
+            'nc -zw 10 '.$test_ftp.' 21 >/dev/null 2>&1 && echo "yes" || echo "no"',
+            200);
+        if ($output eq "yes") {
+            logm("Found a valid mirror: $test_ftp");
+            $ftp = $test_ftp;
+            last;
+        }
+    }
+    length($ftp) or die "Unable to find a valid ftp mirror, exiting";
+
+    logm('Install of base system using ZFS on root');
+    target_cmd_root($ho, <<END,2400);
+            set -e
+            gpart destroy -F $disk
+            zfsinstall -d $disk -u ftp://$ftp/pub/FreeBSD/releases/$r{arch}/$version -s 4g
+END
+
+    logm('Setting up ssh and keys for the installed system');
+    target_cmd_root($ho, <<END, 900);
+            set -e
+            echo 'sshd_enable="YES"' >> /mnt/etc/rc.conf
+            echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config
+            mkdir -p /mnt/root/.ssh
+            cat <<ENDKEYS >/mnt/root/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+END
+
+    logm('Setting up serial console');
+    target_cmd_root($ho, <<END, 900);
+            set -e
+            printf "%s" "-Dh" >> /mnt/boot.config
+            cat <<ENDB >>/mnt/boot/loader.conf
+boot_multicons="YES"
+boot_serial="YES"
+comconsole_speed="$c{Baud}"
+console="comconsole,vidconsole"
+boot_verbose="YES"
+ENDB
+END
+
+    logm("Trying to figure out primary nic device name");
+    $nic = target_cmd_output_root($ho,
+            'ifconfig | grep -B3 '.$ho->{Ip}.' | head -n1 | awk \'{print $1}\'|sed s/://',
+            200);
+    length($nic) or die "Unable to find primary network interface";
+
+    logm("Using $nic as primary nic interface");
+
+    logm('Setting up network');
+    target_cmd_root($ho, <<END, 900);
+            set -e
+            echo "net.link.bridge.inherit_mac=1" >> /mnt/boot/loader.conf
+            echo 'cloned_interfaces="bridge0"' >> /mnt/etc/rc.conf
+            echo 'ifconfig_bridge0="addm $nic SYNCDHCP"' >> /mnt/etc/rc.conf
+            echo 'ifconfig_$nic="up"' >> /mnt/etc/rc.conf
+END
+
+    logm('Setting up miscellaneous settings');
+    target_cmd_root($ho, <<END, 900);
+            set -e
+            cp /mnt/usr/share/zoneinfo/Europe/London /mnt/etc/localtime
+            echo 'sendmail_enable="NONE"' >> /mnt/etc/rc.conf
+END
+
+    logm('Copying installer keys into the system');
+    target_cmd_root($ho, 'cp /etc/ssh/*_key* /mnt/etc/ssh/', 900);
+
+    logm('Rebooting into the installed system');
+    target_reboot($ho);
+
+    logm('Setting root shell to /bin/sh');
+    target_cmd_root($ho, 'chsh -s /bin/sh', 900);
+    logm('Adding osstest user');
+    target_cmd_root($ho, 'pw useradd osstest -m', 900);
+    target_cmd_root($ho, <<END, 900);
+            set -e
+            chsh -s /bin/sh osstest
+            mkdir -p /home/osstest/.ssh
+            cat <<ENDKEYS >/home/osstest/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+END
+
+    logm('OK: install completed');
+}
+
+sub setup_pxeboot_firstboot() {
+    my $mfs= 'freebsd/'.$version.'/'.$r{arch}.'/'.'mfsbsd-'.$version.'-'.$r{arch}.'.img';
+
+    logm('Using mfsBSD image: ' . $mfs);
+
+    setup_pxeboot($ho, <<END);
+serial 0 $c{Baud}
+timeout 5
+label overwrite
+	menu label ^Overwrite
+	menu default
+	kernel memdisk
+	append initrd=$mfs
+default overwrite
+END
+}
+
+install();
Signature · 7 lines
1.7.7.5 (Apple Git-26)


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

PATCH v2 3/5 osstest: prepare FreeBSD host for Xen build

In reply to Roger Pau Monne

Install pkg (the binary package management tool) and the dependencies needed to build Xen.

---
Changes since RFC:
- Add the tools necessary in order to build the man pages and markdown documents.

---
 ts-xen-build-prep-freebsd |   48 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
 create mode 100755 ts-xen-build-prep-freebsd
ts-xen-build-prep-freebsd new file +48 -0
new file mode 100755
index 0000000..7a15b03
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2014 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/>.
+
+use strict qw(vars);
+use DBI;
+use POSIX;
+
+use Osstest;
+use Osstest::TestSupport;
+use Osstest::Logtailer;
+
+tsreadconfig();
+
+our ($whhost) = @ARGV;
+$whhost ||= 'host';
+our $ho= selecthost($whhost);
+exit 0 if $ho->{SharedReady};
+
+#TODO: should be a runvar
+our $compiler = 'gcc47';
+our $deps = "mercurial git bash python bcc glib pkgconf yajl gmake pixman ".
+            "perl5 markdown bison gettext gawk $compiler";
+
+sub install_depends () {
+    logm('Installing Xen build dependencies');
+    target_cmd_root($ho, <<END, 2400);
+        set -e
+        export ASSUME_ALWAYS_YES="YES"
+        pkg install -y $deps
+        ln -s /usr/local/bin/$compiler /usr/local/bin/gcc
+END
+}
+
+install_depends();
Signature · 7 lines
1.7.7.5 (Apple Git-26)


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

PATCH v2 4/5 osstest: create a new job called build-<arch>-freebsd

In reply to Roger Pau Monne

This job is very similar to build-<arch> but it doesn't enable ovmf because it doesn't compile on FreeBSD yet.

---
 mfi-common |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
mfi-common +14 -0
index afb6239..174cecd 100644
@@ -154,6 +154,20 @@ create_build_jobs () {
                 revision_qemuu=$REVISION_QEMU_UPSTREAM                       \
                 revision_seabios=$REVISION_SEABIOS
 
+    ./cs-job-create $flight build-$arch-freebsd build                        \
+                arch=$arch enable_xend=false enable_ovmf=false               \
+        tree_qemu=$TREE_QEMU                                                 \
+        tree_qemuu=$TREE_QEMU_UPSTREAM                                       \
+        tree_xen=$TREE_XEN                                                   \
+        tree_seabios=$TREE_SEABIOS                                           \
+                $RUNVARS $BUILD_RUNVARS $BUILD_XEN_RUNVARS $arch_runvars     \
+                $suite_runvars                                               \
+                host_hostflags=$build_hostflags                              \
+                revision_xen=$REVISION_XEN                                   \
+                revision_qemu=$REVISION_QEMU                                 \
+                revision_qemuu=$REVISION_QEMU_UPSTREAM                       \
+                revision_seabios=$REVISION_SEABIOS
+
     if [ $build_extraxend = "true" ] ; then
     ./cs-job-create $flight build-$arch-xend build                           \
                 arch=$arch enable_xend=true enable_ovmf=$enable_ovmf         \
Signature · 7 lines
1.7.7.5 (Apple Git-26)


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

PATCH v2 5/5 osstest: make ts-xen-build work on FreeBSD

In reply to Roger Pau Monne

This patch contains a new subroutine that guesses the right make command to use (gmake on BSDs, make otherwise).

---
 ts-xen-build |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
ts-xen-build +12 -1
index 661f186..d800396 100755
@@ -28,6 +28,16 @@ selectbuildhost(\@ARGV);
 # remaining arguments are passed as targets to "make"
 builddirsprops();
     
+sub get_make_cmd() {
+    my $uname = target_cmd_output_root($ho, 'uname -a', 200);
+
+    if ($uname =~ m/BSD/) {
+        return "gmake";
+    } else {
+        return "make";
+    }
+}
+
 sub checkout () {
     prepbuilddirs();
 
@@ -91,6 +101,7 @@ END
 }
 
 sub build () {
+    my $make_cmd = get_make_cmd();
     my $xend_opt= $r{enable_xend} =~ m/true/ ? "--enable-xend" : "--disable-xend";
     my $ovmf_opt= $r{enable_ovmf} =~ m/true/ ? "--enable-ovmf" : "--disable-ovmf";
 
@@ -112,7 +123,7 @@ END
 END
 #/;
     buildcmd_stamped_logged(9000, 'build', '',<<END,'');
-            $make_prefix make $makeflags @ARGV
+            $make_prefix $make_cmd $makeflags @ARGV
 END
 }
 
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#6 lore raw
In reply to Roger Pau Monne

El 14/08/14 a les 16.08, Roger Pau Monne ha escrit:

Quoted 9 lines

This series add support for bootstrapping a bare metal FreeBSD install using OSS Test and compiling Xen on it.

The first patch adds support for executing commands on remote boxes using ssh with password, which is needed in order to login into the installer. The rest of the patches focus on installing FreeBSD, the Xen build dependencies, and finally compiling the Xen kernel and tools.

Quoted 5 lines

I've been manually running the tests using the following runes:

OSSTEST_FLIGHT=standalone OSSTEST_JOB=build-amd64-freebsd OSSTEST_HOST=kodo4 ./ts-freebsd-host-install host=kodo4 OSSTEST_FLIGHT=standalone OSSTEST_JOB=build-amd64-freebsd OSSTEST_HOST=kodo4 ./ts-xen-build-prep-freebsd host=kodo4 OSSTEST_FLIGHT=standalone OSSTEST_JOB=build-amd64-freebsd OSSTEST_HOST=kodo4 ./ts-xen-build host=kodo4

Hello,

It's been some time since I've posted those patches, but got no feedback so far. Should I repost them?

Thanks, Roger.