mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
daemon: When ensuring running state handle not-installed state
Tests: - Uninstall miniflux and postgresql. Install freshly with all the patches in this series. When installing miniflux freshly, postgresql is not disabled soon after miniflux package is installed. Without this patch, postgresql is disabled after packages are installed leading to a setup failure. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
4ed2a25a8b
commit
f9ca06dc5f
@ -91,6 +91,13 @@ class Daemon(app.LeaderComponent, log.LogEmitter):
|
||||
def ensure_running(self):
|
||||
"""Ensure a service is running and return to previous state."""
|
||||
from plinth.privileged import service as service_privileged
|
||||
|
||||
if action_utils.service_show(self.unit)['LoadState'] == 'not-found':
|
||||
# The service's package not installed yet, don't try to start it
|
||||
# and later stop it after it is installed.
|
||||
yield False # Not running
|
||||
return
|
||||
|
||||
starting_state = self.is_running()
|
||||
if not starting_state:
|
||||
service_privileged.enable(self.unit)
|
||||
|
||||
@ -145,12 +145,21 @@ def test_is_running(service_is_running, daemon):
|
||||
|
||||
@patch('plinth.app.apps_init')
|
||||
@patch('plinth.action_utils.service_is_running')
|
||||
@patch('plinth.action_utils.service_show')
|
||||
@patch('subprocess.run')
|
||||
def test_ensure_running(subprocess_run, service_is_running, apps_init,
|
||||
app_list, mock_privileged, daemon):
|
||||
def test_ensure_running(subprocess_run, service_show, service_is_running,
|
||||
apps_init, app_list, mock_privileged, daemon):
|
||||
"""Test that checking that the daemon is running works."""
|
||||
common_args = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
check=False)
|
||||
|
||||
service_show.return_value = {'LoadState': 'not-found'}
|
||||
with daemon.ensure_running() as starting_state:
|
||||
assert not starting_state
|
||||
assert subprocess_run.mock_calls == []
|
||||
|
||||
service_show.return_value = {'LoadState': 'loaded'}
|
||||
|
||||
service_is_running.return_value = True
|
||||
with daemon.ensure_running() as starting_state:
|
||||
assert starting_state
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user