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 65487c8
Show file tree
Hide file tree
Showing 2 changed files with 33 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
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

0 comments on commit 65487c8

Please sign in to comment.