ssh_script_retry(command[, retry => 3][, delay => 10][, timeout => 90][, ssh_opts =>'..'][, username => 'XXX']);
Run a command via ssh in the given PC instance until it succeeds or the given number of retries is exhausted and an exception is thrown. Timeout can be set by timeout or 90 sec by default. The command is passed in single quotes to SSH. With <ssh_opts='...'>> you can overwrite all default ops which are in <$instance-ssh_opts>>. Use argument username to specify a different username then <$instance-username()>>.
This function is deprecated. Please use ssh_script_retry instead.
C<args> - reference to args hash. it is important to pass reference so function can modify timeout passed to script_run by the caller
to make sure it is bigger than value defined in timeout command which suppose to kill what script_run needs to execute
C<ssh_cmd> - reference to string containing command which will be executed by script_run. function will tweak it to include timeout call
which will kill underlying command after time defined by args{timeout}
ssh_script_run($cmd [, timeout => $timeout] [,quiet => $quiet] [,ssh_opts => $ssh_opts] [,username => $username][, apply_graceful_timeout => $apply_graceful_timeout])
C<timeout> - TTL for command execution measured in seconds . After that period of time execution will be aborded
C<quiet> - avoid recording serial_results ( value pass to script_run call)
C<ssh_opts> - additional ssh options passed to ssh
C<username> - username used for ssh tunnel
C<apply_graceful_timeout> - in case waiting longer than timeout normally script_run will die. Setting this parameter to true
will avoid such failure
Runs a command cmd via ssh on the publiccloud instance and returns the return code, using testapi::script_run.
ssh_assert_script_run($cmd [, timeout => $timeout] [, fail_message => $fail_message] [,quiet => $quiet] [,ssh_opts => $ssh_opts] [,username => $username][, apply_graceful_timeout => $apply_graceful_timeout])
Runs a command cmd via ssh on the publiccloud instance and die on error.
Use the parameters of ssh_script_run.
ssh_script_output($script [, $wait, type_command => 1, proceed_on_failure => 1] [,quiet => $quiet] [,ssh_opts => $ssh_opts] [,username => $username])
Executing script inside SUT with bash -eo and directs stdout (but not stderr!) to the serial console and returns the output if the script exits with 0. Otherwise the test is set to failed.
ssh_script_retry($cmd, [expect => $expect], [retry => $retry], [delay => $delay], [timeout => $timeout], [die => $die] [,ssh_opts => $ssh_opts] [,username => $username])
Repeat command until expected result or timeout.
scp($from, $to [, timeout => 90] [, proceed_on_failure => 0][, apply_graceful_timeout => $apply_graceful_timeout]);
Copy a file to or from this instance using scp.
Arguments:
$from - source path. When it starts with remote:, the prefix is replaced with <username>@<public_ip>: so the file is read from this instance (download). Otherwise it is treated as a local path. Using remote: is only a convenience: you are free to pass an explicit user@host:/path instead, which is left untouched by this function.
$to - destination path. Uses the same remote: rewriting as $from, so a remote: destination uploads a local file to this instance. As with $from, an explicit user@host:/path can be passed and is left untouched.
timeout - maximum time in seconds allowed for the scp command. Defaults to SSH_TIMEOUT (90 seconds).
proceed_on_failure - when set to a true value a failing scp does not abort the test: the command is run via script_run and only an informational message is recorded. When false (the default) the copy is run via assert_script_run so a failure dies. Defaults to 0.
apply_graceful_timeout - same parameter as ssh_script_run.
Any -E <file> logging options present in $instance->ssh_opts are stripped, because scp does not accept them.
E.g. to download the file /var/log/cloudregister into /tmp:
$instance->scp('remote:/var/log/cloudregister', '/tmp');
and to upload a local /tmp/foo to the instance home directory:
$instance->scp('/tmp/foo', 'remote:/home/user/foo');
upload_log($filename);
Upload a file from this instance to openqa using upload_logs(). If the file doesn't exists on the instance, no error is thrown.
upload_check_logs_tar(@files);
Check remote log files status and upload tar.gz of only ok logs, to oqa UI.
Input: @files full-path-files array;
Return 1 true explicit, as stateless and never impact calling code.
wait_for_guestregister([timeout => 300]);
Run command systemctl is-active guestregister on the instance in a loop and wait till guestregister is ready. If guestregister finish with state failed, a soft-failure will be recorded. If guestregister will not finish within timeout seconds, job dies. In case of BYOS images we checking that service is inactive and quit Returns the time needed to wait for the guestregister to complete.
$self->_upload_guestregister_diagnostics($log, $name);
Upload $log (e.g. /var/log/cloudregister) and the full journalctl -u guestregister.service output, as a separate asset file. Used by wait_for_guestregister right before dying, so a failure carries the actual registration error instead of just the systemd state.
update_instance_ip(timeout => 600)
This subroutine checks the public IP cloud provider provides for the VM. When the IP differs from `$self->public_ip` we update `$self->public_ip`.
my $rc = $instance->wait_for_ssh_unreachable([delay => 2] [, timeout => 300] [, port => 22] [, die => 1]);
Wait until the SSH port of this instance stops accepting connections, i.e. when the instance goes down. Retrying continues until the port becomes unreachable or timeout seconds elapse (the number of attempts is derived as timeout / delay).
This is typically used to detect the reboot/shutdown window (e.g. from softreboot). The default delay is intentionally small so the short interval during which SSH becomes unreachable is not missed.
Returns the exit code of the last nc probe, as forwarded by script_retry. The value tells whether the port is still connectable: 0 means "not connected" (unreachable), a non-zero value means "still connected" (reachable).
0 when the port became unreachable within the timeout (success).
a non-zero value when the port is still reachable after the timeout, but only if die is set to a false value.
with the default die => 1, a still-reachable port makes script_retry die instead of returning, so the only value ever returned in that mode is 0.
undef as a corner case: script_retry returns undef when the last probe attempt is killed by its timeout wrapper before an exit code is reported. This is unlikely here (the probe is nc -w 1), but callers relying on the return value should treat undef as "not unreachable".
Arguments:
2. Keep it low to avoid missing the brief window where SSH is unreachable.PUBLIC_CLOUD_SSH_TIMEOUT or 300 if unset.22.1) the function dies if the port is still reachable after timeout. Set to 0 to instead return the non-zero return code.isok($exit_code);
To convert in a true or 1 value for perl tests the exit_code 0 of shell script ok.
Return: the positive test status of a shell exit code, that is true(1) and ok when its value is defined and zero: $x == 0 otherwise false(undef).
($shutdown_time, $bootup_time) = softreboot([timeout => 600] [, scan_ssh_host_key => ?]);
Does a softreboot of the instance by running the command shutdown -r. Return an array of two values, first one is the time till the instance isn't reachable anymore. The second one is the estimated bootup time.
stop();
Stop the instance using the CSP api calls.
start([timeout => ?] [, scan_ssh_host_key => ?]);
Start the instance and wait for the system to be up. Returns the number of seconds till the system up and running.
get_state();
Get the status of the instance using the CSP api calls.