Skip to content

Commit

Permalink
baseclass: Explicitly log retry interval for SSH console
Browse files Browse the repository at this point in the history
The machine may take time to come up. Let's make the retry
behavior more explicit.

See: https://progress.opensuse.org/issues/162272
  • Loading branch information
kalikiana committed Jun 26, 2024
1 parent b55275c commit 1e7e106
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions backend/baseclass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions t/23-baseclass.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};
};

Expand Down

0 comments on commit 1e7e106

Please sign in to comment.