626f07efa6
test / integration-firecracker (pull_request) Failing after 5s
test / integration-docker (pull_request) Successful in 9s
tracker-policy-pr / check-pr (pull_request) Successful in 7s
test / unit (pull_request) Successful in 33s
test / coverage (pull_request) Failing after 27s
lint / lint (push) Failing after 42s
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""Docker availability check used by integration tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import unittest
|
|
|
|
|
|
def docker_available() -> bool:
|
|
if os.environ.get("SKIP_DOCKER_TESTS"):
|
|
return False
|
|
if shutil.which("docker") is None:
|
|
return False
|
|
try:
|
|
return (
|
|
subprocess.run(
|
|
["docker", "info"],
|
|
stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL,
|
|
check=False,
|
|
timeout=5,
|
|
).returncode
|
|
== 0
|
|
)
|
|
except subprocess.TimeoutExpired:
|
|
return False
|
|
|
|
|
|
def skip_unless_docker(reason: str = "docker unreachable"):
|
|
return unittest.skipUnless(docker_available(), reason)
|
|
|
|
|
|
def skip_unless_docker_or_firecracker(
|
|
reason: str = "neither Docker nor Firecracker selected",
|
|
):
|
|
"""Skip a backend-agnostic test unless one supported backend can run.
|
|
|
|
Firecracker does not require the host Docker daemon. The KVM coverage job
|
|
deliberately sets ``SKIP_DOCKER_TESTS`` to exclude Docker-only integration
|
|
classes while still exercising this path.
|
|
"""
|
|
firecracker_selected = os.environ.get("BOT_BOTTLE_BACKEND") == "firecracker"
|
|
return unittest.skipUnless(firecracker_selected or docker_available(), reason)
|