line |
stmt |
code |
1
|
|
# Copyright 2009-2013 Bernhard M. Wiedemann |
2
|
|
# Copyright 2012-2015 SUSE LLC |
3
|
|
# SPDX-License-Identifier: GPL-2.0-or-later |
4
|
|
|
5
|
|
|
6
|
|
use Mojo::Base 'consoles::localXvnc', -signatures; |
7
|
3
|
use autodie ':all'; |
|
3
|
|
|
3
|
|
8
|
3
|
use IO::Socket::INET; |
|
3
|
|
|
3
|
|
9
|
3
|
require IPC::System::Simple; |
|
3
|
|
|
3
|
|
10
|
|
|
11
|
|
# start Xvnc |
12
|
0
|
$self->SUPER::activate; |
|
0
|
|
|
0
|
|
13
|
|
|
14
|
0
|
my $testapi_console = $self->{testapi_console}; |
15
|
|
my $ssh_args = $self->{args}; |
16
|
0
|
my $gui = $self->{args}->{gui}; |
17
|
0
|
|
18
|
0
|
my $hostname = $ssh_args->{hostname} || die('we need a hostname to ssh to'); |
19
|
|
my $password = $ssh_args->{password} || $testapi::password; |
20
|
0
|
my $username = $ssh_args->{username} || 'root'; |
21
|
0
|
my $sshcommand = $self->sshCommand($username, $hostname, $gui); |
22
|
0
|
my $serial = $self->{args}->{serial}; |
23
|
0
|
|
24
|
0
|
# Wait that ssh server on SUT is live on network |
25
|
|
if (!$self->wait_for_ssh_port($hostname, timeout => ($bmwqemu::vars{SSH_XTERM_WAIT_SUT_ALIVE_TIMEOUT} // 120))) { |
26
|
|
bmwqemu::diag("$hostname does not seems to have an active SSH server. Continuing anyway."); |
27
|
0
|
} |
28
|
0
|
$self->callxterm($sshcommand, "ssh:$testapi_console"); |
29
|
|
|
30
|
0
|
if ($serial) { |
31
|
|
|
32
|
0
|
# ssh connection to SUT for iucvconn |
33
|
|
my ($ssh, $serialchan) = $self->backend->start_ssh_serial( |
34
|
|
hostname => $hostname, |
35
|
0
|
password => $password, |
36
|
|
username => 'root' |
37
|
|
); |
38
|
|
|
39
|
|
# start iucvconn |
40
|
|
bmwqemu::diag('ssh xterm vt: grabbing serial console'); |
41
|
|
$ssh->blocking(1); |
42
|
0
|
if (!$serialchan->exec($serial)) { |
43
|
0
|
bmwqemu::fctwarn('ssh xterm vt: unable to grab serial console at this point: ' . ($ssh->error // 'unknown SSH error')); |
44
|
0
|
} |
45
|
0
|
$ssh->blocking(0); |
46
|
|
} |
47
|
0
|
} |
48
|
|
|
49
|
|
$args{timeout} //= 120; |
50
|
|
$args{port} //= 22; |
51
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
52
|
0
|
bmwqemu::diag("Wait for SSH on host $hostname (timeout: $args{timeout})"); |
53
|
0
|
|
54
|
|
$args{timeout} = 1 unless $args{timeout} > 0; |
55
|
0
|
my $endtime = time() + $args{timeout}; |
56
|
|
while (time() < $endtime) { |
57
|
0
|
my $sock = IO::Socket::INET->new(PeerAddr => $hostname, PeerPort => $args{port}, Proto => 'tcp', Timeout => 1); |
58
|
0
|
return 1 if defined $sock; |
59
|
0
|
sleep 1; |
60
|
0
|
} |
61
|
0
|
return 0; |
62
|
0
|
} |
63
|
|
|
64
|
0
|
# to be called on reconnect |
65
|
|
$self->backend->stop_ssh_serial; |
66
|
|
} |
67
|
|
|
68
|
0
|
1; |
|
0
|
|
|
0
|
|