Skip to content

Commit

Permalink
RHOAIENG-18459: chore(tests/containers): handle multiple podman machi…
Browse files Browse the repository at this point in the history
…nes and improve debugging output when podman machine is not found (#869)

* RHOAIENG-18459: chore(tests/containers): improve debugging output when podman machine is not found

* RHOAIENG-18459: chore(tests/containers): reduce the number of podman machine inspect calls, by giving it all machine names at once
  • Loading branch information
jiridanek authored Jan 28, 2025
1 parent 9e76f6f commit 22f1d9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/containers/podman_machine_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
def open_ssh_tunnel(machine_predicate: Callable[[tests.containers.schemas.PodmanMachine], bool],
local_port: int, remote_port: int, remote_interface: str = "localhost") -> subprocess.Popen:
# Load and parse the Podman machine data
json_data = subprocess.check_output(["podman", "machine", "inspect"], text=True)
machine_names = subprocess.check_output(["podman", "machine", "list", "--quiet"], text=True).splitlines()
json_data = subprocess.check_output(["podman", "machine", "inspect", *machine_names], text=True)
inspect = tests.containers.schemas.PodmanMachineInspect(machines=json.loads(json_data))
machines = inspect.machines

machine = next((m for m in machines if machine_predicate(m)), None)
if not machine:
raise ValueError(f"Machine matching given predicate not found")
raise ValueError(f"Machine matching given predicate not found:"
f" the available machines are: {machines}")

ssh_command = [
"ssh",
Expand Down
1 change: 1 addition & 0 deletions tests/containers/workbenches/workbench_image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_ipv6_only(self, image: str, test_frame):
host = "localhost"
port = podman_machine_utils.find_free_port()
socket_path = os.path.realpath(docker_utils.get_socket_path(client.client))
logging.debug(f"{socket_path=}")
process = podman_machine_utils.open_ssh_tunnel(
machine_predicate=lambda m: os.path.realpath(m.ConnectionInfo.PodmanSocket.Path) == socket_path,
local_port=port, remote_port=container.port,
Expand Down

0 comments on commit 22f1d9c

Please sign in to comment.