-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathsles4sap_publiccloud_basetest.pm
142 lines (102 loc) · 3.7 KB
/
sles4sap_publiccloud_basetest.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# SUSE's openQA tests
#
# Copyright SUSE LLC
# SPDX-License-Identifier: FSFAP
# Maintainer: QE-SAP <[email protected]>
# Summary: Base test providing cleanup, post fail and post run hooks for tests using qe-sap-deployment project.
# https://github.com/SUSE/qe-sap-deployment
package sles4sap_publiccloud_basetest;
use Mojo::Base 'publiccloud::basetest';
use strict;
use warnings FATAL => 'all';
use Exporter 'import';
use Carp qw(croak);
use testapi;
use qesapdeployment;
use sles4sap_publiccloud;
use publiccloud::utils qw(get_ssh_private_key_path);
our @EXPORT = qw(cleanup import_context);
=head1 DESCRIPTION
Basetest class for SLES for SAP Applications tests in Public Cloud.
=head2 cleanup
$self->cleanup(%args)
Cleanup method intended to be called at the end of tests or in C<post_fail_hook>.
Mostly a wrapper around C<sles4sap_publiccloud::sles4sap_cleanup> which will:
=over
=item *
Remove network peerings
=item *
Run ansible de-registration playbooks
=item *
Run C<terraform destroy>
=back
Unless any of these has been executed previously.
=cut
sub cleanup {
my ($self, $args) = @_;
my $res = sles4sap_cleanup(
$self,
cleanup_called => $self->{cleanup_called},
network_peering_present => $self->{network_peering_present},
ansible_present => $self->{ansible_present}
);
if ($res eq 0) {
$self->{cleanup_called} = 1;
$self->{network_peering_present} = 0;
$self->{ansible_present} = 0;
}
$args->{my_provider}->terraform_applied(0)
if ((defined $args)
&& (ref($args->{my_provider}) =~ /^publiccloud::(azure|ec2|gce)/)
&& (defined $self->{result})
&& ($self->{result} ne 'fail'));
}
=head2 import_context
$self->import_context(%run_args)
Import into C<$self> the class instances context passed via C<%run_args>, and
record the information in the test results.
=cut
sub import_context {
my ($self, $run_args) = @_;
$self->{instances} = $run_args->{instances};
$self->{network_peering_present} = 1 if ($run_args->{network_peering_present});
$self->{ansible_present} = 1 if ($run_args->{ansible_present});
record_info('CONTEXT LOG', join(' ',
'cleanup_called:', $self->{cleanup_called} // 'undefined',
'instances:', $self->{instances} // 'undefined',
'network_peering_present:', $self->{network_peering_present} // 'undefined',
'ansible_present:', $self->{ansible_present} // 'undefined')
);
}
=head2 set_cli_ssh_opts
$self->set_cli_ssh_opts();
$self->set_cli_ssh_opts('');
$self->set_cli_ssh_opts("-4 -o LogLevel=ERROR -E $logfile");
Set command line SSH options in the instance stored in C<$self-E<gt>{my_instance}>. It takes
as an argument a string with the options in a manner that would be understood by B<ssh>, and
if no argument is provided, uses the following defaults:
=over
=item *
C<-E /var/tmp/ssh_sut.log>: save logging to B</var/tmp/ssh_sut.log>.
=back
B<Note>: if the method receives an empty string, no SSH options will be set.
=cut
sub set_cli_ssh_opts {
my ($self, $ssh_opts) = @_;
croak("Expected \$self->{my_instance} is not defined. Check module Description for details")
unless $self->{my_instance};
$ssh_opts //= join(' ', '-E', '/var/tmp/ssh_sut.log');
$self->{my_instance}->ssh_opts($ssh_opts);
}
sub post_fail_hook {
my ($self) = @_;
if (get_var('QESAP_NO_CLEANUP_ON_FAILURE')) {
diag('Skip post fail', "Variable 'QESAP_NO_CLEANUP_ON_FAILURE' defined.");
return;
}
eval { $self->cleanup(); } or bmwqemu::fctwarn("self::cleanup() failed -- $@");
}
sub post_run_hook {
diag('Skip post run', "Skipping post run hook. \n but also avoid to call the PC one");
}
1;