Skip to content

Commit

Permalink
SDAF PC lib compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lpalovsky committed Nov 27, 2024
1 parent d4285c7 commit 364566a
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use Carp qw(croak);
use sles4sap::sap_deployment_automation_framework::naming_conventions
qw($deployer_private_key_path $sut_private_key_path);
use sles4sap::console_redirection;
use publiccloud::azure;

=head1 SYNOPSIS
Expand Down Expand Up @@ -61,6 +62,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 @@ -231,3 +233,45 @@ 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
=item * B<sut_ssh_key_path> Path to private key file allowing SSH connection to SUT
=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 @@ -5,5 +5,6 @@ description: |
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/publiccloud_lib_compatibility_layer
- sles4sap/publiccloud/hana_sr_schedule_replica_tests
- sles4sap/sap_deployment_automation_framework/cleanup
73 changes: 40 additions & 33 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 @@ -43,39 +75,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 Down Expand Up @@ -105,5 +104,13 @@ subtest '[prepare_ssh_config] ' => sub {

};

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, sut_ssh_key_path=>'/Mamaaa/I/Killed/a/maaan');

};

done_testing;
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ sub run {
# Base operating system configuration
{playbook_filename => 'playbook_01_os_base_config.yaml'},
# SAP-specific operating system configuration
{playbook_filename => 'playbook_02_os_sap_specific_config.yaml'},
#{playbook_filename => 'playbook_02_os_sap_specific_config.yaml'},
# SAP Bill of Materials processing - this also mounts install media storage
{playbook_filename => 'playbook_03_bom_processing.yaml'},
#{playbook_filename => 'playbook_03_bom_processing.yaml'},
# SAP HANA database installation
{playbook_filename => 'playbook_04_00_00_db_install.yaml', timeout => 1800},
#{playbook_filename => 'playbook_04_00_00_db_install.yaml', timeout => 1800},
# SAP HANA high-availability configuration
{playbook_filename => 'playbook_04_00_01_db_ha.yaml', timeout => 1800},
#{playbook_filename => 'playbook_04_00_01_db_ha.yaml', timeout => 1800},
);

connect_target_to_serial();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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_sdaf_config_path 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')
);

my $sut_ssh_private_key = get_sdaf_config_path(
deployment_type => 'sap_system',
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')
) . '/sshkey';

# 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

# copy SUT ssh key to user home dir which is what PC library is using by default.
assert_script_run("cp -Rp $sut_ssh_private_key ~/.ssh/id_rsa");

my $instances = sdaf_create_instances(inventory_content=>$inventory_data, sut_ssh_key_path=>$sut_ssh_private_key);
$run_args->{instances} = $self->{instances} = $instances;

use Data::Dumper;
record_info('Instances', Dumper($instances));

# Basic check if PC library calls work.
for my $instance (@$instances) {
$self->{my_instance} = $instance;
$instance->wait_for_ssh();
}

#disconnect_target_from_serial();
}

1;

0 comments on commit 364566a

Please sign in to comment.