lib/publiccloud/instance.pm

run_ssh_command

run_ssh_command(cmd => 'command'[, timeout => 90][, ssh_opts =>'..'][, username => 'XXX'][, no_quote => 0][, rc_only => 0]);

Runs a command cmd via ssh in the given VM. Retrieves the output. If the command retrieves not zero, an exception is thrown. Timeout can be set by timeout or 90 sec by default. <proceed_on_failure=1>> allows to proceed with validation when cmd is failing (return non-zero exit code) By default, the command is passed in single quotes to SSH. To avoid quoting use <no_quote=1>>. 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()>>. Use argument rc_only to only check for the return code of the command.

retry_ssh_command

ssh_script_retry(command[, retry => 3][, delay => 10][, timeout => 90][, ssh_opts =>'..'][, username => 'XXX'][, no_quote => 0]);

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. By default, the command is passed in single quotes to SSH. To avoid quoting use <no_quote=1>>. 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.

ssh_script_run

ssh_script_run($cmd [, timeout => $timeout] [, fail_message => $fail_message] [,quiet => $quiet] [,ssh_opts => $ssh_opts] [,username => $username])

Runs a command cmd via ssh on the publiccloud instance and returns the return code.

ssh_assert_script_run

ssh_assert_script_run($cmd [, timeout => $timeout] [, fail_message => $fail_message] [,quiet => $quiet] [,ssh_opts => $ssh_opts] [,username => $username])

Runs a command cmd via ssh on the publiccloud instance and die, unless it returns zero.

ssh_script_output

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

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

scp($from, $to, timeout => 90);

Use scp to copy a file from or to this instance. A url starting with remote: is replaced with the IP from this instance. E.g. a call to copy the file /var/log/cloudregister to /tmp looks like: <<$instance-scp('remote:/var/log/cloudregister', '/tmp');>>>

upload_log

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.

wait_for_guestregister

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. wait_for_guestregister is called inside create_instance(), enabled by check_guestregister

wait_for_ssh

wait_for_ssh([timeout => 600] [, proceed_on_failure => 0] [, ...])

When a remote pc instance starting, by default wait_stop param.=0(false) and this routine checks until the SSH port of the remote instance is reachable and open. Then by default also checks that system is up, unless systemup_check false/0.

Wnen a remote pc instance is stopping in shutdown, we set input param. wait_stop=1(true), to expect until ssh is closed; automatic defaults systemup_check=0 and proceed_on_failure=1 applied. Status values of exit_code: 0 = pass; 1 = fail; 2 = fail,but retry,till timeout or valid outcome.

Parameters: timeout => total wait timeout; default: 600. wait_stop => If true waits for ssh port to become unreachable, if false waits for ssh reachable; default: false. proceed_on_failure => in case of fail, if false exit test with error, if true let calling code to continue; default: wait_stop. username => default: username(). public_ip => default: public_ip(). systemup_check => If true, checks if the system is up too, instead of just checking the ssh port; default: !wait_stop. logs => If true, upload journal to test logs, if false log not uploaded, to speed up check; default: true.

Return: duration if pass undef if fail and proceed_on_failure true, otherwise die.

isok

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).

softreboot

($shutdown_time, $bootup_time) = softreboot([timeout => 600]);

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();

Stop the instance using the CSP api calls.

start

start([timeout => ?]);

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_state();

Get the status of the instance using the CSP api calls.

network_speed_test

network_speed_test();

Test the network speed.

measure_boottime

measure_boottime();

Perfomrance measurement of the system Boot time. Mainly used systemd-analyze command for the data extraction. Data is then collected in an internal record, ready for storing in a DB. Set PUBLIC_CLOUD_PERF_COLLECT true or >0, to activate boottime measurements.

store_boottime_db

store_boottime_db();

Save data collected with measure_boottime in a DB; Mainly stored on a remote InfluxDB on a Grafana server. To activate boottime push, shall be available results and PUBLIC_CLOUD_PERF_PUSH_DATA true/not 0 and _SECRET_PUBLIC_CLOUD_PERF_DB_TOKEN defined