mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
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:
parent
9295914a6c
commit
32b470bc7c
@ -27,7 +27,7 @@ TODO:
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from plinth import actions, action_utils, module_loader
|
from plinth import actions, action_utils, module_loader, setup
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -204,6 +204,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
|
|||||||
restore_root = subvolume['mount_path']
|
restore_root = subvolume['mount_path']
|
||||||
subvolume = True
|
subvolume = True
|
||||||
else:
|
else:
|
||||||
|
_install_apps_before_restore(apps)
|
||||||
_lockdown_apps(apps, lockdown=True)
|
_lockdown_apps(apps, lockdown=True)
|
||||||
original_state = _shutdown_services(apps)
|
original_state = _shutdown_services(apps)
|
||||||
restore_root = '/'
|
restore_root = '/'
|
||||||
@ -220,6 +221,16 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
|
|||||||
_lockdown_apps(apps, lockdown=False)
|
_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:
|
class BackupApp:
|
||||||
"""A application that can be backed up and its manifest."""
|
"""A application that can be backed up and its manifest."""
|
||||||
|
|
||||||
@ -228,10 +239,6 @@ class BackupApp:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
# Not installed
|
|
||||||
if app.setup_helper.get_state() == 'needs-setup':
|
|
||||||
raise TypeError
|
|
||||||
|
|
||||||
# Has no backup related meta data
|
# Has no backup related meta data
|
||||||
try:
|
try:
|
||||||
self.manifest = app.backup
|
self.manifest = app.backup
|
||||||
|
|||||||
@ -110,7 +110,8 @@ class TestBackupProcesses(unittest.TestCase):
|
|||||||
backup_handler.assert_called_once()
|
backup_handler.assert_called_once()
|
||||||
|
|
||||||
@staticmethod
|
@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."""
|
"""Test that restore_handler is called."""
|
||||||
restore_handler = MagicMock()
|
restore_handler = MagicMock()
|
||||||
api.restore_apps(restore_handler)
|
api.restore_apps(restore_handler)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user