app: Introduce API to setup an app

Like the earlier API, accept old_version as parameter. A base implementation,
simply call setup on all components.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-11-16 08:17:22 -08:00 committed by James Valleroy
parent 80d0a7638c
commit 057a125531
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 37 additions and 1 deletions

View File

@ -113,6 +113,11 @@ class App:
"""
return self.get_component(self.app_id + '-info')
def setup(self, old_version):
"""Install and configure the app and its components."""
for component in self.components.values():
component.setup(old_version=old_version)
def enable(self):
"""Enable all the components of the app."""
for component in self.components.values():
@ -221,6 +226,9 @@ class Component:
"""
return App.get(self.app_id)
def setup(self, old_version):
"""Run operations to install and configure the component."""
def enable(self):
"""Run operations to enable the component."""

View File

@ -4,7 +4,7 @@ Test module for App, base class for all applications.
"""
import collections
from unittest.mock import patch
from unittest.mock import Mock, call, patch
import pytest
@ -114,6 +114,16 @@ def test_get_components_of_type(app_with_components):
assert list(components) == leader_components
def test_app_setup(app_with_components):
"""Test that running setup on an app run setup on components."""
for component in app_with_components.components.values():
component.setup = Mock()
app_with_components.setup(old_version=2)
for component in app_with_components.components.values():
component.setup.assert_has_calls([call(old_version=2)])
def test_app_enable(app_with_components):
"""Test that enabling an app enables components."""
app_with_components.disable()
@ -222,6 +232,24 @@ def test_component_app_property():
assert component.app == app
def test_component_setup():
"""Test running setup on component."""
component = Component('test-component')
assert component.setup(old_version=1) is None
def test_component_enable():
"""Test running enable on component."""
component = Component('test-component')
assert component.enable() is None
def test_component_disable():
"""Test running disable on component."""
component = Component('test-component')
assert component.disable() is None
def test_component_diagnose():
"""Test running diagnostics on component."""
component = Component('test-component')