backups: Automatically install required apps before restore

Fixes #1460

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2019-01-23 10:35:00 +05:30 committed by Sunil Mohan Adapa
parent 9295914a6c
commit 32b470bc7c
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 14 additions and 6 deletions

View File

@ -27,7 +27,7 @@ TODO:
import logging
from plinth import actions, action_utils, module_loader
from plinth import actions, action_utils, module_loader, setup
logger = logging.getLogger(__name__)
@ -204,6 +204,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
restore_root = subvolume['mount_path']
subvolume = True
else:
_install_apps_before_restore(apps)
_lockdown_apps(apps, lockdown=True)
original_state = _shutdown_services(apps)
restore_root = '/'
@ -220,6 +221,16 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
_lockdown_apps(apps, lockdown=False)
def _install_apps_before_restore(apps):
"""Automatically install any applications from the backup archive
if they are not installed yet."""
modules_to_setup = []
for backup_app in apps:
if backup_app.app.setup_helper.get_state() == 'needs-setup':
modules_to_setup.append(backup_app.name)
setup.run_setup_on_modules(modules_to_setup)
class BackupApp:
"""A application that can be backed up and its manifest."""
@ -228,10 +239,6 @@ class BackupApp:
self.name = name
self.app = app
# Not installed
if app.setup_helper.get_state() == 'needs-setup':
raise TypeError
# Has no backup related meta data
try:
self.manifest = app.backup

View File

@ -110,7 +110,8 @@ class TestBackupProcesses(unittest.TestCase):
backup_handler.assert_called_once()
@staticmethod
def test_restore_apps():
@patch('plinth.modules.backups.api._install_apps_before_restore')
def test_restore_apps(mock_install):
"""Test that restore_handler is called."""
restore_handler = MagicMock()
api.restore_apps(restore_handler)