mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-27 20:25:55 -04:00
Use isctest.run.cmd() helper function in tests
(cherry picked from commit 77a42f8875)
This commit is contained in:
parent
78c3838310
commit
ec42164265
6 changed files with 23 additions and 43 deletions
|
|
@ -14,10 +14,10 @@
|
|||
from typing import NamedTuple, Tuple
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import isctest
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("dns", minversion="2.0.0")
|
||||
|
|
@ -86,7 +86,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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(";")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue