Skip to content

Commit

Permalink
SDAF run on prem code
Browse files Browse the repository at this point in the history
  • Loading branch information
lpalovsky committed Nov 27, 2024
1 parent 19177d6 commit 1953ae1
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use Exporter qw(import);
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;

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

=head2 read_inventory_file
Expand Down Expand Up @@ -231,3 +231,57 @@ sub verify_ssh_proxy_connection {
}
}
}

=head2 create_redirection_data
create_redirection_data(inventory_data=>HASHREF);
Reads parsed and referenced SDAF inventory data
=over
=item * B<inventory_data> SDAF inventory content in referenced perl data structure.
=back
=cut

sub create_redirection_data {
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<inventory_data> 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,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/redirection_tests/redirection_check
#- sles4sap/sap_deployment_automation_framework/cleanup
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
69 changes: 35 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 @@ -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 All @@ -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;
173 changes: 173 additions & 0 deletions tests/sles4sap/redirection_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Redirection test modules

## Overview

Test modules in this directory are intended for testing scenarios with remote SUT (System under test).
This means worker VM is serving only as an SSH jumphost to SUT.
This is achieved using console redirection located in `lib/sles4sap/console_redirection.pm`.

Test modules should be independent of a deployment solution and should not really contain code related to it.
Technically,
you should be able to run test with two (or more)
local workers where one worker serves as an SSH gateway and test coordinator to the others.

One exception is base test with post-fail/post-run hooks as there is no solution yet to separate those from test code.

### Practical goal

At the moment, there are multiple projects in SLES4SAP/HA that use different deployment solutions,
and the test code is tied to it to some degree.
This means that each test scenario requires separate test modules for each platform/project.
The goal is to do the decrease redundant work done while increasing the coverage.

**Specifically, projects below:**
- Cloud tests deployed using [qe-sap-deployment](https://github.com/SUSE/qe-sap-deployment)
- Azure tests deployed using [SAP deployment automation framework](https://github.com/Azure/sap-automation)
- Tests with SUT running directly on OpenQA worker - using one of the workers as an SSH Jump host
- Remote VMWare deployments

### Ideal goal

One test to rule them all!
Completely independent test modules which will work on any deployment solution if test start criteria are met.
They should solve a problem with poverty, invent panacea, end all conflicts and achieve world peace.

## Rules

- `K`eep `I`t `S`imple `S`tupid
- Do not base test modules on specific deployment type but on use of console redirection principle:
- worker serves as SSH jumphost to SUT
- standard OpenQA API calls are executed transparently on remote host the console is redirected to (in most cases SUT)
- Ideally test module should work regardless of deployment if required start conditions are met (input variables, SUT state, etc...)
- Always document test module requirements, input parameters in `SYNOPSIS` or create an .md file
- Keep documentation up to date
- Sadly, there will be projects that won't be able to benefit from this concept, please don't make compromises and shortcuts for the sake of one project.

## Requirements

- working passwordless SSH connection from worker VM to SUT

## Redirection data structure

There is a standard required data that has to be provided to test module using `$run_args->{redirection_data}`.
Redirection data contains a list of hosts which belong to the tested infrastructure and SSH connection data.

```
$run_args->{redirection_data} = {
host_group_type => {
'hostname' => {
ip_address => '',
ssh_user => ''
}
}
};
```

Example:
```
$run_args->{redirection_data} = {
ha_node => {
cluster_01 => {
ip_address => '192.168.1.3',
ssh_user => 'hanaadmin'
},
cluster_02 => {
ip_address => '192.168.1.4',
ssh_user => 'hanaadmin'
},
cluster_03 => {
ip_address => '192.168.1.3',
ssh_user => 'hanaadmin'
},
},
db_hana => {
hanadb_a => {
ip_address => '192.168.1.3',
ssh_user => 'hanaadmin'
},
hanadb_b => {
ip_address => '192.168.1.4',
ssh_user => 'hanaadmin'
}
},
db_ase => {
asedb => {
ip_address => '192.168.1.5',
ssh_user => 'hanaadmin'
}
},
nw_pas => {
nw_pas => {
ip_address => '192.168.1.6',
ssh_user => 'hanaadmin'
}
},
nw_aas => {
nw_aas_01 => {
ip_address => '192.168.1.7',
ssh_user => 'hanaadmin'
},
nw_aas_02 => {
ip_address => '192.168.1.8',
ssh_user => 'hanaadmin'
}
},
nw_ascs => {
nw_ascs => {
ip_address => '192.168.1.9',
ssh_user => 'hanaadmin'
}
},
nw_ers => {
nw_ers => {
ip_address => '192.168.1.10',
ssh_user => 'hanaadmin'
}
}
};
```

Please keep information in the data structure only relevant to console redirection.
If a test module needs additional information (data about sap instances),
create a new required structure and document it.
Try to make this structure generic,
not based on a specific document outputted from a specific deployment solution like a tfvars file.

For data to be passed between test modules, it is required to include variable `TEST_CONTEXT: OpenQA::Test::RunArgs`
into YAML schedule:

```
vars:
TEST_CONTEXT: 'OpenQA::Test::RunArgs'
```

# Test module example

Below is an example of a basic test module which loops over all hosts and tests common API calls:

```
sub run {
my ($self, $run_args) = @_;
my %redirection_data = %{ $run_args->{redirection_data} };
for my $instance_type (keys(%redirection_data)) {
my $hosts = redirection_data{$instance_type};
for my $hostname (keys %$hosts) {
my $ip_addr = $hosts->{$hostname}{ip_address};
my $user = $hosts->{$hostname}{user};
# Redirect console to SUT
connect_target_to_serial(destination_ip=>$ip_addr, ssh_user=>$user);
# Do your things on SUT
record_info(script_output('sudo crm status'));
my $hostname_real = script_output('hostname');
assert_script_run("echo \$(hostname) > /tmp/hostname_$hostname_real");
upload_logs("/tmp/hostname_$hostname_real");
# Disconnect serial from SUT <- never forget to do that.
disconnect_target_from_serial();
}
}
}
```
Loading

0 comments on commit 1953ae1

Please sign in to comment.