From: Ian Campbell Subject: [PATCH OSSTEST v3 07/19] Debian: refactor preseeding of .ssh directories Date: Mon, 1 Dec 2014 12:57:24 +0000 Message-ID: <1417438656-15451-7-git-send-email-ian.campbell@citrix.com> References: <1417438571.29138.22.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1417438571.29138.22.camel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: ian.jackson@eu.citrix.com Cc: Ian Campbell , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org Causes known_hosts to be consistently created as well as ~osstest/.ssh to be consistently populated (it previsouly wasn't for HVM guests). Signed-off-by: Ian Campbell --- v3: New patch --- Osstest/Debian.pm | 99 +++++++++++++++++++++++++++++---------------------- ts-debian-hvm-install | 5 ++- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm index d1adb02..bdbe2f3 100644 --- a/Osstest/Debian.pm +++ b/Osstest/Debian.pm @@ -35,6 +35,7 @@ BEGIN { %preseed_cmds preseed_base preseed_create + preseed_ssh preseed_hook_command preseed_hook_installscript preseed_hook_cmds di_installcmdline_core ); @@ -427,6 +428,60 @@ sub di_installcmdline_core ($$;@) { return @cl; } +sub preseed_ssh ($$) { + my ($ho,$sfx) = @_; + + my $authkeys_url= create_webfile($ho, "authkeys$sfx", authorized_keys()); + + my $hostkeyfile= "$c{OverlayLocal}/etc/ssh/ssh_host_rsa_key.pub"; + my $hostkey= get_filecontents($hostkeyfile); + chomp($hostkey); $hostkey.="\n"; + my $knownhosts= ''; + + my $hostsq= $dbh_tests->prepare(<execute($flight); + while (my ($node) = $hostsq->fetchrow_array()) { + my $longname= "$node.$c{TestHostDomain}"; + my (@hostent)= gethostbyname($longname); + if (!@hostent) { + logm("skipping host key for nonexistent host $longname"); + next; + } + my $specs= join ',', $longname, $node, map { + join '.', unpack 'W4', $_; + } @hostent[4..$#hostent]; + logm("adding host key for $specs"); + $knownhosts.= "$specs ".$hostkey; + } + $hostsq->finish(); + + $knownhosts.= "localhost,127.0.0.1 ".$hostkey; + my $knownhosts_url= create_webfile($ho, "known_hosts$sfx", $knownhosts); + + preseed_hook_command($ho, 'late_command', $sfx, <prepare(<execute($flight); - while (my ($node) = $hostsq->fetchrow_array()) { - my $longname= "$node.$c{TestHostDomain}"; - my (@hostent)= gethostbyname($longname); - if (!@hostent) { - logm("skipping host key for nonexistent host $longname"); - next; - } - my $specs= join ',', $longname, $node, map { - join '.', unpack 'W4', $_; - } @hostent[4..$#hostent]; - logm("adding host key for $specs"); - $knownhosts.= "$specs ".$hostkey; - } - $hostsq->finish(); - - $knownhosts.= "localhost,127.0.0.1 ".$hostkey; - my $knownhosts_url= create_webfile($ho, "known_hosts$sfx", $knownhosts); - my $overlays= ''; my $create_overlay= sub { my ($srcdir, $tfilename) = @_; @@ -602,6 +626,8 @@ ls -l /dev/sd* true END + preseed_ssh($ho, $sfx); + preseed_hook_command($ho, 'late_command', $sfx, <> /target/etc/lsb-base-logging.sh $overlays diff --git a/ts-debian-hvm-install b/ts-debian-hvm-install index 878083f..d2bb6f8 100755 --- a/ts-debian-hvm-install +++ b/ts-debian-hvm-install @@ -47,7 +47,6 @@ our $toolstack= toolstack()->{Command}; sub preseed () { my $preseed_file = preseed_base('wheezy','',()); - my $authkeys = join('\\n', split(/\n/, authorized_keys())); $preseed_file .= (< /root/.ssh/authorized_keys"; END + preseed_ssh($ho,''); + $preseed_file .= preseed_hook_cmds(); return $preseed_file; -- 2.1.1