mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
*: Use action_utils.run instead of subprocess.check_output
- 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:
1 parent
bf9005ac48
commit
b253166f6d
17 files changed
+101
-72
No files matched your search
@@ -29,8 +29,9 @@ def _sort_interfaces(interfaces: list[str]) -> list[str]:
|
||||
|
||||
def _get_interfaces() -> dict[str, list[str]]:
|
||||
"""Return all network interfaces by their type."""
|
||||
output = subprocess.check_output(
|
||||
['nmcli', '--terse', '--fields', 'type,device', 'device'])
|
||||
output = action_utils.run(
|
||||
['nmcli', '--terse', '--fields', 'type,device', 'device'],
|
||||
check=True).stdout
|
||||
interfaces = collections.defaultdict(list)
|
||||
for line in output.decode().splitlines():
|
||||
type_, _, interface = line.partition(':')
|
||||
@@ -45,8 +46,9 @@ def _get_interfaces() -> dict[str, list[str]]:
|
||||
def _add_connection(connection_name: str, interface: str,
|
||||
remaining_arguments: list[str]):
|
||||
"""Add an Ethernet/Wi-Fi connection of type regular or shared."""
|
||||
output = subprocess.check_output(
|
||||
['nmcli', '--terse', '--fields', 'name,device', 'con', 'show'])
|
||||
output = action_utils.run(
|
||||
['nmcli', '--terse', '--fields', 'name,device', 'con', 'show'],
|
||||
check=True).stdout
|
||||
lines = output.decode().splitlines()
|
||||
if f'{connection_name}:{interface}' in lines:
|
||||
logging.info('Connection %s already exists for device %s, not adding.',
|
||||
|
||||
@@ -6,10 +6,10 @@ from unittest.mock import patch
|
||||
from .. import privileged
|
||||
|
||||
|
||||
@patch('subprocess.check_output')
|
||||
def test_get_interfaces(check_output):
|
||||
@patch('subprocess.run')
|
||||
def test_get_interfaces(run):
|
||||
"""Test returning list of network interfaces in sorted order."""
|
||||
check_output.return_value = '\n'.join([
|
||||
run.return_value.stdout = '\n'.join([
|
||||
'ethernet:ve-fbx-testing',
|
||||
'ethernet:enp39s0',
|
||||
'ethernet:enp32s1',
|
||||
|
||||
Reference in new issue
Block a user