lib/sles4sap/console_redirection.pm

SYNOPSIS

Library that enables console redirection and file transfers from worker based VM to another host. Can be used for cases where worker VM is not the target host for API calls and command execution, but serves only as a jumphost. Console redirection is achieved by ssh remote port forwarding and redirecting remote VM ssh session stdin and stdout outputs into serial terminal of the worker VM.

USAGE: 1. Set mandatory OpenQA parameters (they can be as well provided directly as named arguments in functions): - REDIRECT_DESTINATION_USER: SSH user for remote SUT - REDIRECT_DESTINATION_IP: IP address for remote SUT 2. Establish console redirection to SUT host by calling function connect_target_to_serial - all test code is now transparently executed on SUT instead of worker VM - from OpenQA perspective SUT is the worker VM 3. Disable console redirection from SUT host by calling function disconnect_target_from_serial

handle_login_prompt

handle_login_prompt();

Detects if login prompt appears and types the password. In case of ssh keys being in place and command prompt appears, the function does not type anything.

set_serial_term_prompt

set_serial_term_prompt();

Set expected serial prompt according to user which is currently active. This changes global setting $testapi::distri->{serial_term_prompt} which is important for calls like wait_for_serial.

connect_target_to_serial

connect_target_to_serial( [, ssh_user=>ssh_user, destination_ip=>$destination_ip]);

ssh_user: SSH login user for destination_ip - default value is defined by OpenQA parameter REDIRECT_DESTINATION_USER

destination_ip: Destination host IP - default value is defined by OpenQA parameter REDIRECT_DESTINATION_IP

switch_root: Switch to root after login with unprivileged user with 'sudo su -'. User MUST have passwordless sudo permission.

fail_ok: Do not die, return 0 instead. Good for verifying if redirection works.

Establishes ssh connection to destination host and redirects serial output to serial console on worker VM. Connection activates remote port forwarding of OpenQA QEMUPORT+1. This allows running standard OpenQA modules directly on a remote host accessed from worker VM via SSH. Returns 1 if redirection was successful, or dies if redirection fails. If fail_ok is set to true, function does not fail, but returns 0.

disconnect_target_from_serial

disconnect_target_from_serial();

Disconnects target from serial console by typing 'exit' command until host machine ID matches ID of the worker VM.

check_serial_redirection

check_serial_redirection();

Checks if serial redirection is currently active by comparing worker VM machine id against id returned from serial console. VM ID is collected by opening 'log-console' which is not redirected.