From 65487c871b4991e98744a600198f05fcd21b47aa Mon Sep 17 00:00:00 2001 From: Michele Pagot Date: Tue, 17 Oct 2023 14:57:05 +0200 Subject: [PATCH] Add argument to customize qesap log filename 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. --- lib/qesapdeployment.pm | 29 ++++++++++++++++++------ tests/sles4sap/qesapdeployment/deploy.pm | 14 +++++++++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/qesapdeployment.pm b/lib/qesapdeployment.pm index 9cb9fb2c5187..10731368ae47 100644 --- a/lib/qesapdeployment.pm +++ b/lib/qesapdeployment.pm @@ -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 - qesap.py subcommand to run @@ -391,6 +391,10 @@ sub qesap_yaml_replace { =item B - activate verbosity in qesap.py =item B - max expected execution time + +=item B - 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 @@ -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, @@ -681,6 +691,8 @@ sub qesap_ansible_cmd { =item B - if not set, Ansible failure result in die +=item B - 1 result in ansible-playbook to be called with '-vvvv', default is 0. + =item B - 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. @@ -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'; @@ -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}'"), @@ -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; } @@ -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"; diff --git a/tests/sles4sap/qesapdeployment/deploy.pm b/tests/sles4sap/qesapdeployment/deploy.pm index 234e9f6a36de..795c52abcd9b 100644 --- a/tests/sles4sap/qesapdeployment/deploy.pm +++ b/tests/sles4sap/qesapdeployment/deploy.pm @@ -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(); @@ -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();