1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# Copyright © 2009-2013 Bernhard M. Wiedemann
# Copyright © 2012-2016 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
package backend::svirt;
use strict;
use base ('backend::virt');
use testapi qw(get_required_var check_var);
use IO::Select;
# this is a fake backend to some extend. We don't start VMs, but provide ssh access
# to a libvirt running host (KVM for System Z in mind)
use testapi qw/get_var check_var/;
sub new {
my $class = shift;
my $self = $class->SUPER::new;
get_required_var('WORKER_HOSTNAME');
return $self;
}
# we don't do anything actually
sub do_start_vm {
my ($self) = @_;
# truncate the serial file
open(my $sf, '>', $self->{serialfile});
close($sf);
my $ssh = $testapi::distri->add_console(
'svirt',
'ssh-virtsh',
{
hostname => get_required_var('VIRSH_HOSTNAME'),
password => get_var('VIRSH_PASSWORD'),
});
$ssh->backend($self);
$self->select_console({testapi_console => 'svirt'});
# remove backend.crashed
$self->unlink_crash_file;
return {};
}
sub do_stop_vm {
my ($self) = @_;
$self->stop_serial_grab;
return {};
}
# Open another ssh connection to grab the serial console.
sub start_serial_grab {
my ($self, $name) = @_;
my $chan = $self->start_ssh_serial(hostname => get_required_var('VIRSH_HOSTNAME'), password => get_var('VIRSH_PASSWORD'), username => 'root');
if (check_var('VIRSH_VMM_FAMILY', 'vmware')) {
# libvirt esx driver does not support `virsh console', so
# we have to connect to VM's serial port via TCP which is
# provided by ESXi server.
$chan->exec('nc ' . get_var('VMWARE_SERVER') . ' ' . get_var('VMWARE_SERIAL_PORT'));
}
elsif (check_var('VIRSH_VMM_FAMILY', 'hyperv')) {
# Hyper-V does not support serial console export via TCP, just
# windows named pipes (e.g. \\.\pipe\mypipe). Such a named pipe
# has to be enabled by a namedpipe-to-TCP on HYPERV_SERVER application.
$chan->exec('nc ' . get_var('HYPERV_SERVER') . ' ' . get_var('HYPERV_SERIAL_PORT'));
}
else {
$chan->exec('virsh console ' . $name);
}
}
sub check_socket {
my ($self, $fh, $write) = @_;
if ($self->check_ssh_serial($fh)) {
return 1;
}
return $self->SUPER::check_socket($fh, $write);
}
sub stop_serial_grab {
my ($self) = @_;
$self->stop_ssh_serial;
return;
}
1;
# vim: set sw=4 et:
|