From 898d6659000f075f8b3edf57a204f3b8dbf1a43f Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 15 Jun 2018 15:29:05 +0200 Subject: [PATCH] Remove archivemount stuff (#491) --- debian/control | 2 +- src/yunohost/backup.py | 89 +++++++++------------- src/yunohost/tests/test_backuprestore.py | 96 +----------------------- 3 files changed, 39 insertions(+), 148 deletions(-) diff --git a/debian/control b/debian/control index ba5f65b6c..256038598 100644 --- a/debian/control +++ b/debian/control @@ -33,7 +33,7 @@ Recommends: yunohost-admin , python-pip , unattended-upgrades , libdbd-ldap-perl, libnet-dns-perl -Suggests: htop, vim, rsync, acpi-support-base, udisks2, archivemount +Suggests: htop, vim, rsync, acpi-support-base, udisks2 Conflicts: iptables-persistent , moulinette-yunohost, yunohost-config , yunohost-config-others, yunohost-config-postfix diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 1fe67e406..db0f44abe 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -1316,9 +1316,7 @@ class BackupMethod(object): TarBackupMethod --------------- This method compresses all files to backup in a .tar.gz archive. When - restoring, it tries to mount the archive using archivemount/fuse instead - of untaring the archive. Some systems don't support fuse (for these, - it automatically falls back to untaring the required parts). + restoring, it untars the required parts. CustomBackupMethod ------------------ @@ -1687,8 +1685,7 @@ class CopyBackupMethod(BackupMethod): class TarBackupMethod(BackupMethod): """ - This class compress all files to backup in archive. To restore it try to - mount the archive with archivemount (fuse). Some system don't support fuse. + This class compress all files to backup in archive. """ def __init__(self, repo=None): @@ -1760,8 +1757,6 @@ class TarBackupMethod(BackupMethod): Exceptions: backup_archive_open_failed -- Raised if the archive can't be open - backup_archive_mount_failed -- Raised if the system don't support - archivemount """ super(TarBackupMethod, self).mount(restore_manager) @@ -1776,60 +1771,50 @@ class TarBackupMethod(BackupMethod): tar.close() # Mount the tarball + logger.debug(m18n.n("restore_extracting")) + tar = tarfile.open(self._archive_file, "r:gz") + tar.extract('info.json', path=self.work_dir) + try: - ret = subprocess.call(['archivemount', '-o', 'readonly', - self._archive_file, self.work_dir]) - except: - ret = -1 + tar.extract('backup.csv', path=self.work_dir) + except KeyError: + # Old backup archive have no backup.csv file + pass - # If archivemount failed, extract the archive - if ret != 0: - logger.warning(m18n.n('backup_archive_mount_failed')) + # Extract system parts backup + conf_extracted = False - logger.debug(m18n.n("restore_extracting")) - tar = tarfile.open(self._archive_file, "r:gz") - tar.extract('info.json', path=self.work_dir) + system_targets = self.manager.targets.list("system", exclude=["Skipped"]) + apps_targets = self.manager.targets.list("apps", exclude=["Skipped"]) - try: - tar.extract('backup.csv', path=self.work_dir) - except KeyError: - # Old backup archive have no backup.csv file - pass - - # Extract system parts backup - conf_extracted = False - - system_targets = self.manager.targets.list("system", exclude=["Skipped"]) - apps_targets = self.manager.targets.list("apps", exclude=["Skipped"]) - - for system_part in system_targets: - # Caution: conf_ynh_currenthost helpers put its files in - # conf/ynh - if system_part.startswith("conf_"): - if conf_extracted: - continue - system_part = "conf/" - conf_extracted = True - else: - system_part = system_part.replace("_", "/") + "/" - subdir_and_files = [ - tarinfo for tarinfo in tar.getmembers() - if tarinfo.name.startswith(system_part) - ] - tar.extractall(members=subdir_and_files, path=self.work_dir) + for system_part in system_targets: + # Caution: conf_ynh_currenthost helpers put its files in + # conf/ynh + if system_part.startswith("conf_"): + if conf_extracted: + continue + system_part = "conf/" + conf_extracted = True + else: + system_part = system_part.replace("_", "/") + "/" subdir_and_files = [ tarinfo for tarinfo in tar.getmembers() - if tarinfo.name.startswith("hooks/restore/") + if tarinfo.name.startswith(system_part) ] tar.extractall(members=subdir_and_files, path=self.work_dir) + subdir_and_files = [ + tarinfo for tarinfo in tar.getmembers() + if tarinfo.name.startswith("hooks/restore/") + ] + tar.extractall(members=subdir_and_files, path=self.work_dir) - # Extract apps backup - for app in apps_targets: - subdir_and_files = [ - tarinfo for tarinfo in tar.getmembers() - if tarinfo.name.startswith("apps/" + app) - ] - tar.extractall(members=subdir_and_files, path=self.work_dir) + # Extract apps backup + for app in apps_targets: + subdir_and_files = [ + tarinfo for tarinfo in tar.getmembers() + if tarinfo.name.startswith("apps/" + app) + ] + tar.extractall(members=subdir_and_files, path=self.work_dir) class BorgBackupMethod(BackupMethod): diff --git a/src/yunohost/tests/test_backuprestore.py b/src/yunohost/tests/test_backuprestore.py index 8c860fc60..1071c1642 100644 --- a/src/yunohost/tests/test_backuprestore.py +++ b/src/yunohost/tests/test_backuprestore.py @@ -101,9 +101,6 @@ def app_is_installed(app): def backup_test_dependencies_are_met(): - # We need archivemount installed for the backup features to work - assert os.system("which archivemount >/dev/null") == 0 - # Dummy test apps (or backup archives) assert os.path.exists("./tests/apps/backup_wordpress_from_2p4") assert os.path.exists("./tests/apps/backup_legacy_app_ynh") @@ -250,42 +247,6 @@ def test_backup_and_restore_all_sys(): assert os.path.exists("/etc/ssowat/conf.json") -def test_backup_and_restore_archivemount_failure(monkeypatch, mocker): - - # Create the backup - backup_create(ignore_system=False, ignore_apps=True) - - archives = backup_list()["archives"] - assert len(archives) == 1 - - archives_info = backup_info(archives[0], with_details=True) - assert archives_info["apps"] == {} - assert (len(archives_info["system"].keys()) == - len(os.listdir("/usr/share/yunohost/hooks/backup/"))) - - # Remove ssowat conf - assert os.path.exists("/etc/ssowat/conf.json") - os.system("rm -rf /etc/ssowat/") - assert not os.path.exists("/etc/ssowat/conf.json") - - def custom_subprocess_call(*args, **kwargs): - import subprocess as subprocess2 - if args[0] and args[0][0]=="archivemount": - monkeypatch.undo() - return 1 - return subprocess.call(*args, **kwargs) - - monkeypatch.setattr("subprocess.call", custom_subprocess_call) - mocker.spy(m18n, "n") - - # Restore the backup - backup_restore(auth, name=archives[0], force=True, - ignore_system=False, ignore_apps=True) - - # Check ssowat conf is back - assert os.path.exists("/etc/ssowat/conf.json") - - ############################################################################### # System restore from 2.4 # ############################################################################### @@ -311,38 +272,6 @@ def test_restore_system_from_Ynh2p4(monkeypatch, mocker): ignore_apps=True, force=True) - -@pytest.mark.with_system_archive_from_2p4 -def test_restore_system_from_Ynh2p4_archivemount_failure(monkeypatch, mocker): - - # Backup current system - backup_create(ignore_system=False, ignore_apps=True) - archives = backup_list()["archives"] - assert len(archives) == 2 - - def custom_subprocess_call(*args, **kwargs): - import subprocess as subprocess2 - if args[0] and args[0][0]=="archivemount": - monkeypatch.undo() - return 1 - return subprocess.call(*args, **kwargs) - - monkeypatch.setattr("subprocess.call", custom_subprocess_call) - - try: - # Restore system from 2.4 - backup_restore(auth, name=backup_list()["archives"][1], - ignore_system=False, - ignore_apps=True, - force=True) - finally: - # Restore system as it was - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=False, - ignore_apps=True, - force=True) - - ############################################################################### # App backup # ############################################################################### @@ -545,29 +474,6 @@ def test_restore_app_not_in_backup(mocker): assert not _is_installed("yoloswag") -@pytest.mark.with_wordpress_archive_from_2p4 -def test_restore_app_archivemount_failure(monkeypatch, mocker): - - def custom_subprocess_call(*args, **kwargs): - import subprocess as subprocess2 - if args[0] and args[0][0]=="archivemount": - monkeypatch.undo() - return 1 - return subprocess.call(*args, **kwargs) - - monkeypatch.setattr("subprocess.call", custom_subprocess_call) - mocker.spy(m18n, "n") - - assert not _is_installed("wordpress") - - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, - apps=["wordpress"]) - - assert _is_installed("wordpress") - - @pytest.mark.with_wordpress_archive_from_2p4 def test_restore_app_already_installed(mocker): @@ -643,7 +549,7 @@ def test_restore_archive_with_no_json(mocker): # Create a backup with no info.json associated os.system("touch /tmp/afile") os.system("tar -czvf /home/yunohost.backup/archives/badbackup.tar.gz /tmp/afile") - + assert "badbackup" in backup_list()["archives"] mocker.spy(m18n, "n")