app, component: Add repair method

- Allows apps and component to implement custom repair methods.

- Default implementation asks relevant components to repair, and then if
  needed, requests re-run setup for the app.

- Component.repair will return True by default, indicating that setup should be
  re-run.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Minor docstring styling fixes]
[sunil: Improve tests for repair]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2024-05-02 21:45:25 -07:00
1 parent ddc9b434a7
commit f487565b2c
2 files changed
+89 -5

No files matched your search

+39
View File
@@ -279,6 +279,38 @@ def test_app_has_diagnostics(app_with_components):
assert app.has_diagnostics()
@patch('plinth.setup.run_setup_on_app')
def test_app_repair(_run_setup_on_app, app_with_components):
"""Test running repair on an app."""
component = app_with_components.get_component('test-follower-1')
component.repair = Mock(return_value=True)
check1 = DiagnosticCheck('check1', 'check1', Result.FAILED, {})
check2 = DiagnosticCheck('check2', 'check2', Result.WARNING, {})
check3 = DiagnosticCheck('check3', 'check3', Result.FAILED, {},
'test-follower-1')
should_rerun_setup = app_with_components.repair([])
assert not should_rerun_setup
should_rerun_setup = app_with_components.repair([check1])
assert should_rerun_setup
should_rerun_setup = app_with_components.repair([check2])
assert should_rerun_setup
should_rerun_setup = app_with_components.repair([check1, check2])
assert should_rerun_setup
component.repair.assert_not_called()
should_rerun_setup = app_with_components.repair([check3])
assert should_rerun_setup
assert component.repair.mock_calls == [call([check3])]
component.repair = Mock(return_value=False)
should_rerun_setup = app_with_components.repair([check3])
assert not should_rerun_setup
def test_component_initialization():
"""Test that component is initialized properly."""
with pytest.raises(ValueError):
@@ -340,6 +372,13 @@ def test_component_has_diagnostics():
assert not component.has_diagnostics()
@patch('plinth.setup.run_setup_on_app')
def test_component_repair(_run_setup_on_app):
"""Test running repair on component."""
component = Component('test-component')
assert component.repair(['test-check'])
def test_follower_component_initialization():
"""Test that follower component is initialized properly."""
component = FollowerComponent('test-follower-1')