Skip to content

Commit 4564730

Browse files
authored
Merge pull request #25963 from lilyeyes/fix-sdaf-iscisi-img-version
Use the same public cloud image in one test case
2 parents 92f95a7 + d0c1c8d commit 4564730

3 files changed

Lines changed: 85 additions & 61 deletions

File tree

lib/sles4sap/sap_deployment_automation_framework/configure_sap_systems_tfvars.pm

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Carp qw(croak);
1414
use utils qw(write_sut_file);
1515
use sles4sap::sap_deployment_automation_framework::deployment
1616
qw(get_os_variable validate_components get_fencing_mechanism);
17-
use sles4sap::sap_deployment_automation_framework::configure_workload_tfvars qw(write_tfvars_file get_tags_entry);
17+
use sles4sap::sap_deployment_automation_framework::configure_workload_tfvars qw(write_tfvars_file get_tags_entry define_vm_images);
1818
use sles4sap::sap_deployment_automation_framework::naming_conventions
1919
qw(generate_resource_group_name get_sizing_filename convert_region_to_short);
2020

@@ -404,58 +404,4 @@ sub define_nfs_settings {
404404
return (\%result);
405405
}
406406

407-
=head2 define_vm_images
408-
409-
define_vm_images(os_image=>'suse:sles-sap-15-sp5:gen2:latest');
410-
411-
VM OS image tfvars setting definition. Currently all VMs use the same OS image. Both BYOS and PAYG images can be used.
412-
B<Example:> {source_image_id : '"suse:sles-sap-15-sp5:gen2:latest"', publisher : '"SUSE"' ... }
413-
Pay attention to double quoting strings. They are very important in resulting file.
414-
415-
=over
416-
417-
=item * B<os_image>: BYOS or PAYG image ID.
418-
419-
=back
420-
421-
=cut
422-
423-
sub define_vm_images {
424-
my (%args) = @_;
425-
croak 'Missing mandatory argument $args{os_image}' unless $args{os_image};
426-
my $type;
427-
my $publisher;
428-
my $offer;
429-
my $sku;
430-
my $version;
431-
432-
# This regex targets the general Azure Gallery image naming patterns,
433-
# excluding part of the name that are related to PC library.
434-
if ($args{os_image} =~ /^\/subscriptions\/.*\/galleries\/.*/) {
435-
$type = 'custom';
436-
($publisher, $offer, $sku, $version) = ''; # Those can't be undef
437-
}
438-
else {
439-
# Parse image ID supplied by OpenQA parameter 'PUBLIC_CLOUD_IMAGE_ID'
440-
($publisher, $offer, $sku, $version) = split(':', $args{os_image});
441-
$type = 'marketplace';
442-
}
443-
444-
my %result = (
445-
header => '### VM images ###'
446-
);
447-
for my $component ('database_vm_image', 'scs_server_image', 'application_server_image') {
448-
$result{$component} = <<"END";
449-
{ os_type = "LINUX",
450-
source_image_id = "$args{os_image}",
451-
publisher = "$publisher",
452-
offer = "$offer",
453-
sku = "$sku",
454-
version = "$version",
455-
type = "$type"
456-
}
457-
END
458-
}
459-
460-
return (\%result);
461-
}
407+
1;

lib/sles4sap/sap_deployment_automation_framework/configure_workload_tfvars.pm

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ use sles4sap::sap_deployment_automation_framework::deployment_connector qw(find_
2222
Library with common functions for Microsoft SDAF deployment automation that help with preparation of
2323
'WORKLOAD-ZONE' tfvars file.
2424
Generated file is following example template:
25-
https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/SYSTEM/LAB-SECE-SAP04-L00/LAB-SECE-SAP04-L00.tfvars
25+
https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/LANDSCAPE/LAB-SECE-SAP04-INFRASTRUCTURE/LAB-SECE-SAP04-INFRASTRUCTURE.tfvars
2626
2727
=cut
2828

2929
our @EXPORT = qw(
3030
create_workload_tfvars
3131
write_tfvars_file
3232
get_tags_entry
33+
define_vm_images
3334
);
3435

3536
=head2 write_tfvars_file
@@ -137,6 +138,8 @@ Content is generated in perl and transformed into tfvars format. File is uploade
137138
138139
=item * B<workload_vnet_code>: Workload zone VNET code
139140
141+
=item * B<os_image>: BYOS or PAYG image ID. For example: 'suse:sles-sap-15-sp7:gen2:latest'
142+
140143
=back
141144
142145
=cut
@@ -149,14 +152,14 @@ sub create_workload_tfvars {
149152
my $vnet_code = get_required_var('SDAF_DEPLOYER_VNET_CODE');
150153

151154
# Mandatory arguments
152-
for my $arg ('network_data', 'workload_vnet_code') {
155+
for my $arg ('network_data', 'workload_vnet_code', 'os_image') {
153156
croak("Missing mandatory argument \$args{$arg}") unless $args{$arg};
154157
}
155158

156159
# Generate tfvars file data
157160
my $tfvars_file = get_os_variable('workload_zone_parameter_file');
158161
my %tfvars_data;
159-
$tfvars_data{file_header} = "### File was generated by OpenQA automation according to template:\n### https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/SYSTEM/LAB-SECE-SAP04-L00/LAB-SECE-SAP04-L00.tfvars\n";
162+
$tfvars_data{file_header} = "### File was generated by OpenQA automation according to template:\n### https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/LANDSCAPE/LAB-SECE-SAP04-INFRASTRUCTURE/LAB-SECE-SAP04-INFRASTRUCTURE.tfvars\n";
160163
$tfvars_data{env_definitions} = define_workload_environment(
161164
environment => $env_code,
162165
location => $location,
@@ -176,6 +179,8 @@ sub create_workload_tfvars {
176179
workload_vnet_code => $args{workload_vnet_code});
177180
$tfvars_data{iscsi_devices} = define_iscsi_devices();
178181
$tfvars_data{storage_account} = define_storage_account();
182+
# Defines the Virtual Machine image for the iSCSI devices
183+
$tfvars_data{iscsi_image} = define_vm_images(os_image => $args{os_image}, deployment_type => 'workload_zone');
179184

180185
# Write file and upload to OpenQA logs
181186
write_tfvars_file(tfvars_data => \%tfvars_data, tfvars_file => $tfvars_file);
@@ -422,3 +427,66 @@ sub define_storage_account {
422427

423428
return (\%result);
424429
}
430+
431+
=head2 define_vm_images
432+
433+
define_vm_images(os_image=>'suse:sles-sap-15-sp5:gen2:latest');
434+
435+
VM OS image tfvars setting definition. Currently all VMs use the same OS image. Both BYOS and PAYG images can be used.
436+
B<Example:> {source_image_id : '"suse:sles-sap-15-sp5:gen2:latest"', publisher : '"SUSE"' ... }
437+
Pay attention to double quoting strings. They are very important in resulting file.
438+
439+
=over
440+
441+
=item * B<os_image>: BYOS or PAYG image ID.
442+
443+
=item * B<deployment_type>: deployment type: optional argument; 'workload_zone' or 'sap_system'; default is 'sap_system'.
444+
445+
=back
446+
447+
=cut
448+
449+
sub define_vm_images {
450+
my (%args) = @_;
451+
$args{deployment_type} //= 'sap_system';
452+
croak 'Missing mandatory argument $args{os_image}' unless $args{os_image};
453+
my $type;
454+
my $publisher;
455+
my $offer;
456+
my $sku;
457+
my $version;
458+
459+
# This regex targets the general Azure Gallery image naming patterns,
460+
# excluding part of the name that are related to PC library.
461+
if ($args{os_image} =~ /^\/subscriptions\/.*\/galleries\/.*/) {
462+
$type = 'custom';
463+
($publisher, $offer, $sku, $version) = ('', '', '', ''); # Those can't be undef
464+
}
465+
else {
466+
# Parse image ID supplied by OpenQA parameter 'PUBLIC_CLOUD_IMAGE_ID'
467+
($publisher, $offer, $sku, $version) = split(':', $args{os_image});
468+
$type = 'marketplace';
469+
}
470+
471+
my %result = (
472+
header => '### VM images ###'
473+
);
474+
my @components = ('database_vm_image', 'scs_server_image', 'application_server_image');
475+
@components = ('iscsi_image') if ($args{deployment_type} eq 'workload_zone');
476+
for my $component (@components) {
477+
$result{$component} = <<"END";
478+
{ os_type = "LINUX",
479+
source_image_id = "$args{os_image}",
480+
publisher = "$publisher",
481+
offer = "$offer",
482+
sku = "$sku",
483+
version = "$version",
484+
type = "$type"
485+
}
486+
END
487+
}
488+
489+
return (\%result);
490+
}
491+
492+
1;

tests/sles4sap/sap_deployment_automation_framework/deploy_workload_zone.pm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Maintainer: QE-SAP <qe-sap@suse.de>
66
# Summary: Deployment of the workload zone using SDAF automation
77

8-
use Mojo::Base 'sles4sap::sap_deployment_automation_framework::basetest';
8+
use Mojo::Base qw(sles4sap::sap_deployment_automation_framework::basetest publiccloud::basetest);
99

1010
use sles4sap::sap_deployment_automation_framework::deployment;
1111
use sles4sap::sap_deployment_automation_framework::naming_conventions;
@@ -22,6 +22,7 @@ sub test_flags {
2222
}
2323

2424
sub run {
25+
my ($self) = @_;
2526
# Skip module if existing deployment is being re-used
2627
return if sdaf_deployment_reused();
2728

@@ -32,6 +33,15 @@ sub run {
3233
connect_target_to_serial();
3334
load_os_env_variables();
3435

36+
my $os;
37+
# This section is only needed by Azure tests using images uploaded
38+
if (get_var('PUBLIC_CLOUD_IMAGE_LOCATION')) {
39+
my $provider = $self->provider_factory();
40+
$os = $self->{provider}->get_image_id();
41+
} else {
42+
$os = get_required_var('PUBLIC_CLOUD_IMAGE_ID');
43+
}
44+
3545
my $workload_vnet_code = get_workload_vnet_code();
3646
set_var('SDAF_VNET_CODE', $workload_vnet_code);
3747
# 'vnet_code' variable changes with deployment type.
@@ -60,7 +70,7 @@ sub run {
6070
set_var(uc($variable_name), $network_data{$variable_name});
6171
}
6272

63-
create_workload_tfvars(network_data => \%network_data, workload_vnet_code => $workload_vnet_code);
73+
create_workload_tfvars(network_data => \%network_data, workload_vnet_code => $workload_vnet_code, os_image => $os);
6474

6575
az_login();
6676
sdaf_execute_deployment(

0 commit comments

Comments
 (0)