Skip to content

Commit 48730a9

Browse files
Refactor it
1 parent 31c23cd commit 48730a9

File tree

2 files changed

+51
-44
lines changed

2 files changed

+51
-44
lines changed

lib/main_containers.pm

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,23 @@ sub load_firewall_test {
143143
loadtest('containers/firewall', run_args => $run_args, name => $run_args->{runtime} . "_firewall");
144144
}
145145

146+
sub load_python_tests {
147+
my $runtime = shift;
148+
foreach my $target (qw(setup unit integration)) {
149+
my $run_args = OpenQA::Test::RunArgs->new();
150+
$run_args->{runtime} = $runtime;
151+
$run_args->{target} = $target;
152+
loadtest('containers/runtime_py', run_args => $run_args, name => "${runtime}_py_$target");
153+
}
154+
}
155+
146156
sub load_host_tests_podman {
147157
my ($run_args) = @_;
148158
# python3-podman is not available in SLE 16.0 due to https://bugzilla.suse.com/show_bug.cgi?id=1248415
149-
loadtest('containers/runtime_py', run_args => $run_args, name => $run_args->{runtime} . "_py") unless (is_staging || is_transactional || is_sle(">=16.0"));
159+
unless (is_staging || is_transactional || is_sle(">=16.0")) {
160+
load_python_tests $run_args{runtime};
161+
}
162+
# FIXME
150163
return;
151164
load_container_engine_test($run_args);
152165
# In Public Cloud we don't have internal resources
@@ -191,7 +204,10 @@ sub load_host_tests_podman {
191204

192205
sub load_host_tests_docker {
193206
my ($run_args) = @_;
194-
loadtest('containers/runtime_py', run_args => $run_args, name => $run_args->{runtime} . "_py") unless (is_staging || is_transactional);
207+
unless (is_staging || is_transactional) {
208+
load_python_tests $run_args{runtime};
209+
}
210+
# FIXME
195211
return;
196212
load_container_engine_test($run_args);
197213
# In Public Cloud we don't have internal resources
@@ -220,7 +236,6 @@ sub load_host_tests_docker {
220236
# select_user_serial_terminal is broken on public cloud
221237
loadtest 'containers/rootless_docker' unless (is_public_cloud);
222238
}
223-
loadtest('containers/runtime_py', run_args => $run_args, name => $run_args->{runtime} . "_py") unless (is_staging || is_transactional);
224239
# Expected to work anywhere except of real HW backends, PC and Micro
225240
unless (is_generalhw || is_ipmi || is_public_cloud || is_openstack || is_sle_micro || is_microos || is_leap_micro || (is_sle('=12-SP5') && is_aarch64)) {
226241
loadtest 'containers/validate_btrfs';

tests/containers/runtime_py.pm

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,16 @@ use containers::common qw(install_packages);
1717
my $pytest_args = "-vv --capture=tee-sys -o junit_logging=all --junit-xml";
1818
my $runtime;
1919
my $socat = 0;
20+
my $target;
2021
my $timeout = 3600;
2122

22-
sub docker_tests {
23-
my @targets = (
24-
"unit",
25-
"integration"
26-
);
27-
28-
foreach my $target (@targets) {
29-
record_info "TEST", "$target";
30-
script_run "pytest $pytest_args $target.xml tests/$target |& tee $target.txt", timeout => $timeout;
31-
parse_extra_log('XUnit', "$target.xml");
32-
upload_logs("$target.txt");
33-
}
34-
}
35-
36-
sub podman_tests {
37-
my @targets = (
38-
"unit",
39-
"integration"
40-
);
41-
42-
foreach my $target (@targets) {
43-
record_info "TEST", "$target";
44-
script_run "pytest $pytest_args $target.xml podman/tests/$target |& tee $target.txt", timeout => $timeout;
45-
parse_extra_log('XUnit', "$target.xml");
46-
upload_logs("$target.txt");
47-
}
48-
}
49-
50-
51-
sub run {
52-
my ($self, $args) = @_;
53-
$runtime = $args->{runtime};
23+
sub setup {
24+
my $runtime = shift;
5425

55-
my @pkgs = ($runtime, "python3-$runtime");
56-
push @pkgs, qw(git-core jq python3-pytest);
57-
push @pkgs, ($runtime eq "podman") ? qw(python3-fixtures python3-requests-mock) : qw(password-store python3-paramiko socat);
26+
my $python3 = "python3";
27+
my @pkgs = ($runtime, "$python3-$runtime");
28+
push @pkgs, qq(git-core jq $python3-pytest);
29+
push @pkgs, ($runtime eq "podman") ? qq($python3-fixtures $python3-requests-mock) : qq(password-store $python3-paramiko socat);
5830
install_packages(@pkgs);
5931

6032
select_serial_terminal;
@@ -87,7 +59,6 @@ sub run {
8759
assert_script_run "chmod +x /usr/local/bin/docker-credential-pass";
8860
}
8961

90-
my $python3 = "python3";
9162
my $version = script_output "$python3 -c 'import $runtime; print($runtime.__version__)'";
9263
record_info("Version", $version);
9364
my $branch = ($runtime eq "podman") ? "v$version" : $version;
@@ -107,21 +78,40 @@ sub run {
10778
assert_script_run "git clone --depth 1 --branch $branch https://github.com/$github_org/$runtime-py";
10879
assert_script_run "cd $runtime-py";
10980

110-
if ($runtime eq "podman") {
111-
podman_tests;
112-
} else {
81+
if ($runtime eq "docker") {
11382
# Fill credentials store
11483
assert_script_run "gpg2 --import ./tests/gpg-keys/secret";
11584
assert_script_run "gpg2 --import-ownertrust ./tests/gpg-keys/ownertrust";
11685
assert_script_run "yes | pass init \$(gpg2 --no-auto-check-trustdb --list-secret-key | awk '/^sec/{getline; \$1=\$1; print}')";
11786
assert_script_run "gpg2 --check-trustdb";
118-
docker_tests;
11987
}
12088
}
12189

122-
1;
90+
sub test {
91+
my $target = shift;
92+
93+
# Tests directory
94+
my $tests = ($runtime eq "podman") ? "podman/tests" : "tests";
95+
96+
script_run "pytest $pytest_args $target.xml $tests/$target |& tee $target.txt", timeout => $timeout;
97+
parse_extra_log('XUnit', "$target.xml");
98+
upload_logs("$target.txt");
99+
}
100+
101+
sub run {
102+
my ($self, $args) = @_;
103+
$runtime = $args->{runtime};
104+
$target = $args->{target};
105+
if ($target eq "setup") {
106+
setup;
107+
} else {
108+
test $args->{target};
109+
}
110+
}
123111

124112
sub cleanup() {
113+
# FIXME: We need this
114+
return;
125115
script_run "kill -9 $socat";
126116
script_run "cd / ; rm -rf /root/$runtime-py";
127117
}
@@ -137,3 +127,5 @@ sub post_run_hook {
137127
cleanup;
138128
$self->SUPER::post_run_hook;
139129
}
130+
131+
1;

0 commit comments

Comments
 (0)