Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

machine_core: Add Machine.ws_container runtime detection #7361

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
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
Loading