Skip to contentSkip to conversation

known_hosts handling: Fix over-broad SQL query

PATCH New Ian Jackson 1 participant 3 messages Oct 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 known_hosts handling: Fix over-broad SQL query

This should match only "*_host" and "host". We don't want it matching "*host" without a "_".

---
 Osstest/TestSupport.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest/TestSupport.pm +1 -1
index f2d8a0e1..5e6b15d9 100644
@@ -2796,7 +2796,7 @@ sub known_hosts () {
 
     my $hostsq= $dbh_tests->prepare(<<END);
         SELECT val FROM runvars
-         WHERE flight=? AND name LIKE '%host'
+         WHERE flight=? AND (name = 'host' OR name LIKE '%\\_host')
          GROUP BY val
 END
     $hostsq->execute($flight);
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/3 known hosts handling: Ensure things are good for multi-host jobs

When a multi-host job reuses host(s) from earlier jobs, the set of hosts set up in the on-host known_hosts files may be insufficient, since the hosts we are using now may not have been in any of the flight's runvars when the earlier job set them up.

So we need to update the known_hosts. We use the flight's current set, which will include all of our hosts.

---
 ts-host-reuse | 9 +++++++++
 1 file changed, 9 insertions(+)
ts-host-reuse +9 -0
index 8d674257..ea8a471d 100755
@@ -135,6 +135,14 @@ sub noop_if_playing () {
     }
 }
 
+sub ensure_known_hosts ($) {
+    my ($ho) = @_;
+    # Don't need to bother if job uses only one host
+    return if scalar(grep { m/(_|^)host$/ } keys %r) == 1;
+    target_putfilecontents_root_stash($ho, 30, known_hosts(),
+				      '/root/.ssh/known_hosts');
+}
+
 #---------- actions ----------
 
 sub act_prealloc () {
@@ -153,6 +161,7 @@ sub act_start_test () {
     return unless $ho->{Shared};
     my %oldstate = map { $_ => 1 } qw(prep ready);
     host_shared_mark_ready($ho, $sharetype, \%oldstate, 'mid-test');
+    ensure_known_hosts($ho);
 }
 
 sub act_final () {
Signature · 1 line
2.20.1
#2 lore raw

PATCH 3/3 Revert "host reuse: Reuse hosts only in same role (for now)"

In reply to Ian Jackson

This workaround is no longer needed because I have fixed the problem properly.

Also, it didn't work anyway, because at that point $ho isn't set, so all this did was produce some Perl warnings.

This reverts commit f3668acae2c6201c680dc7b4e9085ab184136d7e.

---
 ts-host-reuse | 1 -
 1 file changed, 1 deletion(-)
ts-host-reuse +0 -1
index ea8a471d..e2498bb6 100755
@@ -67,7 +67,6 @@ sub sharetype_add ($$) {
 sub compute_test_sharetype () {
     my @runvartexts;
     my %done;
-    push @runvartexts, $ho->{Ident};
     foreach my $key (runvar_glob(@accessible_runvar_pats)) {
 	next if runvar_is_synth($key);
 	my $val = $r{$key};
Signature · 1 line
2.20.1