]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use isctest.run.cmd() helper function in tests
authorMichal Nowak <mnowak@isc.org>
Wed, 20 Mar 2024 12:59:34 +0000 (13:59 +0100)
committerMichal Nowak <mnowak@isc.org>
Tue, 14 May 2024 09:45:55 +0000 (11:45 +0200)
bin/tests/system/checkds/tests_checkds.py
bin/tests/system/doth/conftest.py
bin/tests/system/doth/tests_sslyze.py
bin/tests/system/masterfile/tests_masterfile.py
bin/tests/system/rrchecker/tests_rrchecker.py
bin/tests/system/stress/tests_stress_update.py

index f369f2e3fb1a6d4ddbfb8a48e6e9aa2c6ba3600b..0af90c2957ee5285c5c11cdcbd53df2db10b5ca6 100755 (executable)
 from typing import NamedTuple, Tuple
 
 import os
-import subprocess
 import sys
 import time
 
+import isctest
 import pytest
 
 pytest.importorskip("dns", minversion="2.0.0")
@@ -87,7 +87,7 @@ def verify_zone(zone, transfer):
     # dnssec-verify command with default arguments.
     verify_cmd = [verify, "-z", "-o", zone, filename]
 
-    verifier = subprocess.run(verify_cmd, capture_output=True, check=True)
+    verifier = isctest.run.cmd(verify_cmd)
 
     if verifier.returncode != 0:
         print(f"error: dnssec-verify {zone} failed")
@@ -234,7 +234,7 @@ def rekey(zone):
         "loadkeys",
         zone,
     ]
-    controller = subprocess.run(rndc_cmd, capture_output=True, check=True)
+    controller = isctest.run.cmd(rndc_cmd)
 
     if controller.returncode != 0:
         print(f"error: rndc loadkeys {zone} failed")
index 813be146f40c42724b382774f0c75c14830c0299..27dca7ee8a47d63a35b70d7279de432634bab5bc 100644 (file)
@@ -12,9 +12,9 @@
 # information regarding copyright ownership.
 
 import shutil
-import subprocess
 
 import pytest
+import isctest
 
 
 @pytest.fixture
@@ -25,11 +25,8 @@ def gnutls_cli_executable():
         pytest.skip("gnutls-cli not found in PATH")
 
     # Ensure gnutls-cli supports the --logfile command-line option.
-    output = subprocess.run(
-        [executable, "--logfile=/dev/null"],
-        stdout=subprocess.PIPE,
-        stderr=subprocess.STDOUT,
-        check=False,
+    output = isctest.run.cmd(
+        [executable, "--logfile=/dev/null"], log_stderr=False, raise_on_exception=False
     ).stdout
     if b"illegal option" in output:
         pytest.skip("gnutls-cli does not support the --logfile option")
index 2562fe482d70dadf3ffe634c42f1820734ba8d06..a904e7c12e54e13a44de2cf94bdde73a90def58d 100644 (file)
@@ -15,6 +15,7 @@ import os
 import pathlib
 import subprocess
 
+import isctest
 import pytest
 
 
@@ -46,12 +47,12 @@ def run_sslyze_in_a_loop(executable, port, log_file_prefix):
             # Run sslyze, logging stdout+stderr.  Ignore the exit code since
             # sslyze is only used for triggering crashes here rather than
             # actual TLS analysis.
-            subprocess.run(
+            isctest.run.cmd(
                 sslyze_args,
                 stdout=sslyze_log,
                 stderr=subprocess.STDOUT,
                 timeout=30,
-                check=False,
+                raise_on_exception=False,
             )
             # Ensure ns1 is still alive after each sslyze run.
             assert is_pid_alive(pid), f"ns1 (PID: {pid}) exited prematurely"
index 9843a47fbf6fbae75aafa83e2c09706e0b68a5a3..9aaaa769a537778003ce2f00cf3a193bc5f56c3c 100644 (file)
@@ -10,7 +10,6 @@
 # information regarding copyright ownership.
 
 import os
-import subprocess
 
 import dns.message
 import dns.zone
@@ -97,17 +96,14 @@ def test_masterfile_missing_master_file_servfail():
 
 def test_masterfile_owner_inheritance():
     """Test owner inheritance after $INCLUDE"""
-    checker_output = subprocess.run(
+    checker_output = isctest.run.cmd(
         [
             os.environ["CHECKZONE"],
             "-D",
             "-q",
             "example",
             "zone/inheritownerafterinclude.db",
-        ],
-        stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE,
-        check=True,
+        ]
     ).stdout.decode("utf-8")
     owner_inheritance_zone = """
 example.       0       IN      SOA     . . 0 0 0 0 0
index 743949aaf083c46fa5a91be6e8fb6f02672f9e19..f425b83b91627532cdf71df88d9701bc51cd6da0 100644 (file)
@@ -10,8 +10,8 @@
 # information regarding copyright ownership.
 
 import os
-import subprocess
 
+import isctest
 import pytest
 
 
@@ -110,47 +110,37 @@ import pytest
     ],
 )
 def test_rrchecker_list_standard_names(option, expected_result):
-    stdout = subprocess.run(
-        [
-            os.environ["RRCHECKER"],
-            option,
-        ],
-        stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE,
-        check=True,
-    ).stdout.decode("utf-8")
+    stdout = isctest.run.cmd([os.environ["RRCHECKER"], option]).stdout.decode("utf-8")
     values = [line for line in stdout.split("\n") if line.strip()]
 
     assert sorted(values) == sorted(expected_result)
 
 
 def run_rrchecker(option, rr_class, rr_type, rr_rest):
-    with subprocess.Popen(
-        [os.environ["RRCHECKER"], option],
-        stdin=subprocess.PIPE,
-        stdout=subprocess.PIPE,
-    ) as process:
-        rrchecker_output, _ = process.communicate(
-            f"{rr_class} {rr_type} {rr_rest}".encode("utf-8")
+    rrchecker_output = (
+        isctest.run.cmd(
+            [os.environ["RRCHECKER"], option],
+            input_text=f"{rr_class} {rr_type} {rr_rest}".encode("utf-8"),
         )
-    return rrchecker_output.decode("utf-8").split()
+        .stdout.decode("utf-8")
+        .strip()
+    )
+    return rrchecker_output.split()
 
 
 @pytest.mark.parametrize("option", ["-p", "-u"])
 def test_rrchecker_conversions(option):
     tempzone_file = "tempzone"
     with open(tempzone_file, "w", encoding="utf-8") as file:
-        subprocess.run(
+        isctest.run.cmd(
             [
                 os.environ["SHELL"],
                 os.environ["TOP_SRCDIR"] + "/bin/tests/system/genzone.sh",
                 "0",
             ],
             stdout=file,
-            stderr=subprocess.PIPE,
-            check=True,
         )
-    checkzone_output = subprocess.run(
+    checkzone_output = isctest.run.cmd(
         [
             os.environ["CHECKZONE"],
             "-D",
@@ -158,9 +148,6 @@ def test_rrchecker_conversions(option):
             ".",
             tempzone_file,
         ],
-        stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE,
-        check=True,
     ).stdout.decode("utf-8")
     checkzone_output = [
         line for line in checkzone_output.splitlines() if not line.startswith(";")
index 11044830d5644fbbeb8b37af5b7961f39d4be7b7..4c6f1f36942a2af8279a89430b5bf1439f9f0706 100644 (file)
@@ -11,7 +11,6 @@
 
 import concurrent.futures
 import os
-import subprocess
 import time
 
 import dns.query
@@ -36,7 +35,7 @@ def rndc_loop(test_state, server):
     ]
 
     while not test_state["finished"]:
-        subprocess.run(cmdline, check=False)
+        isctest.run.cmd(cmdline, raise_on_exception=False)
         time.sleep(1)