Skip to content

Commit

Permalink
Set ssh serial console alive and check kvm modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Julie-CAO committed Apr 3, 2023
1 parent e1214f9 commit 8451a22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/Utils/Backends.pm
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,15 @@ sub is_generalhw { check_var('BACKEND', 'generalhw'); }
sub set_ssh_console_timeout {
my ($sshd_config_file, $sshd_timeout) = @_;
my $client_count_max = $sshd_timeout / 60;
script_run("sed -irnE 's/^.*TCPKeepAlive.*\$/TCPKeepAlive yes/g; s/^.*ClientAliveInterval.*\$/ClientAliveInterval 60/g; s/^.*ClientAliveCountMax.*\$/ClientAliveCountMax $client_count_max/g' $sshd_config_file");
script_run("service sshd restart") if (script_run("systemctl restart sshd") ne '0');
if (script_run("ls $sshd_config_file") == 0) {
script_run("sed -irnE 's/^.*TCPKeepAlive.*\$/TCPKeepAlive yes/g; s/^.*ClientAliveInterval.*\$/ClientAliveInterval 60/g; s/^.*ClientAliveCountMax.*\$/ClientAliveCountMax $client_count_max/g' $sshd_config_file");
script_run("grep -i Alive $sshd_config_file");
script_run("service sshd restart") if (script_run("systemctl restart sshd") ne '0');
record_info("Keep ssh connection alive for long-time run test!");
}
else {
record_info("Fail to set ssh session alive for long-time run test", "Unable to find $sshd_config_file", result => 'softfail');
}
}

=head2 is_ssh_installation
Expand Down
20 changes: 16 additions & 4 deletions tests/virt_autotest/login_console.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use testapi;
use Utils::Architectures;
use Utils::Backends qw(use_ssh_serial_console is_remote_backend set_ssh_console_timeout);
use ipmi_backend_utils;
use virt_autotest::utils qw(is_xen_host check_port_state check_host_health);
use virt_autotest::utils qw(is_xen_host is_kvm_host check_port_state check_host_health);
use IPC::Run;

sub set_ssh_console_timeout_before_use {
reset_consoles;
select_console('root-console');
set_ssh_console_timeout('/etc/ssh/sshd_config', '28800');
reset_consoles;
select_console 'sol', await_console => 1;
select_console 'sol', await_console => 0;
send_key 'ret';
check_screen([qw(linux-login virttest-displaymanager)], 60);
save_screenshot;
Expand All @@ -49,6 +49,16 @@ sub double_check_xen_role {
save_screenshot;
}

sub check_kvm_modules {
if (script_run('lsmod | grep "^kvm\b"') == 0 and script_run('lsmod | grep -e "^kvm_intel\b" -e "^kvm_amd\b"') == 0) {
save_screenshot;
record_info("KVM", "kvm and kvm_intel/amd modules are loaded");
}
else {
die "KVM modules are not loaded!";
}
}

#Explanation for parameters introduced to facilitate offline host upgrade:
#OFFLINE_UPGRADE indicates whether host upgrade is offline which needs reboot
#the host and upgrade from installation media. Please refer to this document:
Expand Down Expand Up @@ -191,12 +201,14 @@ sub login_to_console {
send_key 'ret';
}

# Set ssh console timeout for thunderx machine
set_ssh_console_timeout_before_use if (is_remote_backend && is_aarch64 && get_var('IPMI_HW') eq 'thunderx');
# Set ssh console timeout for virt tests on ipmi backend machines
# it will make ssh serial console alive even with long time command
set_ssh_console_timeout_before_use if (is_remote_backend and is_x86_64 and get_var('VIRT_AUTOTEST', ''));
# use console based on ssh to avoid unstable ipmi
use_ssh_serial_console;
# double-check xen role for xen host
double_check_xen_role if (is_xen_host and !get_var('REBOOT_AFTER_UPGRADE'));
check_kvm_modules if is_x86_64 and is_kvm_host and !get_var('REBOOT_AFTER_UPGRADE');
}

sub run {
Expand Down

0 comments on commit 8451a22

Please sign in to comment.