diff mbox

[Xen-devel,OSSTEST,v2,08/15] Debian: add preseed_create_guest helper

Message ID 1398681696-2773-8-git-send-email-ian.campbell@citrix.com
State New
Headers show

Commit Message

Ian Campbell April 28, 2014, 10:41 a.m. UTC
Creates a preseed file suitable for use in a PV guest

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 Osstest/Debian.pm | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

Comments

Ian Jackson May 2, 2014, 11:33 a.m. UTC | #1
Ian Campbell writes ("[PATCH OSSTEST v2 08/15] Debian: add preseed_create_guest helper"):
> Creates a preseed file suitable for use in a PV guest
...
> +    my $authkeys= authorized_keys();
> +
> +    my $hostkeyfile= "$c{OverlayLocal}/etc/ssh/ssh_host_rsa_key";
> +    my $host_rsa_key= get_filecontents($hostkeyfile);
> +    chomp($host_rsa_key); $host_rsa_key.="\n";

Osstest::Debian::preseed_create already has machinery for doing this
(in a slightly different way).  Can you use it ?  (It would
presumably need breaking out.)

I see ts-debian-hvm-install has a yet-different way of doing this,
which I didn't spot.

Ian.
Ian Campbell May 2, 2014, 12:23 p.m. UTC | #2
On Fri, 2014-05-02 at 12:33 +0100, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH OSSTEST v2 08/15] Debian: add preseed_create_guest helper"):
> > Creates a preseed file suitable for use in a PV guest
> ...
> > +    my $authkeys= authorized_keys();
> > +
> > +    my $hostkeyfile= "$c{OverlayLocal}/etc/ssh/ssh_host_rsa_key";
> > +    my $host_rsa_key= get_filecontents($hostkeyfile);
> > +    chomp($host_rsa_key); $host_rsa_key.="\n";
> 
> Osstest::Debian::preseed_create already has machinery for doing this
> (in a slightly different way).  Can you use it ?  (It would
> presumably need breaking out.)

There was something which didn't fit between host and guest usage that I
couldn't figure out, but it was a long time ago and I don't remember.
Let me try again and I'll either succeed or find the problem again.

> I see ts-debian-hvm-install has a yet-different way of doing this,
> which I didn't spot.

I'll see what I can do about this while I'm there.

Ian.
diff mbox

Patch

diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm
index ab09abb..043ab0d 100644
--- a/Osstest/Debian.pm
+++ b/Osstest/Debian.pm
@@ -35,6 +35,7 @@  BEGIN {
                       %preseed_cmds
                       preseed_base
                       preseed_create
+                      preseed_create_guest
                       preseed_hook_command preseed_hook_installscript
                       di_installcmdline_core
                       );
@@ -429,6 +430,8 @@  sub di_installcmdline_core ($$;@) {
 sub preseed_base ($$;@) {
     my ($suite,$extra_packages,%xopts) = @_;
 
+    $extra_packages ||= '';
+
     return <<"END";
 d-i mirror/suite string $suite
 
@@ -498,7 +501,66 @@  $xopts{ExtraPreseed}
 ### END OF DEBIAN PRESEED BASE
 
 END
-}          
+}
+
+sub preseed_create_guest ($$;@) {
+    my ($ho, $sfx, %xopts) = @_;
+
+    my $suite= $xopts{Suite} || $c{DebianSuite};
+
+    my $extra_packages;
+
+    my $preseed_file= preseed_base($suite, $extra_packages, %xopts);
+    $preseed_file.= (<<END);
+d-i     partman-auto/method             string regular
+d-i     partman-auto/choose_recipe \\
+                select All files in one partition (recommended for new users)
+
+d-i     grub-installer/bootdev          string /dev/xvda
+
+END
+
+    my $authkeys= authorized_keys();
+
+    my $hostkeyfile= "$c{OverlayLocal}/etc/ssh/ssh_host_rsa_key";
+    my $host_rsa_key= get_filecontents($hostkeyfile);
+    chomp($host_rsa_key); $host_rsa_key.="\n";
+
+    preseed_hook_command($ho, 'late_command', $sfx, <<END);
+#!/bin/sh
+set -ex
+
+r=/target/root
+cd \$r
+
+umask 022
+mkdir .ssh
+cat <<'ENDKEYS' >.ssh/authorized_keys
+$authkeys
+ENDKEYS
+
+u=osstest
+h=/home/\$u
+mkdir /target\$h/.ssh
+cp .ssh/authorized_keys /target\$h/.ssh
+chroot /target chown -R \$u.\$u \$h/.ssh
+
+rm -f /target/etc/ssh/ssh_host_*_key
+rm -f /target/etc/ssh/ssh_host_*_key.pub
+
+cat <<'ENDKEYS' > /target/etc/ssh/ssh_host_rsa_key
+$host_rsa_key
+ENDKEYS
+chmod 0600 /target/etc/ssh/ssh_host_rsa_key
+END
+
+    foreach my $di_key (keys %preseed_cmds) {
+        $preseed_file .= "d-i preseed/$di_key string ".
+            (join ' && ', @{ $preseed_cmds{$di_key} }). "\n";
+    }
+
+    return create_webfile($ho, "preseed$sfx", $preseed_file);
+}
 
 sub preseed_create ($$;@) {
     my ($ho, $sfx, %xopts) = @_;