From 5cd929b5fdf11a458df58b1a0fe299c7bf0b183c Mon Sep 17 00:00:00 2001 From: lpalovsky Date: Thu, 14 Nov 2024 15:03:21 +0100 Subject: [PATCH] SDAF run on prem code --- .../inventory_tools.pm | 54 +++++++++++++++ .../test_hana_sr.yml | 6 +- t/29_sdaf_inventory_tools.t | 69 ++++++++++--------- .../redirection_tests/hanasr_stop_primary.pm | 43 ++++++++++++ .../prepare_ssh_config.pm | 2 +- 5 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 tests/sles4sap/redirection_tests/hanasr_stop_primary.pm diff --git a/lib/sles4sap/sap_deployment_automation_framework/inventory_tools.pm b/lib/sles4sap/sap_deployment_automation_framework/inventory_tools.pm index 24f2dc3da002..53123000d66e 100644 --- a/lib/sles4sap/sap_deployment_automation_framework/inventory_tools.pm +++ b/lib/sles4sap/sap_deployment_automation_framework/inventory_tools.pm @@ -231,3 +231,57 @@ sub verify_ssh_proxy_connection { } } } + +=head2 inventory_to_redirection + + inventory_to_redirection(inventory_data=>HASHREF); + +Reads parsed and referenced SDAF inventory data + +=over + +=item * B SDAF inventory content in referenced perl data structure. + +=back +=cut + +sub inventory_to_redirection { + my (%args) = @_; + my %infrastructure; + + for my $instance_type (keys(%{$args{inventory_data}})) { + my $hosts = $args{inventory_data}->{$instance_type}{hosts}; + for my $hostname (keys %$hosts) { + + } + } + + return \%infrastructure; +} + +=head2 get_instance_type + + get_instance_type(inventory_data=>HASHREF); + +Reads parsed and referenced SDAF inventory data + +=over + +=item * B SDAF inventory content in referenced perl data structure. + +=back +=cut + +sub get_instance_type { + my (%args) = @_; + my %infrastructure; + + for my $instance_type (keys(%{$args{inventory_data}})) { + my $hosts = $args{inventory_data}->{$instance_type}{hosts}; + for my $hostname (keys %$hosts) { + my $section = '' + } + } + + return \%infrastructure; +} \ No newline at end of file diff --git a/schedule/sles4sap/sap_deployment_automation_framework/test_hana_sr.yml b/schedule/sles4sap/sap_deployment_automation_framework/test_hana_sr.yml index c2e09bbafb9f..78438148e635 100644 --- a/schedule/sles4sap/sap_deployment_automation_framework/test_hana_sr.yml +++ b/schedule/sles4sap/sap_deployment_automation_framework/test_hana_sr.yml @@ -2,8 +2,12 @@ name: sap_deployment_automation_framework description: | Hana SR test scenario executed on deployment created by 'SAP Deployment automation framework' +vars: + TEST_CONTEXT: 'OpenQA::Test::RunArgs' 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/compile_redirection_data + - sles4sap/redirection_tests/hanasr_stop_primary + #- sles4sap/sap_deployment_automation_framework/cleanup diff --git a/t/29_sdaf_inventory_tools.t b/t/29_sdaf_inventory_tools.t index 83f5d4543b3a..bab721caefb8 100644 --- a/t/29_sdaf_inventory_tools.t +++ b/t/29_sdaf_inventory_tools.t @@ -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); @@ -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'); @@ -101,9 +100,11 @@ subtest '[prepare_ssh_config] ' => sub { ok($db_host_B_content =~ /identity_file/, '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 '[inventory_to_redirection] ' => sub { + my $mock = Test::MockModule->new('sles4sap::sap_deployment_automation_framework::inventory_tools', no_auto => 1); }; - done_testing; diff --git a/tests/sles4sap/redirection_tests/hanasr_stop_primary.pm b/tests/sles4sap/redirection_tests/hanasr_stop_primary.pm new file mode 100644 index 000000000000..d92e738a6b68 --- /dev/null +++ b/tests/sles4sap/redirection_tests/hanasr_stop_primary.pm @@ -0,0 +1,43 @@ +# SUSE's openQA tests +# +# Copyright SUSE LLC +# SPDX-License-Identifier: FSFAP +# Maintainer: QE-SAP +# Summary: + +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; + +sub test_flags { + return {fatal => 1, publiccloud_multi_module => 1}; +} + +sub run { + my ($self, $run_args) = @_; + my %inventory = %{ $run_args->{sdaf_inventory} }; + use Data::Dumper; + record_info('Inventory', Dumper(\%inventory)); + + for my $instance_type (keys(%inventory)) { + my $hosts = $inventory{$instance_type}{hosts}; + for my $hostname (keys %$hosts) { + my $ip_addr = $hosts->{$hostname}{ansible_host}; + my $user = $hosts->{$hostname}{ansible_user}; + connect_target_to_serial(destination_ip=>$ip_addr, ssh_user=>$user); + record_info(script_output('sudo crm status')); + assert_script_run('hostname'); + assert_script_run("echo \$(hostname) > /tmp/hostname"); + upload_logs('/tmp/hostname'); + disconnect_target_from_serial(); + } + } + + +} + +1; \ No newline at end of file diff --git a/tests/sles4sap/sap_deployment_automation_framework/prepare_ssh_config.pm b/tests/sles4sap/sap_deployment_automation_framework/prepare_ssh_config.pm index a12702fb073c..79569abc618b 100644 --- a/tests/sles4sap/sap_deployment_automation_framework/prepare_ssh_config.pm +++ b/tests/sles4sap/sap_deployment_automation_framework/prepare_ssh_config.pm @@ -48,7 +48,7 @@ sub run { disconnect_target_from_serial(); # Share inventory data between all tests - $self->{sdaf_inventory} = $inventory_data; + $run_args->{sdaf_inventory} = $inventory_data; my @workload_key_vault = @{az_keyvault_list( resource_group => generate_resource_group_name(deployment_type => 'workload_zone'))};