diff --git a/lib/sles4sap/sap_deployment_automation_framework/configure_tfvars.pm b/lib/sles4sap/sap_deployment_automation_framework/configure_tfvars.pm index 693a410cd571..e5edb67f2542 100644 --- a/lib/sles4sap/sap_deployment_automation_framework/configure_tfvars.pm +++ b/lib/sles4sap/sap_deployment_automation_framework/configure_tfvars.pm @@ -144,12 +144,17 @@ sub set_image_parameters { my @variable_names = qw(SDAF_IMAGE_PUBLISHER SDAF_IMAGE_OFFER SDAF_IMAGE_SKU SDAF_IMAGE_VERSION); # This maps a variable name from array @variable names to value from delimited 'PUBLIC_CLOUD_IMAGE_ID' parameter # Order is important here - @params{@variable_names} = split(':', get_required_var('PUBLIC_CLOUD_IMAGE_ID')); # Add all remaining parameters with static values $params{SDAF_IMAGE_OS_TYPE} = 'LINUX'; # this can be modified in case of non linux images - $params{SDAF_SOURCE_IMAGE_ID} = ''; # for supplying uploaded image - not implemented yet - $params{SDAF_IMAGE_TYPE} = 'marketplace'; + if (get_var('PUBLIC_CLOUD_IMAGE_LOCATION')) { + $params{SDAF_SOURCE_IMAGE_ID} = get_required_var('SDAF_SOURCE_IMAGE_ID'); # for supplying uploaded image + $params{SDAF_IMAGE_TYPE} = 'custom'; + } + else { + @params{@variable_names} = split(':', get_required_var('PUBLIC_CLOUD_IMAGE_ID')); + $params{SDAF_IMAGE_TYPE} = 'marketplace'; + } foreach (keys(%params)) { set_var($_, $params{$_}); diff --git a/lib/sles4sap/sap_deployment_automation_framework/deployment.pm b/lib/sles4sap/sap_deployment_automation_framework/deployment.pm index 0cb1b3eff138..5cc2fd405223 100644 --- a/lib/sles4sap/sap_deployment_automation_framework/deployment.pm +++ b/lib/sles4sap/sap_deployment_automation_framework/deployment.pm @@ -45,6 +45,7 @@ our @EXPORT = qw( load_os_env_variables sdaf_cleanup sdaf_execute_playbook + ansible_execute_command ansible_show_status playbook_settings $output_log_file @@ -893,6 +894,8 @@ Execute command on host group using ansible. Returns execution output. =item * B: Command to be executed +=item * B: verbose ansible output + =back =cut @@ -903,9 +906,10 @@ sub ansible_execute_command { my @cmd = ('ansible', $args{host_group}, "--private-key=$args{sdaf_config_root_dir}/sshkey", "--inventory=$args{sap_sid}_hosts.yaml", + $args{verbose} ? '-vvv' : '', '--module-name=shell'); - return script_output(join(' ', @cmd, "--args=\"$args{command}\"", '2> /dev/null')); + return script_output(join(' ', @cmd, "--args=\"$args{command}\"")); } =head2 playbook_settings diff --git a/t/27_sdaf_configure_tfvars.t b/t/27_sdaf_configure_tfvars.t index 9907a8f4cc7a..dc145182988d 100644 --- a/t/27_sdaf_configure_tfvars.t +++ b/t/27_sdaf_configure_tfvars.t @@ -68,6 +68,8 @@ subtest '[set_image_parameters]' => sub { $ms_sdaf->redefine(data_url => sub { return 'capuccino'; }); $ms_sdaf->redefine(validate_components => sub { return 'mocha'; }); + set_var('PUBLIC_CLOUD_IMAGE_LOCATION', ''); + set_var('SDAF_SOURCE_IMAGE_ID', ''); set_var('PUBLIC_CLOUD_IMAGE_ID', 'suse:sles-sap-15-sp6:gen2:latest'); prepare_tfvars_file(deployment_type => 'sap_system'); diff --git a/tests/sles4sap/sap_deployment_automation_framework/deploy_sap_systems.pm b/tests/sles4sap/sap_deployment_automation_framework/deploy_sap_systems.pm index 9a4ca407681d..8e22f2c48065 100644 --- a/tests/sles4sap/sap_deployment_automation_framework/deploy_sap_systems.pm +++ b/tests/sles4sap/sap_deployment_automation_framework/deploy_sap_systems.pm @@ -6,6 +6,7 @@ # Summary: Deployment of the SAP systems zone using SDAF automation use parent 'sles4sap::sap_deployment_automation_framework::basetest'; +use Mojo::Base 'publiccloud::basetest'; use strict; use warnings; @@ -58,6 +59,8 @@ sub test_flags { } sub run { + my ($self) = @_; + serial_console_diag_banner('Module sdaf_deploy_sap_systems.pm : start'); select_serial_terminal(); my $env_code = get_required_var('SDAF_ENV_CODE'); @@ -75,6 +78,11 @@ sub run { load_os_env_variables(); my @installed_components = split(',', get_required_var('SDAF_DEPLOYMENT_SCENARIO')); + # This section is only needed by Azure tests using images uploaded + if (get_var('PUBLIC_CLOUD_IMAGE_LOCATION')) { + my $provider = $self->provider_factory(); + set_var('SDAF_SOURCE_IMAGE_ID', $self->{provider}->get_blob_uri(get_var('PUBLIC_CLOUD_IMAGE_LOCATION'))); + } prepare_tfvars_file(deployment_type => 'sap_system', components => \@installed_components); # Custom VM sizing since default VMs are way too large for functional testing diff --git a/tests/sles4sap/sap_deployment_automation_framework/execute_playbooks.pm b/tests/sles4sap/sap_deployment_automation_framework/execute_playbooks.pm index 11a7e7405221..3e613a94eaea 100644 --- a/tests/sles4sap/sap_deployment_automation_framework/execute_playbooks.pm +++ b/tests/sles4sap/sap_deployment_automation_framework/execute_playbooks.pm @@ -11,12 +11,12 @@ use parent 'sles4sap::sap_deployment_automation_framework::basetest'; use strict; use warnings; use sles4sap::sap_deployment_automation_framework::deployment; -use sles4sap::sap_deployment_automation_framework::naming_conventions - qw(get_sdaf_config_path convert_region_to_short get_workload_vnet_code); +use sles4sap::sap_deployment_automation_framework::naming_conventions qw(get_sdaf_config_path convert_region_to_short get_workload_vnet_code); use sles4sap::console_redirection qw(connect_target_to_serial disconnect_target_from_serial); use sles4sap::sap_deployment_automation_framework::configure_tfvars qw(validate_components); use serial_terminal qw(select_serial_terminal); use testapi; +use publiccloud::utils 'is_byos'; =head1 SYNOPSIS @@ -68,8 +68,7 @@ sub run { vnet_code => get_workload_vnet_code(), env_code => get_required_var('SDAF_ENV_CODE'), sdaf_region_code => convert_region_to_short(get_required_var('PUBLIC_CLOUD_REGION')), - sap_sid => get_required_var('SAP_SID') - ); + sap_sid => get_required_var('SAP_SID')); # setup = combination of all components chosen for installation my @setup = split(/,/, get_required_var('SDAF_DEPLOYMENT_SCENARIO')); validate_components(components => \@setup); @@ -86,6 +85,27 @@ sub run { # Some playbooks use azure cli az_login(); + # Register SUTs before executing playbooks + if (is_byos() || get_var('PUBLIC_CLOUD_FORCE_REGISTRATION')) { + # Execute playbook 'pb_get-sshkey.yaml' for sshkey + $sles4sap::sap_deployment_automation_framework::basetest::serial_regexp_playbook = 1; + sdaf_execute_playbook(playbook_filename => 'pb_get-sshkey.yaml', timeout => 90, sdaf_config_root_dir => $sdaf_config_root_dir); + $sles4sap::sap_deployment_automation_framework::basetest::serial_regexp_playbook = 0; + + # Register SUTs + my $sap_sid = get_required_var('SAP_SID'); + my $scc_reg_code = get_required_var('SCC_REGCODE_SLES4SAP'); + assert_script_run("cd $sdaf_config_root_dir"); + record_info('Register SUTs'); + ansible_execute_command( + command => "sudo registercloudguest -r $scc_reg_code", + host_group => "${sap_sid}_DB", + sdaf_config_root_dir => "$sdaf_config_root_dir", + sap_sid => "$sap_sid", + verbose => 1 + ); + } + for my $playbook_options (@execute_playbooks) { $sles4sap::sap_deployment_automation_framework::basetest::serial_regexp_playbook = 1; sdaf_execute_playbook(%{$playbook_options}, sdaf_config_root_dir => $sdaf_config_root_dir);