Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTSS registration in HanaSR test #20642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions lib/sles4sap_publiccloud.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ use strict;
use JSON;
use warnings FATAL => 'all';
use Exporter 'import';
use Scalar::Util 'looks_like_number';
use Scalar::Util qw(looks_like_number);
use List::MoreUtils qw(uniq);
use Carp qw(croak);
use YAML::PP;
use testapi;
use utils qw(file_content_replace);
use serial_terminal qw(serial_term_prompt);
use version_utils qw(check_version);
use version_utils qw(check_version is_sle);
use hacluster;
use qesapdeployment;
use publiccloud::utils;
use publiccloud::provider;
use publiccloud::ssh_interactive 'select_host_console';
use publiccloud::ssh_interactive qw(select_host_console);
use publiccloud::instance;
use sles4sap;
use saputils;
use version_utils 'is_sle';

our @EXPORT = qw(
run_cmd
Expand Down Expand Up @@ -901,6 +900,13 @@ sub delete_network_peering {

=item B<ptf_container> - name of the container for PTF files (optional)

=item B<ltss> - 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

Expand All @@ -921,14 +927,19 @@ sub create_playbook_section_list {
my @playbook_list;

unless ($args{registration} eq 'noreg') {
# Add registration module as first element
my $reg_code = '-e reg_code=' . get_required_var('SCC_REGCODE_SLES4SAP') . " -e email_address=''";
if ($args{registration} eq 'suseconnect') {
push @playbook_list, "registration.yaml $reg_code -e use_suseconnect=true";
}
else {
push @playbook_list, "registration.yaml $reg_code";
my @reg_args = ('registration.yaml');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the command line composition for this playbook become more complex I decided to fit all argument in a list and then join them at the end

push @reg_args, '-e reg_code=' . get_required_var('SCC_REGCODE_SLES4SAP') . " -e email_address=''";
push @reg_args, '-e use_suseconnect=true' if ($args{registration} eq 'suseconnect');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to inline

if ($args{ltss}) {
my @ltss_args = split(/,/, $args{ltss});
Copy link
Contributor Author

@mpagot mpagot Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

die "Missing reg_code for '$ltss_args[0]'" if scalar @ltss_args != 2;
push @reg_args, "-e sles_modules='[{" .
"\"key\":\"$ltss_args[0]\"," .
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sles_modules= on the Ansible side, potentially supports multiple modules to be passed at once.

This implementation only support one.

[0] is the name of the extension
[1] is the registration code

"\"value\":\"$ltss_args[1]\"}]'";
}
# Add registration module as first element
push @playbook_list, join(' ', @reg_args);

# Add "fully patch system" module after registration module and before test start/configuration modules.
# Temporary moved inside noreg condition to avoid test without Ansible to fails.
# To be properly addressed in the caller and fully-patch-system can be placed back out of the if.
Expand Down
11 changes: 11 additions & 0 deletions t/12_sles4sap_publicccloud.t
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,17 @@ subtest '[create_playbook_section_list]' => sub {
};


subtest '[create_playbook_section_list] ltss' => sub {
set_var('SCC_REGCODE_SLES4SAP', 'Magellano');
set_var('USE_SAPCONF', 'Colombo');
my $ansible_playbooks = create_playbook_section_list(ltss => 'XuFu,Jofuku');
set_var('SCC_REGCODE_SLES4SAP', undef);
set_var('USE_SAPCONF', undef);
note("\n --> " . join("\n --> ", @$ansible_playbooks));
ok((any { /.*registration\.yaml.*sles_modules=.*key.*XuFu.*value.*Jofuku/ } @$ansible_playbooks), 'registration playbook is called with reg code from SCC_REGCODE_LTSS');
};


subtest '[create_playbook_section_list] ha_enabled => 0' => sub {
set_var('SCC_REGCODE_SLES4SAP', 'Magellano');
set_var('USE_SAPCONF', 'Colombo');
Expand Down
17 changes: 17 additions & 0 deletions tests/sles4sap/publiccloud/qesap_terraform.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use publiccloud::utils qw(is_azure is_gce get_ssh_private_key_path);
use sles4sap_publiccloud;
use qesapdeployment;
use serial_terminal 'select_serial_terminal';
use registration qw(get_addon_fullname scc_version %ADDONS_REGCODE);

our $ha_enabled = set_var_output('HA_CLUSTER', '0') =~ /false|0/i ? 0 : 1;

Expand Down Expand Up @@ -175,6 +176,22 @@ sub run {
$playbook_configs{spn_application_password} = get_var('AZURE_SPN_APP_PASSWORD', get_required_var('_SECRET_AZURE_SPN_APP_PASSWORD'));
}
}

my @addons = grep { defined $_ && $_ } 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.
foreach my $addon (@addons) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scan all extensions in SCC_ADDONS and only care about ltss, calculate SCC Extension name and reg code for it and pack them in the right format expected by ltss argument of create_playbook_section_list

my $name;
# Keep the code simple by only support ltss addons,
# it simplify version calculation.
$name = get_addon_fullname($addon) if ($addon =~ 'ltss');
alvarocarvajald marked this conversation as resolved.
Show resolved Hide resolved
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');
}
}
$ansible_playbooks = create_playbook_section_list(%playbook_configs);

my $ansible_hana_vars = create_hana_vars_section($ha_enabled);
Expand Down
Loading