Skip to content

Commit

Permalink
machine_core: Add Machine.ws_container runtime detection
Browse files Browse the repository at this point in the history
We want to introduce proper bootc image testing for cockpit. In that
scenario we want to install the actual rpm, not use the cockpit/ws
container. This conflicts with cockpit-ostree's current assumption that
the centos-9-bootc image always uses the ws container.

Thus make this check dynamic: If cockpit-ws package is installed (check
for `/usr/share/cockpit/static` as that's the same on all distros and a
cheap test), use it, otherwise use the ws container. Keep the
`TEST_SCENARIO=ws-container` check, at least until we update
cockpit-ostree's image preparation to remove cockpit-ws.rpm.

We can't yet run `.execute()` in the Machine constructor, so delay the
detection by making `ws_container` a (cached) property.
  • Loading branch information
martinpitt authored and jelly committed Jan 30, 2025
1 parent 7f20011 commit 8fa8fdc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions machine/machine_core/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import subprocess
from collections.abc import Collection, Mapping, Sequence
from functools import cached_property

from lib.constants import BOTS_DIR, DEFAULT_IDENTITY_FILE, OSTREE_IMAGES

Expand Down Expand Up @@ -91,9 +92,6 @@ def __init__(
self.arch = arch
self.image = image
self.ostree_image = self.image in OSTREE_IMAGES
# start via cockpit/ws container on OSTree or when explicitly requested
self.ws_container = self.ostree_image or "ws-container" in os.getenv("TEST_SCENARIO", "")

if ":" in browser:
self.web_address, _, self.web_port = browser.rpartition(":")
else:
Expand All @@ -103,6 +101,23 @@ def __init__(
# The Linux kernel boot_id
self.boot_id = None

@cached_property
def ws_container(self) -> bool:
"""Return if image uses the cockpit/ws container
True → ws container; False: cockpit-ws package
Tests can force using the ws container by setting TEST_SCENARIO=ws-container
Otherwise this does runtime detection.
A project's test image preparation should ensure that only one is installed
to avoid confusion.
"""
if "ws-container" in os.getenv("TEST_SCENARIO", ""):
return True
else:
return not self.execute("ls /usr/share/cockpit/static", check=False).strip()

def diagnose(self, tty: bool = True) -> str:
keys = {
"ssh_user": self.ssh_user,
Expand Down

0 comments on commit 8fa8fdc

Please sign in to comment.