Added passing arguments to log and status

This allows automated tests to run smoother.

Currently there are 2 tests that block the console for input:
* edit
* shell
This commit is contained in:
Lockszmith 2024-06-27 18:18:09 -04:00 committed by Jip-Hop
parent 2841137177
commit 1b796ca2cf
1 changed files with 14 additions and 5 deletions

View File

@ -490,21 +490,23 @@ def exec_jail(jail_name, cmd):
).returncode
def status_jail(jail_name):
def status_jail(jail_name, cmd_args):
"""
Show the status of the systemd service wrapping the jail with given name.
"""
# Alternatively `machinectl status jail_name` could be used
if not cmd_args: cmd_args = []
return subprocess.run(
["systemctl", "status", f"{SHORTNAME}-{jail_name}"]
["systemctl", "status", f"{SHORTNAME}-{jail_name}", *cmd_args, ]
).returncode
def log_jail(jail_name):
def log_jail(jail_name, cmd_args):
"""
Show the log file of the jail with given name.
"""
return subprocess.run(["journalctl", "-u", f"{SHORTNAME}-{jail_name}"]).returncode
if not cmd_args: cmd_args = ["-xe"]
return subprocess.run(["journalctl", *cmd_args, "-u", f"{SHORTNAME}-{jail_name}"]).returncode
def shell_jail(args):
@ -1807,7 +1809,7 @@ def main():
title="commands", dest="command", metavar="", parser_class=CustomSubParser
)
split_commands = ["create", "exec"]
split_commands = ["create", "exec", "log", "status"]
commands = {}
for d in [
@ -1883,6 +1885,13 @@ def main():
for cmd in ["edit", "exec", "log", "remove", "restart", "start", "status", "stop"]:
commands[cmd].add_argument("jail_name", help="name of the jail")
for cmd in ["log", "status"]:
commands[cmd].add_argument(
"cmd_args",
nargs="*",
help="journalctl arguments",
)
commands["exec"].add_argument(
"cmd",
nargs="*",