From: Ian Campbell Subject: [PATCH OSSTEST v4 05/25] Debian: refactor preseeding of .ssh directories Date: Thu, 2 Apr 2015 10:16:19 +0100 Message-ID: <1427966199-5064-5-git-send-email-ian.campbell@citrix.com> References: <1427966183.4037.17.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1427966183.4037.17.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: longtaox.pang@intel.com, 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 Cc: longtaox.pang@intel.com --- 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 ef602b1..db89326 100644 --- a/Osstest/Debian.pm +++ b/Osstest/Debian.pm @@ -37,6 +37,7 @@ BEGIN { %preseed_cmds preseed_base preseed_create + preseed_ssh preseed_hook_command preseed_hook_installscript preseed_hook_cmds di_installcmdline_core ); @@ -551,6 +552,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, <{Tftp}{Path}.'/'.$ho->{Tftp}{DiBase}.'/'.$r{arch}.'/'. $c{TftpDiVersion}.'-'.$ho->{Suite}; - 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); - my $overlays= ''; my $create_overlay= sub { my ($srcdir, $tfilename) = @_; @@ -740,6 +764,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 95fce9a..02c142b 100755 --- a/ts-debian-hvm-install +++ b/ts-debian-hvm-install @@ -44,7 +44,6 @@ our $gho; sub preseed () { my $preseed_file = preseed_base($gho,'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.4