All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org, Ian.Jackson@eu.citrix.com
Cc: Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 2/7] osstest: move known_hosts generation to TestSupport
Date: Tue, 23 May 2017 14:51:43 +0100	[thread overview]
Message-ID: <20170523135148.77673-3-roger.pau@citrix.com> (raw)
In-Reply-To: <20170523135148.77673-1-roger.pau@citrix.com>

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é <roger.pau@citrix.com>
---
 Osstest/Debian.pm      | 36 +-----------------------------------
 Osstest/TestSupport.pm | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm
index 8ba48bfa..87539822 100644
--- a/Osstest/Debian.pm
+++ b/Osstest/Debian.pm
@@ -709,41 +709,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(<<END);
-        SELECT val FROM runvars
-         WHERE flight=? AND name LIKE '%host'
-         GROUP BY val
-END
-    $hostsq->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, <<END);
 #!/bin/sh
diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index 5f13eb0b..8c7078c5 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -89,7 +89,7 @@ BEGIN {
                       store_revision store_vcs_revision
                       git_massage_url
 
-                      sshopts authorized_keys
+                      sshopts authorized_keys known_hosts
                       cfg_tftp_di_version
                       remote_perl_script_open remote_perl_script_done
                       host_reboot target_reboot target_reboot_hard            
@@ -2356,6 +2356,45 @@ sub authorized_keys () {
     return $authkeys;
 }
 
+sub known_hosts () {
+    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(<<END);
+        SELECT val FROM runvars
+         WHERE flight=? AND name LIKE '%host'
+         GROUP BY val
+END
+    $hostsq->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{...}
-- 
2.11.0 (Apple Git-81)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-05-23 13:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-23 13:51 [PATCH 0/7] osstest: initial FreeBSD support Roger Pau Monne
2017-05-23 13:51 ` [PATCH 1/7] osstest: make built_stash_file store a path_ runvar for each file Roger Pau Monne
2017-05-23 14:55   ` Ian Jackson
2017-05-23 13:51 ` Roger Pau Monne [this message]
2017-05-23 14:56   ` [PATCH 2/7] osstest: move known_hosts generation to TestSupport Ian Jackson
2017-05-23 13:51 ` [PATCH 3/7] osstest: fix regular expression used to match buildjob in ts-build-check Roger Pau Monne
2017-05-23 15:01   ` Ian Jackson
2017-05-24  7:18     ` Roger Pau Monne
2017-05-23 13:51 ` [PATCH 4/7] osstest: add a FreeBSD host install recipe Roger Pau Monne
2017-05-23 16:04   ` Ian Jackson
2017-05-24 10:48     ` Roger Pau Monne
2017-05-24 11:12       ` Ian Jackson
2017-05-23 17:14   ` Ian Jackson
2017-05-23 13:51 ` [PATCH 5/7] osstest: introduce a FreeBSD build script Roger Pau Monne
2017-05-23 17:58   ` Ian Jackson
2017-05-24 14:15     ` Roger Pau Monne
2017-05-24 14:19       ` Ian Jackson
2017-05-23 13:51 ` [PATCH 6/7] osstest: add a FreeBSD build to flights Roger Pau Monne
2017-05-23 13:51 ` [PATCH 7/7] osstest: introduce make-freebsd-flight Roger Pau Monne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170523135148.77673-3-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.