mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
daemon: Implement diagnostic test to check if a daemon is running
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
9cc3ddea2c
commit
68bc2f45a5
@ -62,14 +62,26 @@ class Daemon(app.LeaderComponent):
|
|||||||
return action_utils.service_is_running(self.unit)
|
return action_utils.service_is_running(self.unit)
|
||||||
|
|
||||||
def diagnose(self):
|
def diagnose(self):
|
||||||
"""Check if the daemon is listening on expected ports."""
|
"""Check if the daemon is running and listening on expected ports.
|
||||||
|
|
||||||
|
See :py:meth:`plinth.app.Component.diagnose`.
|
||||||
|
|
||||||
|
"""
|
||||||
results = []
|
results = []
|
||||||
|
results.append(self._diagnose_unit_is_running())
|
||||||
for port in self.listen_ports:
|
for port in self.listen_ports:
|
||||||
results.append(
|
results.append(
|
||||||
action_utils.diagnose_port_listening(port[0], port[1]))
|
action_utils.diagnose_port_listening(port[0], port[1]))
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def _diagnose_unit_is_running(self):
|
||||||
|
"""Check if a daemon is running."""
|
||||||
|
message = _('Service {service_name} is running').format(
|
||||||
|
service_name=self.unit)
|
||||||
|
result = 'passed' if self.is_running() else 'failed'
|
||||||
|
return [message, result]
|
||||||
|
|
||||||
|
|
||||||
def app_is_running(app_):
|
def app_is_running(app_):
|
||||||
"""Return whether all the daemons in the app are running."""
|
"""Return whether all the daemons in the app are running."""
|
||||||
|
|||||||
@ -92,8 +92,9 @@ def test_is_running(service_is_running, daemon):
|
|||||||
assert not daemon.is_running()
|
assert not daemon.is_running()
|
||||||
|
|
||||||
|
|
||||||
|
@patch('plinth.action_utils.service_is_running')
|
||||||
@patch('plinth.action_utils.diagnose_port_listening')
|
@patch('plinth.action_utils.diagnose_port_listening')
|
||||||
def test_diagnose(diagnose_port_listening, daemon):
|
def test_diagnose(diagnose_port_listening, service_is_running, daemon):
|
||||||
"""Test running diagnostics."""
|
"""Test running diagnostics."""
|
||||||
def side_effect(port, kind):
|
def side_effect(port, kind):
|
||||||
return [f'test-result-{port}-{kind}', 'passed']
|
return [f'test-result-{port}-{kind}', 'passed']
|
||||||
@ -101,11 +102,18 @@ def test_diagnose(diagnose_port_listening, daemon):
|
|||||||
daemon = Daemon('test-daemon', 'test-unit', listen_ports=[(8273, 'tcp4'),
|
daemon = Daemon('test-daemon', 'test-unit', listen_ports=[(8273, 'tcp4'),
|
||||||
(345, 'udp')])
|
(345, 'udp')])
|
||||||
diagnose_port_listening.side_effect = side_effect
|
diagnose_port_listening.side_effect = side_effect
|
||||||
|
service_is_running.return_value = True
|
||||||
results = daemon.diagnose()
|
results = daemon.diagnose()
|
||||||
assert results == [['test-result-8273-tcp4', 'passed'],
|
assert results == [['Service test-unit is running', 'passed'],
|
||||||
|
['test-result-8273-tcp4', 'passed'],
|
||||||
['test-result-345-udp', 'passed']]
|
['test-result-345-udp', 'passed']]
|
||||||
diagnose_port_listening.assert_has_calls(
|
diagnose_port_listening.assert_has_calls(
|
||||||
[call(8273, 'tcp4'), call(345, 'udp')])
|
[call(8273, 'tcp4'), call(345, 'udp')])
|
||||||
|
service_is_running.assert_has_calls([call('test-unit')])
|
||||||
|
|
||||||
|
service_is_running.return_value = False
|
||||||
|
results = daemon.diagnose()
|
||||||
|
assert results[0][1] == 'failed'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('plinth.action_utils.service_is_running')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user