From a52f3f4ddea9723a15ae07d325025956f7ec2370 Mon Sep 17 00:00:00 2001 From: Ivan Lausuch Date: Thu, 14 Sep 2023 12:10:31 +0200 Subject: [PATCH] Add test for BCI systemd in podman Testing systemd in a container for the podman engine https://progress.opensuse.org/issues/134687 --- lib/main_containers.pm | 1 + tests/containers/podman_bci_systemd.pm | 61 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/containers/podman_bci_systemd.pm diff --git a/lib/main_containers.pm b/lib/main_containers.pm index eed87b6b444f..bf052cdc1253 100644 --- a/lib/main_containers.pm +++ b/lib/main_containers.pm @@ -93,6 +93,7 @@ sub load_host_tests_podman { # In Public Cloud we don't have internal resources load_image_test($run_args) unless is_public_cloud || is_alp; load_3rd_party_image_test($run_args); + loadtest 'containers/podman_bci_systemd'; loadtest 'containers/podman_pods'; # Default for ALP is Netavark loadtest('containers/podman_network_cni') unless (is_alp); diff --git a/tests/containers/podman_bci_systemd.pm b/tests/containers/podman_bci_systemd.pm new file mode 100644 index 000000000000..1151225acc76 --- /dev/null +++ b/tests/containers/podman_bci_systemd.pm @@ -0,0 +1,61 @@ +# SUSE's openQA tests +# +# Copyright 2023 SUSE LLC +# SPDX-License-Identifier: FSFAP + +# Package: podman +# Summary: Test podman with systemd +# Maintainer: Richard Brown + +use Mojo::Base 'containers::basetest'; +use testapi; +use utils qw(script_retry); +use containers::utils qw(check_min_runtime_version); +use serial_terminal 'select_serial_terminal'; +use version_utils qw(is_sle is_opensuse is_staging); +use containers::k8s qw(install_k3s uninstall_k3s); +use Utils::Architectures qw(is_ppc64le); + + +sub run { + my ($self, $args) = @_; + select_serial_terminal; + my $podman = $self->containers_factory('podman'); + $self->{podman} = $podman; + + my $image = get_var("CONTAINER_IMAGE_TO_TEST", "registry.suse.com/bci/bci-init:latest"); + + record_info('Test', 'Launch a container with systemd'); + assert_script_run("podman run -d -p 80:80 --name nginx $image"); + + record_info('Test', 'Install nginx'); + assert_script_run("podman exec -t nginx zypper -n in nginx"); + + record_info('Test', 'Start nginx'); + assert_script_run("podman exec -t nginx systemctl start nginx"); + + record_info('Nginx service status', script_output("podman exec -t nginx systemctl status nginx")); + + record_info('Test', 'Curl localhost'); + assert_script_run("podman exec -t nginx curl http://localhost"); + + record_info('Test', 'Curl localhost from host'); + assert_script_run("curl http://localhost"); +} + +sub cleanup { + my ($self) = @_; + $self->{podman}->cleanup_system_host(); +} + +sub post_run_hook { + my ($self) = @_; + $self->cleanup(); +} + +sub post_fail_hook { + my ($self) = @_; + $self->cleanup(); +} + +1;