From a98819090a325dbf121917997a1f3f361f5db435 Mon Sep 17 00:00:00 2001 From: Michele Pagot Date: Fri, 13 Dec 2024 15:59:21 +0100 Subject: [PATCH] Align qesap regression LTSS to HanaSR (#20796) Change the qesap regression implementation of LTSS registration to be more aligned to the one implemented for HanaSR. Use more similar variables, use functions from the registration library. Allow LTSS to be enabled in all conf.yaml. --- .../sles4sap/qe_sap_deployment/qesap_aws.yaml | 2 +- .../qe_sap_deployment/qesap_aws_fencing.yaml | 2 +- .../qe_sap_deployment/qesap_aws_sapconf.yaml | 2 +- .../qe_sap_deployment/qesap_azure.yaml | 2 +- .../qesap_azure_fencing_msi.yaml | 2 +- .../qesap_azure_fencing_spn.yaml | 2 +- .../qe_sap_deployment/qesap_azure_ltss.yaml | 50 ------------------- .../qesap_azure_sapconf.yaml | 2 +- .../qe_sap_deployment/qesap_azure_uri.yaml | 2 +- .../sles4sap/qe_sap_deployment/qesap_gcp.yaml | 2 +- .../qe_sap_deployment/qesap_gcp_fencing.yaml | 2 +- .../qe_sap_deployment/qesap_gcp_sapconf.yaml | 2 +- lib/qesapdeployment.pm | 34 ++++++++++++- lib/sles4sap_publiccloud.pm | 15 +----- t/14_qesap_ansible.t | 13 +++++ tests/sles4sap/publiccloud/qesap_terraform.pm | 3 +- tests/sles4sap/qesapdeployment/configure.pm | 21 +++++++- 17 files changed, 79 insertions(+), 79 deletions(-) delete mode 100644 data/sles4sap/qe_sap_deployment/qesap_azure_ltss.yaml diff --git a/data/sles4sap/qe_sap_deployment/qesap_aws.yaml b/data/sles4sap/qe_sap_deployment/qesap_aws.yaml index 164e831d038f..f02959be50a6 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_aws.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_aws.yaml @@ -36,7 +36,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' -e use_suseconnect=%SUSECONNECT% + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml diff --git a/data/sles4sap/qe_sap_deployment/qesap_aws_fencing.yaml b/data/sles4sap/qe_sap_deployment/qesap_aws_fencing.yaml index 96446cc9fecf..d6fa72155e1b 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_aws_fencing.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_aws_fencing.yaml @@ -39,7 +39,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml diff --git a/data/sles4sap/qe_sap_deployment/qesap_aws_sapconf.yaml b/data/sles4sap/qe_sap_deployment/qesap_aws_sapconf.yaml index b98c791f5c80..ccdb3e01efe5 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_aws_sapconf.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_aws_sapconf.yaml @@ -36,7 +36,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_sapconf=true diff --git a/data/sles4sap/qe_sap_deployment/qesap_azure.yaml b/data/sles4sap/qe_sap_deployment/qesap_azure.yaml index d98efdda8380..9187646b8e38 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_azure.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_azure.yaml @@ -35,7 +35,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_reboottimeout=900 diff --git a/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_msi.yaml b/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_msi.yaml index 4eeab231bc5e..09e5289f13d9 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_msi.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_msi.yaml @@ -38,7 +38,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_reboottimeout=900 diff --git a/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_spn.yaml b/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_spn.yaml index ccf55f31d8a7..30a5cd8cf2aa 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_spn.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_azure_fencing_spn.yaml @@ -38,7 +38,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_reboottimeout=900 diff --git a/data/sles4sap/qe_sap_deployment/qesap_azure_ltss.yaml b/data/sles4sap/qe_sap_deployment/qesap_azure_ltss.yaml deleted file mode 100644 index 9f58712925e8..000000000000 --- a/data/sles4sap/qe_sap_deployment/qesap_azure_ltss.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# SUSE's openQA tests -# -# Copyright SUSE LLC -# SPDX-License-Identifier: FSFAP -# Maintainer: QE-SAP -# Summary: Generic yaml template for use with qe-sap-deployment project: https://github.com/SUSE/qe-sap-deployment -provider: 'azure' -apiver: 3 -terraform: - variables: - az_region: '%REGION%' - deployment_name: '%DEPLOYMENTNAME%' - os_image: '%OS_VER%' - public_key: '%SLES4SAP_PUBSSHKEY%' - hana_remote_python: '%ANSIBLE_REMOTE_PYTHON%' - iscsi_remote_python: '%ANSIBLE_REMOTE_PYTHON%' - vnet_address_range: '%VNET_ADDRESS_RANGE%' - subnet_address_range: '%SUBNET_ADDRESS_RANGE%' -ansible: - roles_path: '%ANSIBLE_ROLES%' - az_storage_account_name: '%HANA_ACCOUNT%' - az_container_name: '%HANA_CONTAINER%' - az_key_name: '%HANA_KEYNAME%' - hana_media: - - '%HANA_SAR%' - - '%HANA_CLIENT_SAR%' - - '%HANA_SAPCAR%' - hana_vars: - sap_hana_install_software_directory: /hana/shared/install - sap_hana_install_master_password: 'DoNotUseThisPassw0rd' - sap_hana_install_sid: 'HQ0' - sap_hana_install_instance_number: '00' - sap_domain: 'qe-test.example.com' - primary_site: 'goofy' - secondary_site: 'miky' - use_sap_hana_sr_angi: '%USE_SR_ANGI%' - create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' -e sles_modules='[{"key":"%SCC_LTSS_MODULE%","value":"%SCC_LTSS_REGCODE%"}]' - - fully-patch-system.yaml - - pre-cluster.yaml - - sap-hana-preconfigure.yaml -e use_reboottimeout=900 - - cluster_sbd_prep.yaml - - sap-hana-storage.yaml - - sap-hana-download-media.yaml - - sap-hana-install.yaml - - sap-hana-system-replication.yaml - - sap-hana-system-replication-hooks.yaml - - sap-hana-cluster.yaml - destroy: - - deregister.yaml diff --git a/data/sles4sap/qe_sap_deployment/qesap_azure_sapconf.yaml b/data/sles4sap/qe_sap_deployment/qesap_azure_sapconf.yaml index 775278cacf26..22f21c76e52d 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_azure_sapconf.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_azure_sapconf.yaml @@ -33,7 +33,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_sapconf=true -e use_reboottimeout=900 diff --git a/data/sles4sap/qe_sap_deployment/qesap_azure_uri.yaml b/data/sles4sap/qe_sap_deployment/qesap_azure_uri.yaml index 9f8541feea5e..82a184309e6c 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_azure_uri.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_azure_uri.yaml @@ -33,7 +33,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' -e use_suseconnect=%SUSECONNECT% + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_sapconf=%USE_SAPCONF% diff --git a/data/sles4sap/qe_sap_deployment/qesap_gcp.yaml b/data/sles4sap/qe_sap_deployment/qesap_gcp.yaml index 504f1c414855..d01e7208d8bb 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_gcp.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_gcp.yaml @@ -38,7 +38,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml diff --git a/data/sles4sap/qe_sap_deployment/qesap_gcp_fencing.yaml b/data/sles4sap/qe_sap_deployment/qesap_gcp_fencing.yaml index 2241fa01654d..bc588c3eef18 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_gcp_fencing.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_gcp_fencing.yaml @@ -40,7 +40,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml diff --git a/data/sles4sap/qe_sap_deployment/qesap_gcp_sapconf.yaml b/data/sles4sap/qe_sap_deployment/qesap_gcp_sapconf.yaml index 31123218b815..f7760a222044 100644 --- a/data/sles4sap/qe_sap_deployment/qesap_gcp_sapconf.yaml +++ b/data/sles4sap/qe_sap_deployment/qesap_gcp_sapconf.yaml @@ -38,7 +38,7 @@ ansible: secondary_site: 'miky' use_sap_hana_sr_angi: '%USE_SR_ANGI%' create: - - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' + - %REGISTRATION_PLAYBOOK%.yaml -e reg_code='%SCC_REGCODE_SLES4SAP%' -e email_address='testing@suse.com' %REG_ARGS% - fully-patch-system.yaml - pre-cluster.yaml - sap-hana-preconfigure.yaml -e use_sapconf=true diff --git a/lib/qesapdeployment.pm b/lib/qesapdeployment.pm index b798bb26b856..a40c3e4b6b73 100644 --- a/lib/qesapdeployment.pm +++ b/lib/qesapdeployment.pm @@ -69,6 +69,8 @@ our @EXPORT = qw( qesap_ansible_script_output_file qesap_ansible_script_output qesap_ansible_fetch_file + qesap_ansible_reg_module + qesap_ansible_error_detection qesap_create_ansible_section qesap_remote_hana_public_ips qesap_wait_for_ssh @@ -105,7 +107,6 @@ our @EXPORT = qw( qesap_az_list_container_files qesap_az_diagnostic_log qesap_terrafom_ansible_deploy_retry - qesap_ansible_error_detection qesap_test_postfail ); @@ -1135,6 +1136,37 @@ sub qesap_ansible_fetch_file { return $args{out_path} . $args{file}; } +=head3 qesap_ansible_reg_module + + Compose the ansible-playbook argument for the registration.yaml playbook, + about an additional module registration + + -e sles_modules='[{"key":"SLES-LTSS-Extended-Security/12.5/x86_64","value":"*******"}]' + + Known limitation is that registration.yaml supports multiple modules to be registered, + this code only supports one. + +=over +=item B - name and reg_code for the additional extension to register. + This argument is a two element comma separated list string. + Like: 'SLES-LTSS-Extended-Security/12.5/x86_64,123456789' + First string before the comma has to be a valid SCC extension name, later used by Ansible + as argument for SUSEConnect or registercloudguest argument. + Second string has to be valid registration code for the particular extension. + +=back +=cut + +sub qesap_ansible_reg_module { + my (%args) = @_; + croak 'Missing mandatory "reg" argument' unless $args{reg}; + my @reg_args = split(/,/, $args{reg}); + die "Missing reg_code for '$reg_args[0]'" if (@reg_args != 2); + return "-e sles_modules='[{" . + "\"key\":\"$reg_args[0]\"," . + "\"value\":\"$reg_args[1]\"}]'"; +} + =head3 qesap_create_aws_credentials Creates a AWS credentials file as required by QE-SAP Terraform deployment code. diff --git a/lib/sles4sap_publiccloud.pm b/lib/sles4sap_publiccloud.pm index 2646d998f6f4..6589765059dc 100644 --- a/lib/sles4sap_publiccloud.pm +++ b/lib/sles4sap_publiccloud.pm @@ -909,13 +909,6 @@ sub delete_network_peering { =item B - name of the container for PTF files (optional) -=item B - name and reg_code for LTSS extension to register. - This argument is a two element comma separated list string. - Like: 'SLES-LTSS-Extended-Security/12.5/x86_64,123456789' - First string before the comma has to be a valid SCC extension name, later used by Ansible - as argument for SUSEConnect or registercloudguest argument. - Second string has to be valid registration code for the particular LTSS extension. - =back =cut @@ -941,13 +934,7 @@ sub create_playbook_section_list { my @reg_args = ('registration.yaml'); push @reg_args, "-e reg_code=$args{scc_code} -e email_address=''"; push @reg_args, '-e use_suseconnect=true' if ($args{registration} eq 'suseconnect'); - if ($args{ltss}) { - my @ltss_args = split(/,/, $args{ltss}); - die "Missing reg_code for '$ltss_args[0]'" if scalar @ltss_args != 2; - push @reg_args, "-e sles_modules='[{" . - "\"key\":\"$ltss_args[0]\"," . - "\"value\":\"$ltss_args[1]\"}]'"; - } + push @reg_args, qesap_ansible_reg_module(reg => $args{ltss}) if ($args{ltss}); # Add registration module as first element push @playbook_list, join(' ', @reg_args); diff --git a/t/14_qesap_ansible.t b/t/14_qesap_ansible.t index 7b029e16c263..cfcf322c3919 100644 --- a/t/14_qesap_ansible.t +++ b/t/14_qesap_ansible.t @@ -519,4 +519,17 @@ subtest '[qesap_ansible_fetch_file] integration' => sub { 'The default local file path is /tmp/ansible_script_output/testout.txt'); }; +subtest '[qesap_ansible_reg_module]' => sub { + my $ret = qesap_ansible_reg_module(reg => 'CRAB,ALGAE'); + note("ret:$ret"); + ok($ret eq "-e sles_modules='[{\"key\":\"CRAB\",\"value\":\"ALGAE\"}]'"); +}; + +subtest '[qesap_ansible_reg_module] wrong arguments' => sub { + dies_ok { qesap_ansible_reg_module() } "Missing argument"; + dies_ok { qesap_ansible_reg_module(reg => '') } "Empty argument"; + dies_ok { qesap_ansible_reg_module(reg => 'CRAB') } "Only one argument instead of exactly 2"; + dies_ok { qesap_ansible_reg_module(reg => 'CRAB,ALGAE,SPONGE') } "Too much arguments"; +}; + done_testing; diff --git a/tests/sles4sap/publiccloud/qesap_terraform.pm b/tests/sles4sap/publiccloud/qesap_terraform.pm index e87e5ce08758..a4db7476238a 100644 --- a/tests/sles4sap/publiccloud/qesap_terraform.pm +++ b/tests/sles4sap/publiccloud/qesap_terraform.pm @@ -178,7 +178,7 @@ sub run { } $playbook_configs{scc_code} = get_required_var('SCC_REGCODE_SLES4SAP') if ($os_image_name =~ 'byos'); - my @addons = grep { defined $_ && $_ } split(/,/, get_var('SCC_ADDONS')); + my @addons = split(/,/, get_var('SCC_ADDONS', '')); # This implementation has a known limitation # if SCC_ADDONS has two or more elements (like "ltss,ltss_es") # only the last one will be added to the playbook argument. @@ -188,7 +188,6 @@ sub run { # it simplify version calculation. $name = get_addon_fullname($addon) if ($addon =~ 'ltss'); if ($name) { - record_info($name, "Register '$name' with code '$ADDONS_REGCODE{$name}'"); $playbook_configs{ltss} = join(',', join('/', $name, scc_version(), 'x86_64'), $ADDONS_REGCODE{$name}); $playbook_configs{registration} = 'suseconnect' if ($os_image_name =~ 'byos' && $reg_mode !~ 'noreg'); } diff --git a/tests/sles4sap/qesapdeployment/configure.pm b/tests/sles4sap/qesapdeployment/configure.pm index 1ab9e79a82e4..e51959617dc4 100644 --- a/tests/sles4sap/qesapdeployment/configure.pm +++ b/tests/sles4sap/qesapdeployment/configure.pm @@ -11,6 +11,7 @@ use publiccloud::azure_client; use publiccloud::utils qw(get_ssh_private_key_path); use testapi; use serial_terminal 'select_serial_terminal'; +use registration qw(get_addon_fullname scc_version %ADDONS_REGCODE); use qesapdeployment; sub run { @@ -47,7 +48,25 @@ sub run { $variables{SLES4SAP_PUBSSHKEY} = get_ssh_private_key_path() . '.pub'; $variables{REGISTRATION_PLAYBOOK} = get_var('QESAPDEPLOY_REGISTRATION_PLAYBOOK', 'registration'); $variables{REGISTRATION_PLAYBOOK} =~ s/\.yaml$//; - $variables{SUSECONNECT} = get_var('QESAPDEPLOY_USE_SUSECONNECT', 'false'); + + my $reg_args; + $reg_args = "-e use_suseconnect=true " if (get_var('QESAPDEPLOY_USE_SUSECONNECT')); + my @addons = split(/,/, get_var('SCC_ADDONS', '')); + # This implementation has a known limitation + # if SCC_ADDONS has two or more elements (like "ltss,ltss_es") + # only the first one will be added to the playbook argument. + foreach my $addon (@addons) { + my $name; + # Keep the code simple by only support ltss addons, + # it simplifies version calculation. + $name = get_addon_fullname($addon) if ($addon =~ 'ltss'); + if ($name) { + $reg_args .= qesap_ansible_reg_module(reg => join(',', join('/', $name, scc_version(), 'x86_64'), $ADDONS_REGCODE{$name})); + # exit from the addons loop not to pack on the playbook command line more than one "-e sles_module" + last; + } + } + $variables{REG_ARGS} = $reg_args; # Only BYOS images needs it $variables{SCC_REGCODE_SLES4SAP} = get_var('SCC_REGCODE_SLES4SAP', '');