From 1e7e106973d38bd81e43fef232794cb974a991da Mon Sep 17 00:00:00 2001 From: Liv Dywan Date: Fri, 21 Jun 2024 14:08:38 +0200 Subject: [PATCH] baseclass: Explicitly log retry interval for SSH console The machine may take time to come up. Let's make the retry behavior more explicit. See: https://progress.opensuse.org/issues/162272 --- backend/baseclass.pm | 7 ++++--- t/23-baseclass.t | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/baseclass.pm b/backend/baseclass.pm index d621f1e9173..e3d1c8abb70 100644 --- a/backend/baseclass.pm +++ b/backend/baseclass.pm @@ -1207,8 +1207,9 @@ sub new_ssh_connection ($self, %args) { # timeout requires libssh2 >= 1.2.9 so not all versions might have it my $ssh = Net::SSH2->new(timeout => ($bmwqemu::vars{SSH_COMMAND_TIMEOUT_S} // 5 * ONE_MINUTE) * 1000); - # Retry multiple times, in case of the guest is not running yet + # Retry multiple times in case the guest is not running yet my $counter = $bmwqemu::vars{SSH_CONNECT_RETRY} // 5; + my $interval = $bmwqemu::vars{SSH_CONNECT_RETRY_INTERVAL} // 10; my $con_pretty = "$args{username}\@$args{hostname}"; $con_pretty .= ":$args{port}" unless $args{port} == 22; while ($counter > 0) { @@ -1225,8 +1226,8 @@ sub new_ssh_connection ($self, %args) { last; } else { - bmwqemu::diag "Could not connect to $con_pretty, Retrying after some seconds..."; - sleep($bmwqemu::vars{SSH_CONNECT_RETRY_INTERVAL} // 10); + bmwqemu::diag "Could not connect to $con_pretty. Retrying up to $counter more times after sleeping ${interval}s"; + sleep($interval); $counter--; next; } diff --git a/t/23-baseclass.t b/t/23-baseclass.t index a6f6927bd90..140d96d0d5f 100755 --- a/t/23-baseclass.t +++ b/t/23-baseclass.t @@ -346,9 +346,9 @@ subtest 'SSH utilities' => sub { $mockbmw->redefine(diag => sub { $diag .= $_[0] }); $bmwqemu::vars{SSH_CONNECT_RETRY} = 2; $ssh_connect_error = 1; - $exp_log_new = qr/Could not connect to serial\@foo, Retrying/; + $exp_log_new = qr/Could not connect to serial\@foo. Retrying/; $baseclass->new_ssh_connection(keep_open => 0, hostname => 'foo', username => 'serial', password => 'XXX'); - like $diag, qr/Could not connect to serial\@foo, Retrying/, 'connection error logged'; + like $diag, qr/Could not connect to serial\@foo. Retrying/, 'connection error logged'; }; };