tools: handle container env in generate-test-cases
When we are running inside a container we generally wont be booted with systemd and thus systemctl will fail. Fall back to check for the dnf json socket by checking the path exists and bail otherwise.
This commit is contained in:
parent
898a0f176a
commit
fc4b50e9db
1 changed files with 12 additions and 2 deletions
|
|
@ -63,8 +63,13 @@ class TestCaseGenerator:
|
||||||
def __init__(self, test_case_request):
|
def __init__(self, test_case_request):
|
||||||
self.test_case = test_case_request
|
self.test_case = test_case_request
|
||||||
|
|
||||||
def get_test_case(self, no_image_info, store):
|
def ensure_dnf_json(self):
|
||||||
compose_request = json.dumps(self.test_case["compose-request"])
|
if os.path.exists("/.dockerenv"):
|
||||||
|
if os.path.exists("/run/osbuild-dnf-json/api.sock"):
|
||||||
|
# assume we are good to go
|
||||||
|
return
|
||||||
|
print("running in container and no dnf-json socket found")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
command = ["systemctl", "is-active", "--quiet", "osbuild-dnf-json.socket"]
|
command = ["systemctl", "is-active", "--quiet", "osbuild-dnf-json.socket"]
|
||||||
if not is_subprocess_succeeding(command):
|
if not is_subprocess_succeeding(command):
|
||||||
|
|
@ -74,6 +79,11 @@ class TestCaseGenerator:
|
||||||
print("impossible to start osbuild-dnf-json.socket with systemd")
|
print("impossible to start osbuild-dnf-json.socket with systemd")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def get_test_case(self, no_image_info, store):
|
||||||
|
compose_request = json.dumps(self.test_case["compose-request"])
|
||||||
|
|
||||||
|
self.ensure_dnf_json()
|
||||||
|
|
||||||
pipeline_command = ["go", "run", "./cmd/osbuild-pipeline", "-"]
|
pipeline_command = ["go", "run", "./cmd/osbuild-pipeline", "-"]
|
||||||
self.test_case["manifest"] = json.loads(get_subprocess_stdout(pipeline_command, input=compose_request, encoding="utf-8"))
|
self.test_case["manifest"] = json.loads(get_subprocess_stdout(pipeline_command, input=compose_request, encoding="utf-8"))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue