*: Use action_utils.run instead of subprocess.run

- This is to capture stdout and stderr and transmit that from privileged daemon
back to the service to be displayed in HTML.

Tests:

- Unit tests and code checks pass.

- Some of the modified actions work as expected.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa authored and Veiko Aasa committed 2025-09-29 16:58:53 +03:00
1 parent 355812c9f2
commit 61ff15a04f
36 files changed
+257 -244

No files matched your search

+9 -9
View File
@@ -36,10 +36,10 @@ def _flush_iptables_rules():
iptables_rules += rule_template.format(table=table)
ip6tables_rules += rule_template.format(table=table)
subprocess.run(['iptables-restore'], input=iptables_rules.encode(),
check=True)
subprocess.run(['ip6tables-restore'], input=iptables_rules.encode(),
check=True)
action_utils.run(['iptables-restore'], input=iptables_rules.encode(),
check=True)
action_utils.run(['ip6tables-restore'], input=iptables_rules.encode(),
check=True)
def set_firewall_backend(backend):
@@ -67,8 +67,8 @@ def set_firewall_backend(backend):
def _run_firewall_cmd(args):
"""Run firewall-cmd command, discard output and check return value."""
subprocess.run(['firewall-cmd'] + args, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, check=True)
action_utils.run(['firewall-cmd'] + args, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, check=True)
def _setup_local_service_protection():
@@ -160,9 +160,9 @@ def _setup_inter_zone_forwarding():
def setup():
"""Perform basic firewalld setup."""
action_utils.service_enable('firewalld')
subprocess.run(['firewall-cmd', '--set-default-zone=external'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
check=True)
action_utils.run(['firewall-cmd', '--set-default-zone=external'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
check=True)
set_firewall_backend('nftables')
_setup_local_service_protection()