From ef1d2116c35656e9d30b4c23fbeb755ccc6a2f81 Mon Sep 17 00:00:00 2001 From: tinawang123 Date: Wed, 22 Jul 2020 11:43:36 +0800 Subject: [PATCH] Add RMT automatic testing code for import and export --- lib/repo_tools.pm | 105 ++++++++++++++++++++++------- schedule/migration/rmt_export.yaml | 3 +- schedule/migration/rmt_import.yaml | 2 +- tests/x11/rmt/rmt_export.pm | 47 +++++++++++++ tests/x11/rmt/rmt_import.pm | 50 ++++++++++++++ 5 files changed, 180 insertions(+), 27 deletions(-) create mode 100644 tests/x11/rmt/rmt_export.pm create mode 100644 tests/x11/rmt/rmt_import.pm diff --git a/lib/repo_tools.pm b/lib/repo_tools.pm index c145cd10dc28..68f42e7747c0 100644 --- a/lib/repo_tools.pm +++ b/lib/repo_tools.pm @@ -26,8 +26,18 @@ Tools for repositories used by openQA: =item * rmt_wizard +=item * rmt_sync + +=item * rmt_enable_pro + +=item * rmt_list_pro + =item * rmt_mirror_repo +=item * rmt_export_data + +=item * rmt_import_data + =item * prepare_source_repo =item * disable_source_repo @@ -64,7 +74,12 @@ our @EXPORT = qw( smt_wizard smt_mirror_repo rmt_wizard + rmt_sync + rmt_enable_pro + rmt_list_pro rmt_mirror_repo + rmt_export_data + rmt_import_data prepare_source_repo disable_source_repo get_repo_var_name @@ -215,7 +230,7 @@ sub rmt_wizard { wait_still_screen; type_string(get_required_var('SMT_ORG_PASSWORD')); send_key 'alt-n'; - assert_screen 'yast2_rmt_config_written_successfully'; + assert_screen 'yast2_rmt_config_written_successfully', 60; send_key 'alt-o'; assert_screen 'yast2_rmt_db_password'; send_key 'alt-p'; @@ -229,61 +244,101 @@ sub rmt_wizard { send_key 'alt-n'; assert_screen 'yast2_rmt_ssl_CA_password'; type_password_twice; - assert_screen 'yast2_rmt_firewall'; - send_key 'alt-o'; + if (check_screen 'yast2_rmt_firewall') { + send_key 'alt-o'; + } else { + assert_screen 'yast2_rmt_firewall_disable'; + } wait_still_screen; send_key 'alt-n'; assert_screen 'yast2_rmt_service_status'; - send_key 'alt-n'; - assert_screen 'yast2_rmt_config_summary'; + send_key_until_needlematch('yast2_rmt_config_summary', 'alt-n', 3, 10); send_key 'alt-f'; wait_serial("yast2-rmt-wizard-0", 800) || die 'rmt wizard failed, it can be connection issue or credential issue'; } +=head2 rmt_sync + + rmt_sync(); + +Function to sync rmt server + +=cut +sub rmt_sync { + assert_script_run 'rmt-cli sync', 1800; +} + +=head2 rmt_enable_pro + + rmt_enable_pro(); + +Function to enable products + +=cut +sub rmt_enable_pro { + my $pro_ls = get_var('RMT_PRO') || 'sle-module-legacy/15/x86_64'; + assert_script_run "rmt-cli products enable $pro_ls", 600; +} + =head2 rmt_mirror_repo rmt_mirror_repo(); -Function to verify and enable repository mirror +Function to mirror the enabled repository =cut sub rmt_mirror_repo { - my $repo_list = get_var('RMT_REPO') || 'sle-module-legacy/15/x86_64'; - assert_script_run 'rmt-cli sync', 1800; - for my $repo (split(/,/, $repo_list)) { - assert_script_run "rmt-cli products enable $repo", 600; - } assert_script_run 'rmt-cli mirror', 1800; - assert_script_run 'rmt-cli repo list'; +} + +=head2 rmt_list_pro + + rmt_list_pro(); + +Function to list products + +=cut +sub rmt_list_pro { + assert_script_run 'rmt-cli product list', 600; } =head2 rmt_import_data rmt_import_data($datafile); -RMT server import data about available repositories and the mirrored packages -from disconnected RMT server, then verify imported repositories on new RMT server. +RMT server import data from one folder which stored RMT export data about +available repositories and the mirrored packages C<$datafile> is repository source. =cut sub rmt_import_data { - my ($datafile) = @_; - my $datapath = "/mnt/external/"; - # Decompress the RMT data file to test path - assert_script_run("mkdir -p $datapath"); - assert_script_run("wget -q " . data_url("rmt/$datafile")); - assert_script_run("tar -xzvf $datafile -C $datapath"); - assert_script_run("rm -rf $datafile"); + my ($datapath) = @_; + # Check import data resource exsited + assert_script_run("ls $datapath"); # Import RMT data from test path to new RMT server assert_script_run("rmt-cli import data $datapath", 600); assert_script_run("rmt-cli import repos $datapath", 600); - # Show repo list on new RMT server for later debugging - assert_script_run("rmt-cli repos list"); - # Enable repositories as required on new RMT server - assert_script_run("rmt-cli repos list | grep Web-Scripting"); assert_script_run("rm -rf $datapath"); } +=head2 rmt_export_data + + rmt_export_data(); + +RMT server export data about available repositories and the mirrored packages + +=cut +sub rmt_export_data { + my $datapath = "/rmtdata/"; + assert_script_run("mkdir -p $datapath"); + assert_script_run("chown _rmt:nginx $datapath"); + # Export RMT data to one folder + assert_script_run("rmt-cli export data $datapath", 600); + assert_script_run("rmt-cli export settings $datapath", 600); + assert_script_run("rmt-cli export repos $datapath", 600); + assert_script_run("ls $datapath"); +} + =head2 prepare_source_repo prepare_source_repo($repo_name); diff --git a/schedule/migration/rmt_export.yaml b/schedule/migration/rmt_export.yaml index 2a9e62a9da39..df5a0a9cc448 100644 --- a/schedule/migration/rmt_export.yaml +++ b/schedule/migration/rmt_export.yaml @@ -3,4 +3,5 @@ description: > This is for rmt export and mirror test schedule: - boot/boot_to_desktop - - console/consoletest_setup + - network/setup_multimachine + - x11/rmt/rmt_export diff --git a/schedule/migration/rmt_import.yaml b/schedule/migration/rmt_import.yaml index 7f0eeaefcb4d..f2907b5291db 100644 --- a/schedule/migration/rmt_import.yaml +++ b/schedule/migration/rmt_import.yaml @@ -4,4 +4,4 @@ description: > schedule: - boot/boot_to_desktop - network/setup_multimachine - - x11/rmt + - x11/rmt/rmt_import diff --git a/tests/x11/rmt/rmt_export.pm b/tests/x11/rmt/rmt_export.pm new file mode 100644 index 000000000000..838b540e1f53 --- /dev/null +++ b/tests/x11/rmt/rmt_export.pm @@ -0,0 +1,47 @@ +# SUSE's openQA tests +# +# Copyright © 2020 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: setup one RMT server, sync, enable, mirror and list +# products. Then export RMT data to one folder. Wait another RMT +# Server to import those data +# Maintainer: Yutao Wang + +use strict; +use warnings; +use testapi; +use base 'x11test'; +use repo_tools; +use utils; +use x11utils 'turn_off_gnome_screensaver'; +use lockapi 'mutex_create'; +use mmapi 'wait_for_children'; + +sub run { + x11_start_program('xterm -geometry 150x35+5+5', target_match => 'xterm'); + # Avoid blank screen since smt sync needs time + turn_off_gnome_screensaver; + become_root; + rmt_wizard(); + # sync, enable, mirror and list products + rmt_sync(); + rmt_enable_pro(); + rmt_mirror_repo(); + rmt_list_pro(); + # export data and repos + rmt_export_data(); + mutex_create("FINISH_EXPORT_DATA"); + wait_for_children; + type_string "killall xterm\n"; +} + +sub test_flags { + return {fatal => 1}; +} + +1; diff --git a/tests/x11/rmt/rmt_import.pm b/tests/x11/rmt/rmt_import.pm new file mode 100644 index 000000000000..1ea1748a3b49 --- /dev/null +++ b/tests/x11/rmt/rmt_import.pm @@ -0,0 +1,50 @@ +# 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: Add rmt configuration test and basic configuration via +# rmt-wizard, import RMT data and repos from one folder which +# stored RMT export data, then verify the imported data can list +# Maintainer: Yutao wang + +use strict; +use warnings; +use testapi; +use base 'x11test'; +use repo_tools; +use utils; +use x11utils 'turn_off_gnome_screensaver'; +use lockapi qw(mutex_create mutex_wait); + +sub run { + x11_start_program('xterm -geometry 150x35+5+5', target_match => 'xterm'); + # Avoid blank screen since smt sync needs time + turn_off_gnome_screensaver; + become_root; + rmt_wizard(); + # sync from SCC + rmt_sync; + # import data and repos from an existing RMT server + my $datapath = "/rmtdata/"; + mutex_wait("FINISH_EXPORT_DATA"); + exec_and_insert_password("scp -o StrictHostKeyChecking=no -r root\@10.0.2.101:$datapath /"); + assert_script_run("chown -R _rmt:nginx $datapath"); + rmt_import_data($datapath); + # check the imported products correct + rmt_enable_pro; + rmt_list_pro; + my $pro_ls = get_var('RMT_PRO') || 'sle-module-legacy/15/x86_64'; + assert_script_run("rmt-cli product list | grep $pro_ls"); + type_string "killall xterm\n"; +} + +sub test_flags { + return {fatal => 1}; +} + +1;