Verified Commit 47084a1b authored by Sebastian Endres's avatar Sebastian Endres
Browse files

Add --clean to inject_secrets

parent 3cdf0b44
......@@ -21,6 +21,11 @@ def parse_args():
type=Path,
help="quic-interop-runner log dirs or result.json files",
)
parser.add_argument(
"--clean",
action="store_true",
help="Delete plain pcap files after injecting the secrets into pcapng file.",
)
parser.add_argument(
"--debug",
action="store_true",
......@@ -31,7 +36,7 @@ def parse_args():
class SecretsInjector:
def __init__(self, specs: list[Union[Path, Result]], debug=False):
def __init__(self, specs: list[Union[Path, Result]], clean=False, debug=False):
self.specs = specs
self.num_injected = 0
self.num_already_injected = 0
......@@ -39,6 +44,7 @@ class SecretsInjector:
self.num_failed = 0
self._max_log_str_len = 0
self.debug = debug
self.clean = clean
self._spinner: Optional[YaspinWrapper] = None
def find_keylog_file(self, test_case_path: Path) -> Optional[Path]:
......@@ -62,20 +68,20 @@ class SecretsInjector:
return results[0]
def inject(self, pcap_path: Path, pcap_ng_path: Path, keylog_file: Path):
if not pcap_path.is_file():
if pcap_ng_path.is_file() and pcap_ng_path.stat().st_size > 0:
self.log(
f"⨯ Raw pcap file {pcap_path} not found. Skipping.",
color="red",
f" {pcap_ng_path} already exists. Skipping.",
color="grey",
)
self.num_already_injected += 1
return
if pcap_ng_path.is_file() and pcap_ng_path.stat().st_size > 0:
if not pcap_path.is_file():
self.log(
f" {pcap_ng_path} already exists. Skipping.",
color="grey",
f"⨯ Raw pcap file {pcap_path} not found. Skipping.",
color="red",
)
self.num_already_injected += 1
return
......@@ -94,6 +100,9 @@ class SecretsInjector:
]
)
self.num_injected += 1
if self.clean:
pcap_path.unlink()
except subprocess.CalledProcessError:
self.log(
f"⨯ Failed to inject secrets {keylog_file} into {pcap_path}.",
......@@ -128,20 +137,27 @@ class SecretsInjector:
pcap_ng_path=pcap_ng_path,
keylog_file=keylog_file,
)
self.log()
def inject_in_result(self, result: Result):
"""Inject secrets in result log dir."""
for test_result in result.all_test_results:
if test_result.result == "unsupported":
continue
self.inject_in_test_repetition_run_dir(test_result.log_dir_for_test)
for meas_result in result.all_measurement_results:
if meas_result.result == "unsupported":
continue
for repetition_log_dir in meas_result.repetition_log_dirs:
self.inject_in_test_repetition_run_dir(repetition_log_dir)
def inject_in_log_dir(self, log_dir: Path):
"""Inject Secrets"""
"""Inject secrets."""
for combination in log_dir.iterdir():
if not combination.is_dir():
......@@ -176,10 +192,10 @@ class SecretsInjector:
log_str = ", ".join(
(
colored(f"injected: {self.num_injected}, ", color="green"),
colored(f"failed: {self.num_failed}, ", color="red"),
colored(f"injected: {self.num_injected}", color="green"),
colored(f"failed: {self.num_failed}", color="red"),
colored(
f"already injected: {self.num_already_injected}, ", color="yellow"
f"already injected: {self.num_already_injected}", color="yellow"
),
colored(
f"no keylog file found: {self.num_no_secret_found}", color="red"
......@@ -216,6 +232,7 @@ def main():
args = parse_args()
cli = SecretsInjector(
specs=[Result(spec) if spec.is_file() else spec for spec in args.spec],
clean=args.clean,
debug=args.debug,
)
cli.run()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment