From 5249a7a0119907366ac40ae2894346ed40e024ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dost=C3=A1l?= Date: Fri, 6 Sep 2019 15:14:46 +0200 Subject: [PATCH] QAM public cloud enablement --- data/publiccloud/ssh_config | 7 ++ lib/Utils/Backends.pm | 7 ++ lib/consoletest.pm | 22 ++++-- lib/main_common.pm | 46 +++++++----- lib/publiccloud/basetest.pm | 8 ++- lib/publiccloud/instance.pm | 8 ++- lib/publiccloud/ssh_interactive.pm | 71 ++++++++++++++++++ lib/susedistribution.pm | 7 +- lib/y2_module_consoletest.pm | 2 +- products/sle/main.pm | 2 +- tests/console/ntp.pm | 1 + tests/publiccloud/download_repos.pm | 49 +++++++++++++ tests/publiccloud/instance_overview.pm | 49 +++++++++++++ tests/publiccloud/patch_and_reboot.pm | 39 ++++++++++ tests/publiccloud/ssh_interactive_end.pm | 36 ++++++++++ tests/publiccloud/ssh_interactive_init.pm | 83 ++++++++++++++++++++++ tests/publiccloud/ssh_interactive_start.pm | 40 +++++++++++ tests/publiccloud/transfer_repos.pm | 40 +++++++++++ 18 files changed, 483 insertions(+), 34 deletions(-) create mode 100644 data/publiccloud/ssh_config create mode 100644 lib/publiccloud/ssh_interactive.pm create mode 100644 tests/publiccloud/download_repos.pm create mode 100644 tests/publiccloud/instance_overview.pm create mode 100644 tests/publiccloud/patch_and_reboot.pm create mode 100644 tests/publiccloud/ssh_interactive_end.pm create mode 100644 tests/publiccloud/ssh_interactive_init.pm create mode 100644 tests/publiccloud/ssh_interactive_start.pm create mode 100644 tests/publiccloud/transfer_repos.pm diff --git a/data/publiccloud/ssh_config b/data/publiccloud/ssh_config new file mode 100644 index 000000000000..0d230a0d50f7 --- /dev/null +++ b/data/publiccloud/ssh_config @@ -0,0 +1,7 @@ +ControlMaster auto +ControlPath /tmp/ssh_%r_%h_%p +StrictHostKeyChecking no +HostKeyAlgorithms ssh-rsa +IdentityFile ~/.ssh/id_rsa +ControlPersist 86400 + diff --git a/lib/Utils/Backends.pm b/lib/Utils/Backends.pm index e0ede34c638a..276c5543b11b 100644 --- a/lib/Utils/Backends.pm +++ b/lib/Utils/Backends.pm @@ -44,6 +44,7 @@ use constant { CONSOLES => [ qw( set_sshserial_dev + unset_sshserial_dev use_ssh_serial_console ) ] @@ -62,6 +63,12 @@ sub set_sshserial_dev { bmwqemu::save_vars(); } +sub unset_sshserial_dev { + $serialdev = get_var('SERIALDEV_'); + set_var('SERIALDEV', $serialdev); + bmwqemu::save_vars(); +} + # Use it after SUT boot finish, as it requires ssh connection to SUT to # interact with SUT, including window and serial console diff --git a/lib/consoletest.pm b/lib/consoletest.pm index 72d5a8f9a998..4d3abf043e57 100644 --- a/lib/consoletest.pm +++ b/lib/consoletest.pm @@ -49,13 +49,21 @@ Method executed when run() finishes and the module has result => 'fail' =cut sub post_fail_hook { - my ($self) = shift; - select_console('log-console'); - $self->SUPER::post_fail_hook; - $self->remount_tmp_if_ro; - $self->export_logs_basic; - # Export extra log after failure for further check gdm issue 1127317, also poo#45236 used for tracking action on Openqa - $self->export_logs_desktop; + # On Public Cloud everything is done via SSH so the code below doesn't work + # TODO: Make some reasonable base post_fail_hook for Public Cloud + unless (get_var('PUBLIC_CLOUD')) { + my ($self) = shift; + select_console('log-console'); + $self->SUPER::post_fail_hook; + $self->remount_tmp_if_ro; + $self->export_logs_basic; + # Export extra log after failure for further check gdm issue 1127317, also poo#45236 used for tracking action on Openqa + $self->export_logs_desktop; + } +} + +sub test_flags { + return get_var('PUBLIC_CLOUD') ? {no_rollback => 1} : {}; } 1; diff --git a/lib/main_common.pm b/lib/main_common.pm index a9f0bbc8a2ad..894a426b44ef 100644 --- a/lib/main_common.pm +++ b/lib/main_common.pm @@ -1576,13 +1576,12 @@ sub load_extra_tests_console { # JeOS kernel is missing 'openvswitch' kernel module loadtest "console/openvswitch" unless is_jeos; # dependency of git test - loadtest "console/sshd"; - # start extra console tests from here + loadtest "console/sshd" unless get_var('PUBLIC_CLOUD'); loadtest "console/update_alternatives"; loadtest 'console/rpm'; loadtest 'console/slp'; - # Audio device is not supported on ppc64le, s390x, JeOS, and Xen PV - if (!get_var("OFW") && !is_jeos && !check_var('VIRSH_VMM_FAMILY', 'xen') && !check_var('ARCH', 's390x')) { + # Audio device is not supported on ppc64le, s390x, JeOS, Public Cloud and Xen PV + if (!get_var('PUBLIC_CLOUD') && !get_var("OFW") && !is_jeos && !check_var('VIRSH_VMM_FAMILY', 'xen') && !check_var('ARCH', 's390x')) { loadtest "console/aplay"; loadtest "console/soundtouch" if is_opensuse || (is_sle('12-sp4+') && is_sle('<15')); # wavpack is available only sle12sp4 onwards @@ -1590,9 +1589,9 @@ sub load_extra_tests_console { loadtest "console/wavpack"; } } - loadtest "console/libvorbis"; - loadtest "console/command_not_found"; - if (is_sle '12-sp2+') { + loadtest "console/libvorbis" unless get_var('PUBLIC_CLOUD'); + loadtest "console/command_not_found" unless get_var('PUBLIC_CLOUD'); + if (is_sle('12-sp2+') && !get_var('PUBLIC_CLOUD')) { loadtest 'console/openssl_alpn'; loadtest 'console/autoyast_removed'; } @@ -1601,19 +1600,19 @@ sub load_extra_tests_console { loadtest "console/ntp_client" if (!is_sle || is_jeos); loadtest "console/mta" unless is_jeos; # We cannot change network device settings as rely on ssh/vnc connection to the machine - loadtest "console/yast2_lan_device_settings" unless is_s390x(); + loadtest "console/yast2_lan_device_settings" unless (is_s390x() || get_var('PUBLIC_CLOUD')); loadtest "console/check_default_network_manager"; loadtest "console/ipsec_tools_h2h" if get_var("IPSEC"); loadtest "console/git"; loadtest "console/cups"; loadtest "console/java"; - loadtest "console/sqlite3"; + loadtest "console/sqlite3" unless get_var('PUBLIC_CLOUD'); loadtest "console/ant" if is_sle('<15-sp1'); - loadtest "console/gdb"; + loadtest "console/gdb" unless get_var('PUBLIC_CLOUD'); loadtest "console/perf" if is_sle('<15-sp1'); loadtest "console/sysctl"; loadtest "console/sysstat"; - loadtest "console/curl_ipv6"; + loadtest "console/curl_ipv6" unless get_var('PUBLIC_CLOUD'); loadtest "console/wget_ipv6"; loadtest "console/ca_certificates_mozilla"; loadtest "console/unzip"; @@ -1623,7 +1622,7 @@ sub load_extra_tests_console { loadtest "console/rsync"; loadtest "console/clamav"; loadtest "console/shells"; - loadtest 'console/sudo'; + loadtest 'console/sudo' unless get_var('PUBLIC_CLOUD'); loadtest "console/repo_orphaned_packages_check" if is_jeos; # dstat is not in sle12sp1 loadtest "console/dstat" if is_sle('12-SP2+') || is_opensuse; @@ -1633,21 +1632,21 @@ sub load_extra_tests_console { } # bind need source package and legacy and development module on SLE15+ loadtest 'console/bind' if get_var('MAINT_TEST_REPO'); - unless (is_sle('<12-SP3')) { + unless (is_sle('<12-SP3') || get_var('PUBLIC_CLOUD')) { loadtest 'x11/evolution/evolution_prepare_servers'; loadtest 'console/mutt'; } loadtest 'console/supportutils' if (is_sle && !is_jeos); - loadtest 'console/mdadm' unless is_jeos; + loadtest 'console/mdadm' unless (is_jeos || get_var('PUBLIC_CLOUD')); loadtest 'console/journalctl'; - loadtest 'console/quota' unless is_jeos; - loadtest 'console/vhostmd'; + loadtest 'console/quota' unless (is_jeos || get_var('PUBLIC_CLOUD')); + loadtest 'console/vhostmd' unless get_var('PUBLIC_CLOUD'); loadtest 'console/rpcbind' unless is_jeos; # sysauth test scenarios run in the console - loadtest "sysauth/sssd" if get_var('SYSAUTHTEST') || is_sle('12-SP5+'); + loadtest "sysauth/sssd" if (!get_var('PUBLIC_CLOUD') && (get_var('SYSAUTHTEST') || is_sle('12-SP5+'))); loadtest 'console/timezone'; loadtest 'console/ntp' if is_sle('<15'); - loadtest 'console/procps'; + loadtest 'console/procps' unless get_var('PUBLIC_CLOUD'); loadtest "console/lshw" if ((is_sle('15+') && (is_ppc64le || is_x86_64)) || is_opensuse); loadtest 'console/kmod'; loadtest 'console/suse_module_tools'; @@ -2622,6 +2621,17 @@ sub load_publiccloud_tests { elsif (get_var('PUBLIC_CLOUD_IMG_PROOF_TESTS')) { loadtest "publiccloud/img_proof"; } + elsif (get_var('PUBLIC_CLOUD_QAM')) { + loadtest "publiccloud/download_repos"; + my $args = OpenQA::Test::RunArgs->new(); + loadtest "publiccloud/ssh_interactive_init", run_args => $args; + loadtest "publiccloud/transfer_repos", run_args => $args; + loadtest "publiccloud/patch_and_reboot", run_args => $args; + loadtest "publiccloud/ssh_interactive_start", run_args => $args; + loadtest "publiccloud/instance_overview"; + load_extra_tests_console(); + loadtest "publiccloud/ssh_interactive_end", run_args => $args; + } elsif (get_var('PUBLIC_CLOUD_LTP')) { loadtest 'publiccloud/run_ltp'; } diff --git a/lib/publiccloud/basetest.pm b/lib/publiccloud/basetest.pm index 2f87bd8af2ca..2a5431a0f2d7 100644 --- a/lib/publiccloud/basetest.pm +++ b/lib/publiccloud/basetest.pm @@ -78,6 +78,11 @@ sub _cleanup { eval { $self->cleanup(); } or bmwqemu::fctwarn($@); $self->{provider} //= []; + my $flags = $self->test_flags(); + if ($flags->{publiccloud_multi_module} && + !($self->{result} eq 'fail' && $flags->{fatal})) { + return; # skip cleanup + } for my $provider (@{$self->{provider}}) { eval { $provider->cleanup(); } or bmwqemu::fctwarn($@); } @@ -93,7 +98,4 @@ sub post_run_hook { $self->_cleanup() unless $self->{cleanup_called}; } - - - 1; diff --git a/lib/publiccloud/instance.pm b/lib/publiccloud/instance.pm index b3020e32a23d..5b6bc4571437 100644 --- a/lib/publiccloud/instance.pm +++ b/lib/publiccloud/instance.pm @@ -68,7 +68,13 @@ sub run_ssh_command { delete($args{no_quote}); delete($args{ssh_opts}); delete($args{username}); - return script_output($ssh_cmd, %args); + if ($args{timeout} == 0) { + # Run the command and don't wait for it - no output nor returncode here + script_run($ssh_cmd, %args); + } else { + # Run the command, wait for it and return the output + return script_output($ssh_cmd, %args); + } } =head2 scp diff --git a/lib/publiccloud/ssh_interactive.pm b/lib/publiccloud/ssh_interactive.pm new file mode 100644 index 000000000000..20eae8276040 --- /dev/null +++ b/lib/publiccloud/ssh_interactive.pm @@ -0,0 +1,71 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: Class with helpers related to SSH Interactive mode +# +# Maintainer: Pavel Dostal + +package publiccloud::ssh_interactive; +use base opensusebasetest; +use testapi; +use Utils::Backends qw(set_sshserial_dev unset_sshserial_dev); +use strict; +use warnings; + +our @ISA = qw(Exporter); +our @EXPORT = qw(ssh_interactive_tunnel ssh_interactive_join ssh_interactive_leave); + +sub ssh_interactive_tunnel { + my ($instance) = @_; + + # Prepare the environment for the SSH tunnel + my $upload_port = get_required_var('QEMUPORT') + 1; + my $upload_host = testapi::host_ip(); + + $instance->run_ssh_command( + cmd => "'rm -rf /dev/sshserial; mkfifo -m a=rwx /dev/sshserial; tail -fn +1 /dev/sshserial' | tee /dev/$serialdev ", # Create /dev/sshserial fifo on remote and tail|tee it to /dev/$serialdev on local + timeout => 0, # This will also cause script_run instead of script_output to be used so the test will not wait for the command to end + no_quote => 1, + ssh_opts => "-t -R $upload_port:$upload_host:$upload_port", # Tunnel the worker port (for downloading from data/ and uploading assets / logs + username => 'root' + ); + sleep 3; + save_screenshot; + + set_var('SERIALDEV_', $serialdev); + set_var('_SSH_TUNNELS_INITIALIZED', 1); +} + +sub ssh_interactive_join { + # Prepare the environment to use the SSH tunnel for upload/download from the worker + #set_var('SUT_HOSTNAME', script_output('sed -n "s/^ Hostname \([0-9.]*\)$/\1/p" ~/.ssh/config')); + set_var('AUTOINST_URL_HOSTNAME', 'localhost'); + set_sshserial_dev(); + + # Open SSH interactive session and check the serial console works + type_string("ssh -t sut\n"); + wait_serial("ssh_serial_ready", 10); + + $testapi::distri->set_standard_prompt('root'); +} + +sub ssh_interactive_leave { + # Check if the SSH tunnel is still up and leave the SSH interactive session + assert_script_run("if [[ -p /dev/$serialdev ]]; then true; else false; fi"); + type_string("exit\n"); + + # Restore the environment to not use the SSH tunnel for upload/download from the worker + #set_var('SUT_HOSTNAME', testapi::host_ip()); + set_var('AUTOINST_URL_HOSTNAME', testapi::host_ip()); + unset_sshserial_dev(); + + $testapi::distri->set_standard_prompt('root'); +} + +1; diff --git a/lib/susedistribution.pm b/lib/susedistribution.pm index e31a683eac80..534fe8e7f57f 100644 --- a/lib/susedistribution.pm +++ b/lib/susedistribution.pm @@ -18,6 +18,7 @@ use version_utils qw(is_hyperv_in_gui is_sle is_leap is_svirt_except_s390x is_tu use x11utils qw(desktop_runner_hotkey ensure_unlocked_desktop); use Utils::Backends qw(set_sshserial_dev use_ssh_serial_console is_remote_backend); use backend::svirt qw(SERIAL_TERMINAL_DEFAULT_DEVICE SERIAL_TERMINAL_DEFAULT_PORT); +use publiccloud::ssh_interactive 'ssh_interactive_join'; use Cwd; =head1 SUSEDISTRIBUTION @@ -767,15 +768,15 @@ sub activate_console { # Both consoles and shells should be prevented from blanking if ((($type eq 'console') or ($type =~ /shell/)) and (get_var('BACKEND', '') =~ /qemu|svirt/)) { # On s390x 'setterm' binary is not present as there's no linux console - if (!check_var('ARCH', 's390x')) { + unless (check_var('ARCH', 's390x') || get_var('PUBLIC_CLOUD')) { # Disable console screensaver $self->script_run('setterm -blank 0') unless $args{skip_setterm}; } } if (get_var('TUNNELED') && $name !~ /tunnel/) { die "Console '$console' activated in TUNNEL mode activated but tunnel(s) are not yet initialized, use the 'tunnel' console and call 'setup_ssh_tunnels' first" unless get_var('_SSH_TUNNELS_INITIALIZED'); - $self->script_run('ssh -t sut', 0); - ensure_user($user); + (get_var('PUBLIC_CLOUD')) ? ssh_interactive_join() : $self->script_run('ssh -t sut', 0); + ensure_user($user) unless (get_var('PUBLIC_CLOUD')); } set_var('CONSOLE_JUST_ACTIVATED', 1); } diff --git a/lib/y2_module_consoletest.pm b/lib/y2_module_consoletest.pm index d6aac9db0535..485c27854452 100644 --- a/lib/y2_module_consoletest.pm +++ b/lib/y2_module_consoletest.pm @@ -36,7 +36,7 @@ sub post_run_hook { } sub test_flags { - return {fatal => 0}; + return get_var('PUBLIC_CLOUD') ? {no_rollback => 1, fatal => 0} : {fatal => 0}; } 1; diff --git a/products/sle/main.pm b/products/sle/main.pm index 062affd1c9f0..f99e4b088c1f 100644 --- a/products/sle/main.pm +++ b/products/sle/main.pm @@ -885,7 +885,7 @@ elsif (get_var('LIBSOLV_INSTALLCHECK')) { elsif (get_var("EXTRATEST")) { boot_hdd_image; load_extra_tests(); - loadtest "console/coredump_collect" unless (check_var('EXTRATEST', 'wicked')); + loadtest "console/coredump_collect" unless (check_var('EXTRATEST', 'wicked') || get_var('PUBLIC_CLOUD')); } elsif (get_var("WINDOWS")) { diff --git a/tests/console/ntp.pm b/tests/console/ntp.pm index f376fe6b1cae..99d2d4f4e00c 100644 --- a/tests/console/ntp.pm +++ b/tests/console/ntp.pm @@ -27,4 +27,5 @@ sub run { services::ntpd::check_service(); services::ntpd::check_function(); } + 1; diff --git a/tests/publiccloud/download_repos.pm b/tests/publiccloud/download_repos.pm new file mode 100644 index 000000000000..c7e088eed28d --- /dev/null +++ b/tests/publiccloud/download_repos.pm @@ -0,0 +1,49 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: Download repositores from the internal server +# +# Maintainer: Pavel Dostal + +use base 'consoletest'; +use registration; +use warnings; +use testapi; +use strict; +use utils; + +sub run { + my ($self, $args) = @_; + select_console 'tunnel-console'; + + my $domain = ''; + my @repos = split(/,/, get_var('INCIDENT_REPO')); + assert_script_run("mkdir ~/repos"); + assert_script_run("cd ~/repos"); + for my $maintrepo (@repos) { + my ($parent) = $maintrepo =~ 'https?://(.*)$'; + my ($domain) = $parent =~ '^([a-zA-Z.]*)'; + assert_script_run("wget --no-clobber -r -R 'robots.txt,*.ico,*.png,*.gif,*.css,*.js,*.htm*' --domains $domain --no-parent $parent $maintrepo", timeout => 600); + assert_script_run("echo -en '# $maintrepo:\\n\\n' >> /tmp/repos.list.txt"); + assert_script_run("find $parent >> /tmp/repos.list.txt"); + } + upload_logs('/tmp/repos.list.txt'); + assert_script_run("cd ~/"); +} + +sub test_flags { + return { + fatal => 1, + milestone => 1, + publiccloud_multi_module => 1 + }; +} + +1; + diff --git a/tests/publiccloud/instance_overview.pm b/tests/publiccloud/instance_overview.pm new file mode 100644 index 000000000000..82e2fd97ba4d --- /dev/null +++ b/tests/publiccloud/instance_overview.pm @@ -0,0 +1,49 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: This is just bunch of random commands overviewing the public cloud instance +# We just register the system, install random package, see the system and network configuration +# This test module will fail at the end to prove that the test run will continue without rollback +# +# Maintainer: Pavel Dostal + +use base 'consoletest'; +use registration; +use warnings; +use testapi; +use strict; +use utils; + +sub run { + my ($self, $args) = @_; + select_console 'root-console'; + + assert_script_run("hostname -f"); + assert_script_run("uname -a"); + + assert_script_run("cat /etc/os-release"); + + assert_script_run("ps aux | nl"); + + register_product(); + + assert_script_run("ip a s"); + assert_script_run("ip -6 a s"); + assert_script_run("ip r s"); + assert_script_run("ip -6 r s"); + + assert_script_run("cat /etc/hosts"); + assert_script_run("cat /etc/resolv.conf"); + + zypper_call("in traceroute"); + assert_script_run("traceroute -I gate.suse.cz", 90); +} + +1; + diff --git a/tests/publiccloud/patch_and_reboot.pm b/tests/publiccloud/patch_and_reboot.pm new file mode 100644 index 000000000000..0a4190bc2ffc --- /dev/null +++ b/tests/publiccloud/patch_and_reboot.pm @@ -0,0 +1,39 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: Refresh repositories, apply patches and reboot +# +# Maintainer: Pavel Dostal + +use base 'consoletest'; +use registration; +use warnings; +use testapi; +use strict; +use utils; + +sub run { + my ($self, $args) = @_; + select_console 'tunnel-console'; + + $args->{my_instance}->run_ssh_command(cmd => "sudo zypper ref"); + ssh_fully_patch_system($args->{my_instance}->public_ip); + $args->{my_instance}->softreboot(); +} + +sub test_flags { + return { + fatal => 1, + milestone => 1, + publiccloud_multi_module => 1 + }; +} + +1; + diff --git a/tests/publiccloud/ssh_interactive_end.pm b/tests/publiccloud/ssh_interactive_end.pm new file mode 100644 index 000000000000..164a1fdf36df --- /dev/null +++ b/tests/publiccloud/ssh_interactive_end.pm @@ -0,0 +1,36 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: This test will leave the SSH interactive session, kill the SSH tunnel and destroy the public cloud instance +# +# Maintainer: Pavel Dostal + +use Mojo::Base 'publiccloud::basetest'; +use publiccloud::ssh_interactive; +use testapi; +use utils; + +sub run { + my ($self, $args) = @_; + select_console 'root-console'; + + ssh_interactive_leave(); + + # Find the PID of the SSH tunnel and kill it + #assert_script_run("ps --no-headers ao 'pid:1,cmd:1' | grep '[s]sh'"); + #assert_script_run("kill -9 `ps --no-headers ao 'pid:1,cmd:1' | grep '[s]sh -t -R' | cut -d' ' -f1`"); + + # Destroy the public cloud instance + select_console 'tunnel-console', await_console => 0; + send_key "ctrl-c"; + $args->{my_provider}->cleanup(); +} + +1; + diff --git a/tests/publiccloud/ssh_interactive_init.pm b/tests/publiccloud/ssh_interactive_init.pm new file mode 100644 index 000000000000..4a055e828bf2 --- /dev/null +++ b/tests/publiccloud/ssh_interactive_init.pm @@ -0,0 +1,83 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: This tests will deploy the public cloud instance and prepare the ssh +# +# Maintainer: Pavel Dostal + +use Mojo::Base 'publiccloud::basetest'; +use publiccloud::ssh_interactive; +use testapi; +use utils; + +sub run { + my ($self, $args) = @_; + + # The tunnel-console will be ocupated by the SSH tunnel + select_console 'tunnel-console'; + + # Create public cloud instance + my $provider = $self->provider_factory(); + my $instance = $provider->create_instance(check_connectivity => 0); + $instance->check_ssh_port(timeout => 300); + $args->{my_provider} = $provider; + $args->{my_instance} = $instance; + + # configure ssh client, fetch the instance ssh public key, do not use default $instance->ssh_opts + assert_script_run('curl ' . data_url('publiccloud/ssh_config') . ' -o ~/.ssh/config'); + assert_script_run "ssh-keyscan " . $instance->public_ip . " >> ~/.ssh/known_hosts"; + $instance->ssh_opts(""); + + # Create the ssh alias + assert_script_run('echo -en "Host sut\n Hostname ' . $instance->public_ip . '\n" >> ~/.ssh/config'); + + # Copy the SSH settings also for normal user + assert_script_run("mkdir /home/" . $testapi::username . "/.ssh"); + assert_script_run("chmod -R 700 /home/" . $testapi::username . "/.ssh/"); + assert_script_run("cp ~/.ssh/* /home/" . $testapi::username . "/.ssh/"); + assert_script_run("chown -R " . $testapi::username . " /home/" . $testapi::username . "/.ssh/"); + + # configure ssh server, allow root and password login + $instance->run_ssh_command(cmd => 'hostname -f'); + $instance->run_ssh_command(cmd => 'echo -e "' . $testapi::password . '\n' . $testapi::password . '" | sudo passwd root'); + $instance->run_ssh_command(cmd => 'sudo sed -i "s/PermitRootLogin no/PermitRootLogin yes/g" /etc/ssh/sshd_config'); + $instance->run_ssh_command(cmd => 'sudo sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config'); + $instance->run_ssh_command(cmd => 'sudo cp /home/ec2-user/.ssh/authorized_keys /root/.ssh/'); + $instance->run_ssh_command(cmd => 'sudo chmod 644 /root/.ssh/authorized_keys'); + $instance->run_ssh_command(cmd => 'sudo chown root /root/.ssh/authorized_keys'); + $instance->run_ssh_command(cmd => 'sudo systemctl reload sshd'); + + # Create normal user on remote instance and make it accessible by key + $instance->run_ssh_command(cmd => "sudo useradd " . $testapi::username); + $instance->run_ssh_command(cmd => "sudo mkdir /home/" . $testapi::username); + $instance->run_ssh_command(cmd => "sudo chown -R " . $testapi::username . " /home/" . $testapi::username . "/"); + $instance->run_ssh_command(cmd => 'echo -e "' . $testapi::password . '\n' . $testapi::password . '" | sudo passwd ' . $testapi::username); + $instance->run_ssh_command(cmd => "sudo mkdir /home/" . $testapi::username . "/.ssh"); + $instance->run_ssh_command(cmd => "sudo chmod -R 700 /home/" . $testapi::username . "/.ssh"); + $instance->run_ssh_command(cmd => 'sudo cp /home/ec2-user/.ssh/authorized_keys /home/' . $testapi::username . '/.ssh/'); + $instance->run_ssh_command(cmd => "sudo chmod 644 /home/" . $testapi::username . "/.ssh/authorized_keys"); + $instance->run_ssh_command(cmd => "sudo chown -R " . $testapi::username . " /home/" . $testapi::username . "/.ssh/"); + + # Print ssh_serial_ready to serial console when interactive ssh session is initiated + $instance->run_ssh_command(cmd => "echo \"if tty -s; then echo ssh_serial_ready >> /dev/sshserial; fi\" > .bashrc"); + $instance->run_ssh_command(cmd => "sudo chmod 777 .bashrc"); + $instance->run_ssh_command(cmd => "sudo cp .bashrc /root/"); + $instance->run_ssh_command(cmd => "sudo cp .bashrc /home/" . $testapi::username . "/"); +} + +sub test_flags { + return { + fatal => 1, + milestone => 1, + publiccloud_multi_module => 1 + }; +} + +1; + diff --git a/tests/publiccloud/ssh_interactive_start.pm b/tests/publiccloud/ssh_interactive_start.pm new file mode 100644 index 000000000000..f7b2bef2261a --- /dev/null +++ b/tests/publiccloud/ssh_interactive_start.pm @@ -0,0 +1,40 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: This tests will establish the tunnel and enable the SSH interactive console +# +# Maintainer: Pavel Dostal + +use Mojo::Base 'publiccloud::basetest'; +use publiccloud::ssh_interactive; +use testapi; +use utils; + +sub run { + my ($self, $args) = @_; + select_console 'tunnel-console'; + + # Establish the tunnel (it will stay active in foreground and occupy this console!) + ssh_interactive_tunnel($args->{my_instance}); + + # Switch to root-console and SSH to the instance + # every other loaded test must stay in root-console + select_console 'root-console'; +} + +sub test_flags { + return { + fatal => 1, + milestone => 1, + publiccloud_multi_module => 1 + }; +} + +1; + diff --git a/tests/publiccloud/transfer_repos.pm b/tests/publiccloud/transfer_repos.pm new file mode 100644 index 000000000000..f55af5f914ac --- /dev/null +++ b/tests/publiccloud/transfer_repos.pm @@ -0,0 +1,40 @@ +# SUSE's openQA tests +# +# Copyright © 2019 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: Transfer repositories to the public cloud instasnce +# +# Maintainer: Pavel Dostal + +use base 'consoletest'; +use registration; +use warnings; +use testapi; +use strict; +use utils; + +sub run { + my ($self, $args) = @_; + select_console 'tunnel-console'; + + assert_script_run("rsync -va -e ssh ~/repos root@" . $args->{my_instance}->public_ip . ":'/tmp/repos'", timeout => 900); + $args->{my_instance}->run_ssh_command(cmd => "sudo find /tmp/repos/ -name *.repo -exec sed -i 's,http://,/tmp/repos/repos/,g' '{}' \\;"); + $args->{my_instance}->run_ssh_command(cmd => "sudo find /tmp/repos/ -name *.repo -exec zypper ar '{}' \\;"); + $args->{my_instance}->run_ssh_command(cmd => "sudo find /tmp/repos/ -name *.repo -exec echo '{}' \\;"); +} + +sub test_flags { + return { + fatal => 1, + milestone => 1, + publiccloud_multi_module => 1 + }; +} + +1; +