Skip to content

Commit 111e8ce

Browse files
Fetch supportconfig logs after sles4sap failure
1 parent b8c3551 commit 111e8ce

2 files changed

Lines changed: 110 additions & 1 deletion

File tree

lib/qesapdeployment.pm

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ our @EXPORT = qw(
7676
qesap_cluster_log_cmds
7777
qesap_cluster_logs
7878
qesap_upload_crm_report
79+
qesap_upload_supportconfig_logs
7980
qesap_aws_get_region_subnets
8081
qesap_aws_get_vpc_id
8182
qesap_aws_create_transit_gateway_vpc_attachment
@@ -1306,6 +1307,59 @@ sub qesap_upload_crm_report {
13061307
upload_logs($local_path, failok => 1);
13071308
}
13081309

1310+
=head3 qesap_upload_supportconfig_logs
1311+
1312+
Genarate supportconfig log on a host and upload the resulting tarball to openqa
1313+
1314+
=over
1315+
1316+
=item B<HOST> - host to get the report from
1317+
1318+
=item B<PROVIDER> - Cloud provider name, used to find the inventory
1319+
1320+
=item B<FAILOK> - if not set, Ansible failure result in die
1321+
1322+
=back
1323+
=cut
1324+
1325+
sub qesap_upload_supportconfig_logs {
1326+
my (%args) = @_;
1327+
foreach (qw(provider host)) { croak "Missing mandatory $_ argument" unless $args{$_}; }
1328+
$args{failok} //= 0;
1329+
1330+
my $log_filename = "$args{host}-supportconfig_log";
1331+
1332+
if ($log_filename =~ /hana\[(\d+)\]/) {
1333+
my $number = $1 + 1;
1334+
$log_filename = "vmhana0${number}-supportconfig_log";
1335+
}
1336+
$log_filename =~ s/[\[\]"]//g;
1337+
1338+
qesap_ansible_cmd(cmd => "sudo supportconfig -R /var/tmp -B $log_filename -x AUDIT",
1339+
provider => $args{provider},
1340+
filter => "\"$args{host}\"",
1341+
host_keys_check => 1,
1342+
verbose => 1,
1343+
timeout => bmwqemu::scale_timeout(7200),
1344+
failok => $args{failok});
1345+
qesap_ansible_cmd(cmd => "sudo chmod 755 /var/tmp/scc_$log_filename.txz",
1346+
provider => $args{provider},
1347+
filter => "\"$args{host}\"",
1348+
host_keys_check => 1,
1349+
verbose => 1,
1350+
timeout => bmwqemu::scale_timeout(7200),
1351+
failok => $args{failok});
1352+
my $local_path = qesap_ansible_fetch_file(provider => $args{provider},
1353+
host => $args{host},
1354+
failok => $args{failok},
1355+
root => 1,
1356+
remote_path => '/var/tmp/',
1357+
out_path => '/tmp/ansible_script_output/',
1358+
file => "scc_$log_filename.txz",
1359+
verbose => 1);
1360+
upload_logs($local_path, failok => 1);
1361+
}
1362+
13091363
=head3 qesap_cluster_log_cmds
13101364
13111365
List of commands to collect logs from a deployed cluster
@@ -1394,6 +1448,7 @@ sub qesap_cluster_logs {
13941448
}
13951449
# Upload crm report
13961450
qesap_upload_crm_report(host => $host, provider => $provider, failok => 1);
1451+
qesap_upload_supportconfig_logs(host => $host, provider => $provider, failok => 1);
13971452
}
13981453
}
13991454

t/09_qesapdeployment.t

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ subtest '[qesap_cluster_logs]' => sub {
714714
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
715715
my @ansible_calls;
716716
my @crm_report_calls;
717+
my @supportconfig_log_calls;
717718
my @save_file_calls;
718719
my @logfile_calls;
719720
$qesap->redefine(qesap_ansible_script_output_file => sub {
@@ -728,6 +729,7 @@ subtest '[qesap_cluster_logs]' => sub {
728729
$qesap->redefine(upload_logs => sub { push @save_file_calls, $_[0]; return; });
729730
$qesap->redefine(qesap_cluster_log_cmds => sub { return ({Cmd => 'crm status', Output => 'crm_status.txt'}); });
730731
$qesap->redefine(qesap_upload_crm_report => sub { my (%args) = @_; push @crm_report_calls, $args{host}; return 0; });
732+
$qesap->redefine(qesap_upload_supportconfig_logs => sub { my (%args) = @_; push @supportconfig_log_calls, $args{host}; return 0; });
731733
my $cloud_provider = 'NEMO';
732734
set_var('PUBLIC_CLOUD_PROVIDER', $cloud_provider);
733735

@@ -736,13 +738,15 @@ subtest '[qesap_cluster_logs]' => sub {
736738
set_var('PUBLIC_CLOUD_PROVIDER', undef);
737739
note("\n ANSIBLE_CMD--> " . join("\n ANSIBLE_CMD--> ", @ansible_calls));
738740
note("\n CRM_REPORT--> " . join("\n CRM_REPORT--> ", @crm_report_calls));
741+
note("\n SUPPORTCONFIG_LOG--> " . join("\n SUPPORTCONFIG_LOG--> ", @supportconfig_log_calls));
739742
note("\n SAVE_FILE--> " . join("\n SAVE_FILE--> ", @save_file_calls));
740743
note("\n LOG_FILES--> " . join("\n LOG_FILES--> ", @logfile_calls));
741744
ok((any { /crm status/ } @ansible_calls), 'expected command executed remotely');
742745
ok((any { /.*hana0-crm_status\.txt/ } @logfile_calls), 'qesap_ansible_script_output_file called with the expected vmhana01 log file');
743746
ok((any { /.*hana1-crm_status\.txt/ } @logfile_calls), 'qesap_ansible_script_output_file called with the expected vmhana02 log file');
744747
ok((any { /.*BOUBLE.*/ } @save_file_calls), 'upload_logs is called with whatever filename returned by qesap_ansible_script_output_file');
745-
ok((any { /hana\[[0-1]\]/ } @crm_report_calls), 'upload_logs properly call qesap_upload_crm_report with hostnames');
748+
ok((any { /hana\[[0-1]\]/ } @crm_report_calls), 'upload_logs properly calls qesap_upload_crm_report with hostnames');
749+
ok((any { /.*hana\[[0-1]\]/ } @supportconfig_log_calls), 'upload_logs properly calls qesap_upload_supportconfig_logs with hostnames');
746750
};
747751

748752
subtest '[qesap_cluster_logs] multi log command' => sub {
@@ -761,6 +765,7 @@ subtest '[qesap_cluster_logs] multi log command' => sub {
761765
$qesap->redefine(upload_logs => sub { return; });
762766
$qesap->redefine(qesap_cluster_log_cmds => sub { return ({Cmd => 'crm status', Output => 'crm_status.txt', Logs => ['ignore_me.txt', 'ignore_me_too.txt']}); });
763767
$qesap->redefine(qesap_upload_crm_report => sub { return 0; });
768+
$qesap->redefine(qesap_upload_supportconfig_logs => sub { return 0; });
764769
my $cloud_provider = 'NEMO';
765770
set_var('PUBLIC_CLOUD_PROVIDER', $cloud_provider);
766771

@@ -822,6 +827,55 @@ subtest '[qesap_upload_crm_report] ansible host query' => sub {
822827
ok((any { /vmhana01\-crm_report\.tar/ } @fetch_filename), 'crm report fetch file is properly formatted');
823828
};
824829

830+
subtest '[qesap_upload_supportconfig_logs] die for missing mandatory arguments' => sub {
831+
dies_ok { qesap_upload_supportconfig_logs(); } "Expected die if called without arguments";
832+
dies_ok { qesap_upload_supportconfig_logs(provider => 'SAND'); } "Expected die if called without host";
833+
dies_ok { qesap_upload_supportconfig_logs(host => 'SALT'); } "Expected die if called without provider";
834+
};
835+
836+
subtest '[qesap_upload_supportconfig_logs]' => sub {
837+
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
838+
my @calls;
839+
840+
$qesap->redefine(is_sle => sub { return 0; });
841+
$qesap->redefine(qesap_ansible_cmd => sub {
842+
my (%args) = @_;
843+
push @calls, $args{cmd};
844+
return 0; });
845+
$qesap->redefine(qesap_ansible_fetch_file => sub { return 0; });
846+
$qesap->redefine(upload_logs => sub { return 0; });
847+
848+
qesap_upload_supportconfig_logs(provider => 'SAND', host => 'SALT');
849+
850+
note("\n C--> " . join("\n C--> ", @calls));
851+
ok((any { /.*supportconfig \-R.*/ } @calls), 'supportconfig is called');
852+
ok((any { /.*\/var\/tmp.*SALT.*supportconfig/ } @calls), 'supportconfig log file has the node name in it');
853+
};
854+
855+
subtest '[qesap_upload_supportconfig_logs] ansible host query' => sub {
856+
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
857+
my @calls;
858+
my @fetch_filename;
859+
860+
$qesap->redefine(is_sle => sub { return 0; });
861+
$qesap->redefine(qesap_ansible_cmd => sub {
862+
my (%args) = @_;
863+
push @calls, $args{cmd};
864+
return 0; });
865+
$qesap->redefine(qesap_ansible_fetch_file => sub {
866+
my (%args) = @_;
867+
push @fetch_filename, $args{file};
868+
return 0; });
869+
$qesap->redefine(upload_logs => sub { return 0; });
870+
871+
qesap_upload_supportconfig_logs(provider => 'SAND', host => 'hana[0]');
872+
873+
note("\n C--> " . join("\n C--> ", @calls));
874+
note("\n FETCH_FILENAME--> " . join("\n FETCH_FILENAME--> ", @fetch_filename));
875+
ok((any { /.*\/var\/tmp.*vmhana01.*supportconfig/ } @calls), 'supportconfig log file has the node name in it');
876+
ok((any { /.*vmhana01.*supportconfig/ } @fetch_filename), 'supportconfig log fetch file is properly formatted');
877+
};
878+
825879
subtest '[qesap_calculate_deployment_name]' => sub {
826880
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
827881
$qesap->redefine(get_current_job_id => sub { return 42; });

0 commit comments

Comments
 (0)