File Coverage

consoles/sshSerial.pm
Criterion Covered Total %
statement 46 46 100.0
total 46 46 100.0


line stmt code
1   # Copyright 2020 SUSE LLC
2   # SPDX-License-Identifier: GPL-2.0-or-later
3   #
4   #
5   # Simple serial terminal over SSH
6    
7    
8   use Mojo::Base 'consoles::console', -signatures;
9 1 use consoles::ssh_screen;
  1  
  1  
10 1  
  1  
  1  
11   return $class->SUPER::new($testapi_console, $args);
12 2 }
  2  
  2  
  2  
  2  
13 2  
14    
15   return unless $self->{ssh};
16 2 bmwqemu::diag("Closing SSH connection with " . $self->{ssh}->hostname);
  2  
  2  
  2  
17   $self->{ssh}->disconnect;
18 1 $self->{ssh} = $self->{screen} = undef;
  1  
  1  
19 1 return;
20 1 }
21 1  
22 1 my $hostname = $self->{args}->{hostname} || die('we need a hostname to ssh to');
23 1 my $password = $self->{args}->{password} // $testapi::password;
24   my $username = $self->{args}->{username} // 'root';
25   my $pty_cols = $self->{args}->{pty_cols} // 2048;
26 2 my $port = $self->{args}->{port} // 22;
  2  
  2  
27 2  
28 2 bmwqemu::diag("Connecting SSH serial console for $username\@$hostname port $port");
29 2  
30 2 my $ssh = $self->backend->new_ssh_connection(
31 2 hostname => $hostname,
32   password => $password,
33 2 username => $username,
34   port => $port,
35 2 );
36   my $chan = $ssh->channel()
37   or $ssh->die_with_error('Cannot open SSH channel');
38    
39    
40   # Enable echo, no ANSI color codes, $pty_cols character line width
41 2 # (Sending commands longer than line width will break read-back check)
42   $chan->pty('dumb', {echo => 1}, $pty_cols)
43   or $ssh->die_with_error('PTY request failed');
44   $chan->ext_data('merge');
45   $chan->shell or $ssh->die_with_error('Failed to start remote shell');
46   $chan->blocking(0);
47 2  
48   $self->{screen} = consoles::ssh_screen->new(
49 2 ssh_connection => $ssh,
50 2 ssh_channel => $chan,
51 2 logfile => $self->{args}->{logfile} // "serial_terminal.txt"
52   );
53   $self->{ssh} = $ssh;
54   return;
55   }
56 2  
57    
58 2 1;