Skip to content

Commit

Permalink
Create PC lib classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lpalovsky committed Nov 13, 2024
1 parent d8a8b1d commit 2849dc0
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use YAML::PP;
use testapi;
use Exporter qw(import);
use Carp qw(croak);
use publiccloud::azure;
use sles4sap::sap_deployment_automation_framework::naming_conventions qw(deployer_private_key_path sut_private_key_path);
use sles4sap::console_redirection;

Expand Down Expand Up @@ -60,6 +61,7 @@ our @EXPORT = qw(
read_inventory_file
prepare_ssh_config
verify_ssh_proxy_connection
sdaf_create_instances
);

=head2 read_inventory_file
Expand Down Expand Up @@ -230,3 +232,42 @@ sub verify_ssh_proxy_connection {
}
}
}

=head2 sdaf_create_instances
sdaf_create_instances( inventory_content=>HASHREF);
Creates and returns B<$instances> class which is a main component of F<lib/sles4sap_publiccloud.pm> and
general public cloud libraries F</lib/publiccloud/*>.
=over
=item * B<inventory_content> Referenced content of the inventory yaml file
=back
=cut

sub sdaf_create_instances {
my (%args) = @_;
my $provider = publiccloud::azure->new();
my @instances = ();

for my $instance_type (keys(%{$args{inventory_content}})) {
my $hosts = $args{inventory_content}->{$instance_type}{hosts};
for my $physical_host (keys %$hosts) {
my $instance = publiccloud::instance->new(
public_ip => $hosts->{$physical_host}->{ansible_host},
instance_id => $physical_host,
username => $hosts->{$physical_host}->{ansible_user},
ssh_key => $args{sut_ssh_key_path},
provider => $provider,
region => get_required_var('PUBLIC_CLOUD_REGION')
);
push(@instances, $instance);
}
}
use Data::Dumper;
record_info('Instance', Dumper(\@instances));
publiccloud::instances::set_instances(@instances);
return \@instances;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ schedule:
- sles4sap/sap_deployment_automation_framework/configure_deployer
- sles4sap/sap_deployment_automation_framework/deploy_workload_zone
- sles4sap/sap_deployment_automation_framework/deploy_sap_systems
- sles4sap/sap_deployment_automation_framework/deploy_hanasr
#- sles4sap/sap_deployment_automation_framework/deploy_hanasr
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ schedule:
- boot/boot_to_desktop
- sles4sap/sap_deployment_automation_framework/connect_to_deployer
- sles4sap/sap_deployment_automation_framework/prepare_ssh_config
- sles4sap/sap_deployment_automation_framework/cleanup
- sles4sap/sap_deployment_automation_framework/publiccloud_lib_compatibility_layer
#- sles4sap/sap_deployment_automation_framework/cleanup
72 changes: 38 additions & 34 deletions t/29_sdaf_inventory_tools.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ use testapi;
use sles4sap::sap_deployment_automation_framework::inventory_tools;
use Data::Dumper;

my $mock_inventory_data = {
'QES_PAS' => {
'hosts' => {
'Freddie' => {
'ansible_connection' => 'ssh',
'connection_type' => 'key',
'virtual_host' => 'Mercury',
'ansible_user' => 'freddie',
'vm_name' => 'FreddieMercury',
'become_user' => 'root',
'ansible_host' => '10.10.10.2',
'os_type' => 'linux'
}
},
'vars' => undef
},
'QES_DB' => {
'vars' => undef,
'hosts' => {
'John' => {
'ansible_connection' => 'ssh',
'connection_type' => 'key',
'virtual_host' => 'Deacon',
'ansible_user' => 'john',
'vm_name' => 'JohnDeacon',
'become_user' => 'john',
'ansible_host' => '10.10.10.3',
'os_type' => 'linux'
}
}
}
};

subtest '[prepare_ssh_config] ' => sub {
my $mock = Test::MockModule->new('sles4sap::sap_deployment_automation_framework::inventory_tools', no_auto => 1);
Expand Down Expand Up @@ -44,39 +76,6 @@ subtest '[prepare_ssh_config] ' => sub {
$db_host_B_content = join(' ', @_) if join(' ', @_) =~ /entry_name Freddie/;
return; });

my $mock_inventory_data = {
'QES_PAS' => {
'hosts' => {
'Freddie' => {
'ansible_connection' => 'ssh',
'connection_type' => 'key',
'virtual_host' => 'Mercury',
'ansible_user' => 'freddie',
'vm_name' => 'FreddieMercury',
'become_user' => 'root',
'ansible_host' => '10.10.10.2',
'os_type' => 'linux'
}
},
'vars' => undef
},
'QES_DB' => {
'vars' => undef,
'hosts' => {
'John' => {
'ansible_connection' => 'ssh',
'connection_type' => 'key',
'virtual_host' => 'Deacon',
'ansible_user' => 'john',
'vm_name' => 'JohnDeacon',
'become_user' => 'john',
'ansible_host' => '10.10.10.3',
'os_type' => 'linux'
}
}
}
};

prepare_ssh_config(inventory_data => $mock_inventory_data, jump_host_ip => '127.0.0.1', jump_host_user => 'Freddie');
note("\n --> $jump_config_content");
ok($jump_config_content =~ /entry_name deployer_jump/, 'Jump host: entry_name');
Expand All @@ -102,9 +101,14 @@ subtest '[prepare_ssh_config] ' => sub {
ok($db_host_B_content =~ /identity_file ~\/.ssh\/sut_id_rsa/, 'DB host A: identity_file');
ok($db_host_B_content =~ /proxy_jump deployer_jump/, 'DB host A: proxy_jump');
ok($db_host_B_content =~ /strict_host_key_checking no/, 'DB host A: strict_host_key_checking');
};

subtest '[sdaf_create_instances] ' => sub {
my $mock = Test::MockModule->new('sles4sap::sap_deployment_automation_framework::inventory_tools', no_auto => 1);
$mock->redefine(record_info => sub { note("\n --> " . join("\n --> ", @_)); return; });
set_var('PUBLIC_CLOUD_REGION', 'swedencentral');
my $instances = sdaf_create_instances(inventory_content=>$mock_inventory_data);

};


done_testing;
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
# Summary: Executes setup of HanaSR scenario using SDAF ansible playbooks according to:
# https://learn.microsoft.com/en-us/azure/sap/automation/tutorial#sap-application-installation

use base 'sles4sap_publiccloud_basetest';
use parent 'sles4sap::sap_deployment_automation_framework::basetest';

use warnings;
use strict;
use testapi;
use serial_terminal qw(select_serial_terminal);
use sles4sap::console_redirection;
use sles4sap_publiccloud;
use sles4sap::azure_cli qw(az_keyvault_list);
use sles4sap::sap_deployment_automation_framework::inventory_tools;
use sles4sap::sap_deployment_automation_framework::deployment qw(sdaf_ssh_key_from_keyvault);
use sles4sap::sap_deployment_automation_framework::naming_conventions
qw(get_sdaf_inventory_path convert_region_to_short get_workload_vnet_code sut_private_key_path generate_resource_group_name);

sub test_flags {
return {fatal => 1, publiccloud_multi_module => 1};
}

sub run {
my ($self, $run_args) = @_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SUSE's openQA tests

Check failure on line 1 in tests/sles4sap/sap_deployment_automation_framework/publiccloud_lib_compatibility_layer.pm

View workflow job for this annotation

GitHub Actions / CI: Running static tests with perl v5.32

File tests/sles4sap/sap_deployment_automation_framework/publiccloud_lib_compatibility_layer.pm needs tidying
#
# Copyright SUSE LLC
# SPDX-License-Identifier: FSFAP
# Maintainer: QE-SAP <[email protected]>
# Summary: Prepares compatibility layer for using `lib/publiccloud/` library with SDAF deployment

use parent 'sles4sap::sap_deployment_automation_framework::basetest';

use warnings;
use strict;
use testapi;
use serial_terminal qw(select_serial_terminal);
use sles4sap::console_redirection qw(connect_target_to_serial disconnect_target_from_serial);
use sles4sap::sap_deployment_automation_framework::inventory_tools qw(read_inventory_file sdaf_create_instances);
use sles4sap::sap_deployment_automation_framework::naming_conventions
qw(get_sdaf_inventory_path convert_region_to_short get_workload_vnet_code);
sub run {
my ($self, $run_args) = @_;
select_serial_terminal;

my $inventory_path = get_sdaf_inventory_path(
env_code => get_required_var('SDAF_ENV_CODE'),
sdaf_region_code => convert_region_to_short(get_required_var('PUBLIC_CLOUD_REGION')),
vnet_code => get_workload_vnet_code(),
sap_sid => get_required_var('SAP_SID')
);

# Connect serial to Deployer VM to get inventory file
connect_target_to_serial();
my $inventory_data = read_inventory_file($inventory_path);
# From now on all commands will be executed on worker VM
disconnect_target_from_serial();

my $instances = $self->{instances} = sdaf_create_instances(inventory_content=>$inventory_data);
for my $instance (@$instances) {
$self->{my_instance} = $instance;
$instance->wait_for_ssh();
}
}

1;

0 comments on commit 2849dc0

Please sign in to comment.