From 6a0493a75282ad7b9de2f4fae68dce255d5bd951 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 7 Oct 2022 01:18:37 -0700 Subject: [PATCH] action_utils: Drop support for non-systemd environments - There hasn't been a need for this for a long time. non-systemd environments haven't been worked on or tested for in a long time. - Keep the is_systemd_running() method for future use. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/action_utils.py | 17 ++++------------- plinth/modules/calibre/tests/test_privileged.py | 2 +- .../modules/ejabberd/tests/test_turn_config.py | 2 +- .../matrixsynapse/tests/test_turn_config.py | 6 ++++-- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/plinth/action_utils.py b/plinth/action_utils.py index 3247fb90c..c3d6945f9 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -39,13 +39,8 @@ def service_is_running(servicename): Does not need to run as root. """ try: - if is_systemd_running(): - subprocess.run(['systemctl', 'status', servicename], check=True, - stdout=subprocess.DEVNULL) - else: - subprocess.run(['service', servicename, 'status'], check=True, - stdout=subprocess.DEVNULL) - + subprocess.run(['systemctl', 'status', servicename], check=True, + stdout=subprocess.DEVNULL) return True except subprocess.CalledProcessError: # If a service is not running we get a status code != 0 and @@ -126,12 +121,8 @@ def service_reload(service_name): def service_action(service_name, action): """Perform the given action on the service_name.""" - if is_systemd_running(): - subprocess.run(['systemctl', action, service_name], - stdout=subprocess.DEVNULL, check=False) - else: - subprocess.run(['service', service_name, action], - stdout=subprocess.DEVNULL, check=False) + subprocess.run(['systemctl', action, service_name], + stdout=subprocess.DEVNULL, check=False) def webserver_is_enabled(name, kind='config'): diff --git a/plinth/modules/calibre/tests/test_privileged.py b/plinth/modules/calibre/tests/test_privileged.py index 2b85f3eab..6b41173f8 100644 --- a/plinth/modules/calibre/tests/test_privileged.py +++ b/plinth/modules/calibre/tests/test_privileged.py @@ -30,7 +30,7 @@ def fixture_patch(): path.touch() with patch('subprocess.call') as subprocess_call, \ - patch('shutil.chown'): + patch('subprocess.run'), patch('shutil.chown'): subprocess_call.side_effect = side_effect yield diff --git a/plinth/modules/ejabberd/tests/test_turn_config.py b/plinth/modules/ejabberd/tests/test_turn_config.py index 564418a5e..f88618c47 100644 --- a/plinth/modules/ejabberd/tests/test_turn_config.py +++ b/plinth/modules/ejabberd/tests/test_turn_config.py @@ -66,7 +66,7 @@ def fixture_test_configuration(conf_file): def _set_turn_configuration(config=managed_configuration, managed=True): - with patch('plinth.privileged.service.is_running', return_value=False): + with patch('plinth.action_utils.service_is_running', return_value=False): ejabberd.update_turn_configuration(config, managed=managed) diff --git a/plinth/modules/matrixsynapse/tests/test_turn_config.py b/plinth/modules/matrixsynapse/tests/test_turn_config.py index 9a5f7b961..9971e070b 100644 --- a/plinth/modules/matrixsynapse/tests/test_turn_config.py +++ b/plinth/modules/matrixsynapse/tests/test_turn_config.py @@ -72,12 +72,14 @@ updated_coturn_configuration = TurnConfiguration( def _set_managed_configuration(config=coturn_configuration): - matrixsynapse.update_turn_configuration(config) + with patch('plinth.action_utils.service_try_restart'): + matrixsynapse.update_turn_configuration(config) def _set_overridden_configuration( config=overridden_configuration): - matrixsynapse.update_turn_configuration(config, managed=False) + with patch('plinth.action_utils.service_try_restart'): + matrixsynapse.update_turn_configuration(config, managed=False) def _assert_conf(expected_configuration, expected_managed):