Skip to content

Commit

Permalink
Add argument to customize qesap log filename
Browse files Browse the repository at this point in the history
Add argument to `qesap_execute` about the log filename. Use it in qesap
regression Ansible and Terraform retry.
Add verbosity args with no verbose default in
qesap_ansible_script_output_file.
Improve debug message in peering delete function.
  • Loading branch information
mpagot committed Oct 17, 2023
1 parent 2626881 commit 23eeb10
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 10 deletions.
29 changes: 22 additions & 7 deletions lib/qesapdeployment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ sub qesap_yaml_replace {
https://github.com/SUSE/qe-sap-deployment
Test only returns execution result, failure has to be handled by calling method.
=over 4
=over 5
=item B<CMD> - qesap.py subcommand to run
Expand All @@ -391,6 +391,10 @@ sub qesap_yaml_replace {
=item B<VERBOSE> - activate verbosity in qesap.py
=item B<TIMEOUT> - max expected execution time
=item B<LOGNAME> - filename of the log file. This argument is optional,
if not specified the log filename is internally calculated
using content from CMD and CMD_OPTIONS.
=back
=cut

Expand All @@ -401,10 +405,16 @@ sub qesap_execute {
$args{cmd_options} ||= '';

my %paths = qesap_get_file_paths();
my $exec_log = "/tmp/qesap_exec_$args{cmd}";
$exec_log .= "_$args{cmd_options}" if ($args{cmd_options});
$exec_log .= '.log.txt';
$exec_log =~ s/[-\s]+/_/g;
my $exec_log = '/tmp/';
if ($args{logname})
{
$exec_log .= $args{logname};
} else {
$exec_log .= "qesap_exec_$args{cmd}";
$exec_log .= "_$args{cmd_options}" if ($args{cmd_options});
$exec_log .= '.log.txt';
$exec_log =~ s/[-\s]+/_/g;
}

my $qesap_cmd = join(' ', QESAPDEPLOY_PY, $paths{deployment_dir} . '/scripts/qesap/qesap.py',
$verbose,
Expand Down Expand Up @@ -681,6 +691,8 @@ sub qesap_ansible_cmd {
=item B<FAILOK> - if not set, Ansible failure result in die
=item B<VERBOSE> - 1 result in ansible-playbook to be called with '-vvvv', default is 0.
=item B<TIMEOUT> - max expected execution time, default 180sec.
Same timeout is used both for the execution of script_output.yaml and for the fetch_file.
Timeout of the same amount is started two times.
Expand All @@ -697,6 +709,8 @@ sub qesap_ansible_script_output_file {
$args{root} ||= 0;
$args{failok} //= 0;
$args{timeout} //= bmwqemu::scale_timeout(180);
$args{verbose} //= 0;
my $verbose = $args{verbose} ? '-vvvv' : '';
my $remote_path = $args{remote_path} // '/tmp/';
my $out_path = $args{out_path} // '/tmp/ansible_script_output/';
my $file = $args{file} // 'testout.txt';
Expand All @@ -705,7 +719,7 @@ sub qesap_ansible_script_output_file {
my $playbook = 'script_output.yaml';
qesap_ansible_get_playbook(playbook => $playbook);

my @ansible_cmd = ('ansible-playbook', '-vvvv', $playbook);
my @ansible_cmd = ('ansible-playbook', $verbose, $playbook);
push @ansible_cmd, ('-l', $args{host}, '-i', $inventory, '-u', $args{user});
push @ansible_cmd, ('-b', '--become-user', 'root') if ($args{root});
push @ansible_cmd, ('-e', qq("cmd='$args{cmd}'"),
Expand Down Expand Up @@ -780,6 +794,7 @@ sub qesap_ansible_script_output {
# Print output and delete output file
my $output = script_output("cat $local_tmp");
enter_cmd "rm $local_tmp || echo 'Nothing to delete'";
record_info("Ansible cmd:$args{cmd}", $output);
return $output;
}

Expand Down Expand Up @@ -1225,7 +1240,7 @@ sub qesap_az_vnet_peering_delete {
$source_ret = script_run($source_cmd, timeout => $args{timeout});
}
else {
record_info('NO PEERING', "No peering between job VMs and IBSM - maybe it wasn't created, or the resources have been destroyed.");
record_info('NO PEERING', "Function called without source_group argument.");
}
record_info('Destroying IBSM -> job_resources peering');
my $target_cmd = "$peering_cmd --resource-group $args{target_group} --vnet-name $target_vnet";
Expand Down
1 change: 1 addition & 0 deletions t/14_qesap_ansible.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ subtest '[qesap_ansible_script_output]' => sub {
$qesap->redefine(script_output => sub { push @calls, $_[0];
return 'ANEMONE' if ($_[0] =~ /cat.*/); });
$qesap->redefine(qesap_ansible_script_output_file => sub { return '/tmp/ansible_script_output/'; });
$qesap->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });

my $out = qesap_ansible_script_output(cmd => 'SWIM', provider => 'NEMO', host => 'REEF', file => 'testout.txt', out_path => '/tmp/ansible_script_output/');

Expand Down
2 changes: 2 additions & 0 deletions tests/sles4sap/qesapdeployment/configure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ sub run {
openqa_variables => \%variables,
provider => get_required_var('PUBLIC_CLOUD_PROVIDER')
);

enter_cmd 'export QESAP_SIM_RC=42';
}

sub test_flags {
Expand Down
14 changes: 11 additions & 3 deletions tests/sles4sap/qesapdeployment/deploy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ sub run {
{
if (qesap_file_find_string(file => $ret[1], search_string => 'Missing sudo password')) {
record_info('DETECTED ANSIBLE MISSING SUDO PASSWORD ERROR');
@ret = qesap_execute(cmd => 'ansible', cmd_options => '--profile', verbose => 1, timeout => 3600);
@ret = qesap_execute(cmd => 'ansible',
logname => 'qesap_ansible_retry.log.txt',
timeout => 3600);
if ($ret[0])
{
qesap_cluster_logs();
Expand All @@ -37,9 +39,15 @@ sub run {
elsif (qesap_file_find_string(file => $ret[1], search_string => 'Timed out waiting for last boot time check')) {
record_info('DETECTED ANSIBLE TIMEOUT ERROR');
$self->clean_up();
@ret = qesap_execute(cmd => 'terraform', verbose => 1, timeout => 1800);
@ret = qesap_execute(cmd => 'terraform',
verbose => 1,
logname => 'qesap_terraform_retry.log.txt',
timeout => 1800);
die "'qesap.py terraform' return: $ret[0]" if ($ret[0]);
@ret = qesap_execute(cmd => 'ansible', cmd_options => '--profile', verbose => 1, timeout => 3600);
@ret = qesap_execute(cmd => 'ansible',
verbose => 1,
logname => 'qesap_ansible_retry.log.txt',
timeout => 3600);
if ($ret[0])
{
qesap_cluster_logs();
Expand Down
33 changes: 33 additions & 0 deletions tests/sles4sap/qesapdeployment/setup.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: Setup and install more tools in the running jumphost image for qe-sap-deployment
# Maintainer: QE-SAP <[email protected]>, Michele Pagot <[email protected]>

use strict;
use warnings;
use Mojo::Base 'publiccloud::basetest';
use base 'consoletest';
use testapi;
use qesapdeployment;

sub run {
my ($self) = @_;
$self->select_serial_terminal;

# 'az' and 'terraform' are preinstalled in the PcTools qcow2, we test their version
assert_script_run('az --version');
assert_script_run('terraform --version');

# test ansible installed by pip
assert_script_run('ansible --version');
}

sub post_fail_hook {
my ($self) = @_;
$self->select_serial_terminal;
$self->qesap_upload_logs();
$self->SUPER::post_fail_hook;
}

1;
56 changes: 56 additions & 0 deletions tests/sles4sap/qesapdeployment/test_cluster_ibsm_peering.pm.bkp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: Test for qe-sap-deployment
# Maintainer: QE-SAP <[email protected]>, Michele Pagot <[email protected]>

use strict;
use warnings;
use Mojo::Base 'publiccloud::basetest';
use testapi;
use qesapdeployment;

sub run {
my ($self) = @_;
if (check_var('PUBLIC_CLOUD_PROVIDER', 'AZURE')) {
if (get_var("QESAPDEPLOY_IBSMIRROR_RESOURCE_GROUP")) {
my $rg = qesap_az_get_resource_group();
my $ibs_mirror_rg = get_var('QESAPDEPLOY_IBSMIRROR_RESOURCE_GROUP');
qesap_az_vnet_peering(source_group => $rg, target_group => $ibs_mirror_rg);
qesap_add_server_to_hosts(name => 'download.suse.de', ip => get_required_var("QESAPDEPLOY_IBSMIRROR_IP"));
qesap_az_vnet_peering_delete(source_group => $rg, target_group => $ibs_mirror_rg);
}
} elsif (check_var('PUBLIC_CLOUD_PROVIDER', 'EC2')) {
if (get_var("QESAPDEPLOY_IBSMIRROR_IP_RANGE")) {
my $deployment_name = qesap_calculate_deployment_name('qesapval');
my $vpc_id = qesap_aws_get_vpc_id(resource_group => $deployment_name);
my $ibs_mirror_target_ip = get_var('QESAPDEPLOY_IBSMIRROR_IP_RANGE'); # '10.254.254.240/28'
die 'Error in network peering setup.' if !qesap_aws_vnet_peering(target_ip => $ibs_mirror_target_ip, vpc_id => $vpc_id);
qesap_add_server_to_hosts(name => 'download.suse.de', ip => get_required_var("QESAPDEPLOY_IBSMIRROR_IP"));
die 'Error in network peering delete.' if !qesap_aws_delete_transit_gateway_vpc_attachment(name => $deployment_name . '*');
}
} else {
die 'This test has been scheduled without a valid setting combination';
}
}

sub post_fail_hook {
my ($self) = @_;
qesap_upload_logs();
qesap_execute(cmd => 'ansible', cmd_options => '-d', verbose => 1, timeout => 300);
qesap_execute(cmd => 'terraform', cmd_options => '-d', verbose => 1, timeout => 1200);
if (check_var('PUBLIC_CLOUD_PROVIDER', 'AZURE')) {
if (get_var("QESAPDEPLOY_IBSMIRROR_RESOURCE_GROUP")) {
my $rg = qesap_az_get_resource_group();
my $ibs_mirror_rg = get_required_var('QESAPDEPLOY_IBSMIRROR_RESOURCE_GROUP');
qesap_az_vnet_peering_delete(source_group => $rg, target_group => $ibs_mirror_rg);
}
} elsif (check_var('PUBLIC_CLOUD_PROVIDER', 'EC2')) {
if (get_var("QESAPDEPLOY_IBSMIRROR_IP_RANGE")) {
qesap_aws_delete_transit_gateway_vpc_attachment(name => qesap_calculate_deployment_name('qesapval') . '*');
}
}
$self->SUPER::post_fail_hook;
}

1;

0 comments on commit 23eeb10

Please sign in to comment.