Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# "class Browser" and "class MachineCase" for the available API.

import re
import shlex
import sys
import time
from contextlib import contextmanager
Expand Down Expand Up @@ -125,23 +126,23 @@ class TestApplication(testlib.MachineCase):
identity_file=m.identity_file)

# Enable user service as well; copy our images (except cockpit/ws) from system
self.admin_s.execute("""
self.execute("""
systemctl --user stop podman.service
for img in $(ls /var/lib/test-images/*.tar | grep -v cockpitws); do podman load < "$img"; done
""")
self.addCleanup(self.admin_s.execute, """
""", system=False)
self.addCleanup(self.execute, """
systemctl --user stop podman.service podman.socket
podman system reset --force
""")
""", system=False)
# HACK: system reset has 10s timeout, make that faster with an extra `stop`
# https://github.com/containers/podman/issues/21874
# Ubuntu 22.04 has old podman that does not know about rm --time
if m.image == 'ubuntu-2204':
self.addCleanup(self.admin_s.execute, "podman rm --force --all", timeout=300)
self.addCleanup(self.admin_s.execute, "podman pod rm --force --all", timeout=300)
else:
self.addCleanup(self.admin_s.execute, "podman rm --force --time 0 --all")
self.addCleanup(self.admin_s.execute, "podman pod rm --force --time 0 --all")
self.addCleanup(self.execute, "podman rm --force --time 0 --all", system=False)
self.addCleanup(self.execute, "podman pod rm --force --time 0 --all", system=False)

self.allow_journal_messages("/run.*/podman/podman: couldn't connect.*")
self.allow_journal_messages(".*/run.*/podman/podman.*Connection reset by peer")
Expand Down Expand Up @@ -242,6 +243,44 @@ class TestApplication(testlib.MachineCase):
else:
return self.admin_s.execute(cmd, check=check)

def run_container(self, name: str, options: list[str], image: str, args: list[str],
*, system: bool = False) -> None:
""" Run a container in the background"""
m = self.machine
sd_run: list[str] = []
sd_run_cleanup: list[str] = []

# machinectl shell with podman keeps a tty open if we don't background
if m.image == "rhel-8-10":
options.append("-d")

run_cmd = ["/usr/bin/podman", "run", "--stop-timeout", "0", "--name", name, *options, image, *args]

# RHEL 8.10 systemd does not support --machine=admin@ for local sessions
if m.image == "rhel-8-10":
sd_run.extend(["machinectl", "shell", "--quiet"])
if system is False:
sd_run.extend(["admin@"])
else:
sd_run.extend(["root@"])

self.addCleanup(m.execute, ["/usr/bin/podman", "stop", name])
else:
sd_run.extend(["systemd-run", "--quiet", "--unit", name,
"-p", f"ExecStop=/usr/bin/podman stop {name}"])
sd_run_cleanup = ["systemctl"]
if system is False:
sd_run.extend(["--user", "--machine=admin@"])
sd_run_cleanup.extend(["--user", "--machine=admin@"])

if len(sd_run_cleanup) != 0:
is_active_cmd = shlex.join([*sd_run_cleanup, "is-active", name])
stop_cmd = shlex.join([*sd_run_cleanup, "stop", name])
self.addCleanup(m.execute, f"! {is_active_cmd} || {stop_cmd}")

sd_run.extend(run_cmd)
m.execute(sd_run)

def login(self, *, system: bool = True) -> None:
b = self.browser
self.login_and_go("/podman", superuser=system)
Expand Down Expand Up @@ -1070,7 +1109,7 @@ Yaml={name}.yaml
self.login(system=auth)

# run a container (will exit immediately) and test the display of commit modal
self.execute(f"podman run -d --name test-sh0 --stop-timeout 0 {IMG_ALPINE} sh -c 'ls -a'", system=auth)
self.execute(f"podman run --name test-sh0 --stop-timeout 0 {IMG_ALPINE} sh -c 'ls -a'", system=auth)

self.filter_containers("all")
self.waitContainerRow("test-sh0")
Expand Down Expand Up @@ -1644,8 +1683,8 @@ Yaml={name}.yaml
# On cgroupsv1 systems just check that we get expected error messages

# Run a container
self.execute(f"podman run -dit --name swamped-crate --stop-timeout 0 {IMG_BUSYBOX} sh", system=True)
b.wait(lambda: self.execute("podman ps --all | grep -e swamped-crate", system=True))
m.execute(f"podman run -dit --name swamped-crate --stop-timeout 0 {IMG_BUSYBOX} sh")
b.wait(lambda: m.execute("podman ps --all | grep -e swamped-crate"))

# Checkpoint the container
self.performContainerAction("swamped-crate", "Checkpoint", system=True)
Expand All @@ -1667,10 +1706,10 @@ Yaml={name}.yaml

# Run a container
mac_address = '92:d0:c6:0a:29:38'
self.execute(f"""
m.execute(f"""
podman run -dit --mac-address {mac_address} --name swamped-crate --stop-timeout 0 {IMG_BUSYBOX} sh;
podman stop swamped-crate
""", system=True)
""")
b.wait(lambda: self.execute("podman ps --all | grep -e swamped-crate -e Exited", system=True))

# Check that the restore option is not present (i.e. start is a regular button)
Expand Down Expand Up @@ -2999,7 +3038,7 @@ Yaml={name}.yaml
b = self.browser
container_name = "pauseresume"

self.execute(f"podman run -dt --name {container_name} --stop-timeout 0 {IMG_ALPINE}", system=auth)
self.run_container(container_name, ["-t"], IMG_ALPINE, [], system=auth)
self.login(system=auth)

self.waitContainerRow(container_name)
Expand All @@ -3018,6 +3057,7 @@ Yaml={name}.yaml
b.wait_not_present(self.getContainerAction('Pause'))
self.performContainerAction(container_name, "Resume", system=auth)
b.wait(lambda: self.getContainerAttr(container_name, "State", "", system=auth) == "Running")
testlib.sit()

def testRenameContainerSystem(self) -> None:
self._testRenameContainer(auth=True)
Expand Down
Loading