From: Roger Pau Monne Date: Wed, 13 Jun 2018 07:40:12 +0000 (+0200) Subject: osstest: move known_hosts generation to TestSupport X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=4c75a3346ec50cf7240b966f877e297d70cdb1a9;p=people%2Froyger%2Fosstest.git osstest: move known_hosts generation to TestSupport This is equivalent to the already existing authorized_keys function, and generates the contents of the known_hosts file that should be installed on targets. Signed-off-by: Roger Pau Monné Acked-by: Ian Jackson --- diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm index 2c1e6ed..4c98c2a 100644 --- a/Osstest/Debian.pm +++ b/Osstest/Debian.pm @@ -718,41 +718,7 @@ 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 $defaultfqdn = $node; - $defaultfqdn .= ".$c{TestHostDomain}" unless $defaultfqdn =~ m/\./; - - my %props; - $mhostdb->get_properties($node, \%props); - - my $longname= $props{Fqdn} // $defaultfqdn; - 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 $knownhosts_url= create_webfile($ho, "known_hosts$sfx", known_hosts()); preseed_hook_command($ho, 'late_command', $sfx, <prepare(<execute($flight); + while (my ($node) = $hostsq->fetchrow_array()) { + my $defaultfqdn = $node; + $defaultfqdn .= ".$c{TestHostDomain}" unless $defaultfqdn =~ m/\./; + + my %props; + $mhostdb->get_properties($node, \%props); + + my $longname= $props{Fqdn} // $defaultfqdn; + 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; + + return $knownhosts; +} + sub cfg_tftp_di_version ($) { my ($suite) = @_; $suite //= 'x def suite'; # will not find $c{...}