backup: move BackupRestore class and helpers to 'restore' submodule

This breaks cyclic imports and also allow cleaner separation between
backup make and restore code.

No functional change.
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-20 20:51:30 +02:00
parent 8d884a52e6
commit d8af76ed60
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
7 changed files with 1927 additions and 1902 deletions

View File

@ -8,7 +8,6 @@ disable=
bad-continuation,
duplicate-code,
fixme,
cyclic-import,
locally-disabled,
locally-enabled

File diff suppressed because it is too large Load Diff

1908
qubesadmin/backup/restore.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ import os
import shutil
import qubesadmin.backup
import qubesadmin.backup.restore
import qubesadmin.exc
import qubesadmin.tests
@ -177,7 +177,7 @@ class BackupTestCase(qubesadmin.tests.QubesTestCase):
backupfile = source
with self.assertNotRaises(qubesadmin.exc.QubesException):
restore_op = qubesadmin.backup.BackupRestore(
restore_op = qubesadmin.backup.restore.BackupRestore(
self.app, backupfile, appvm, passphrase)
if options:
for key, value in options.items():

View File

@ -1414,7 +1414,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
mock.patch('qubesadmin.storage.Volume',
functools.partial(MockVolume, qubesd_calls_queue)),
mock.patch(
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
mock.patch(
'qubesadmin.firewall.Firewall',
@ -1476,7 +1476,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
mock.patch('qubesadmin.storage.Volume',
functools.partial(MockVolume, qubesd_calls_queue)),
mock.patch(
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
mock.patch(
'qubesadmin.firewall.Firewall',
@ -1539,7 +1539,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
mock.patch('qubesadmin.storage.Volume',
functools.partial(MockVolume, qubesd_calls_queue)),
mock.patch(
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
mock.patch(
'qubesadmin.firewall.Firewall',
@ -1603,7 +1603,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
mock.patch('qubesadmin.storage.Volume',
functools.partial(MockVolume, qubesd_calls_queue)),
mock.patch(
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
mock.patch(
'qubesadmin.firewall.Firewall',

View File

@ -21,7 +21,8 @@ import qubesadmin.tests
import qubesadmin.tests.tools
import qubesadmin.tools.qvm_backup_restore
from unittest import mock
from qubesadmin.backup import BackupRestore, BackupVM
from qubesadmin.backup import BackupVM
from qubesadmin.backup.restore import BackupRestore
class TC_00_qvm_backup_restore(qubesadmin.tests.QubesTestCase):
@ -33,7 +34,7 @@ class TC_00_qvm_backup_restore(qubesadmin.tests.QubesTestCase):
@mock.patch('qubesadmin.tools.qvm_backup_restore.input', create=True)
@mock.patch('getpass.getpass')
@mock.patch('qubesadmin.backup.BackupRestore')
@mock.patch('qubesadmin.tools.qvm_backup_restore.BackupRestore')
def test_000_simple(self, mock_backup, mock_getpass, mock_input):
mock_getpass.return_value = 'testpass'
mock_input.return_value = 'Y'
@ -62,7 +63,7 @@ class TC_00_qvm_backup_restore(qubesadmin.tests.QubesTestCase):
@mock.patch('qubesadmin.tools.qvm_backup_restore.input', create=True)
@mock.patch('getpass.getpass')
@mock.patch('qubesadmin.backup.BackupRestore')
@mock.patch('qubesadmin.tools.qvm_backup_restore.BackupRestore')
def test_001_selected_vms(self, mock_backup, mock_getpass, mock_input):
mock_getpass.return_value = 'testpass'
mock_input.return_value = 'Y'

View File

@ -23,7 +23,7 @@
import getpass
import sys
import qubesadmin.backup
from qubesadmin.backup.restore import BackupRestore
import qubesadmin.exc
import qubesadmin.tools
import qubesadmin.utils
@ -96,20 +96,20 @@ def handle_broken(app, args, restore_info):
dom0_username_mismatch = False
for vm_info in restore_info.values():
assert isinstance(vm_info, qubesadmin.backup.BackupRestore.VMToRestore)
if qubesadmin.backup.BackupRestore.VMToRestore.EXCLUDED in \
assert isinstance(vm_info, BackupRestore.VMToRestore)
if BackupRestore.VMToRestore.EXCLUDED in \
vm_info.problems:
continue
if qubesadmin.backup.BackupRestore.VMToRestore.MISSING_TEMPLATE in \
if BackupRestore.VMToRestore.MISSING_TEMPLATE in \
vm_info.problems:
there_are_missing_templates = True
if qubesadmin.backup.BackupRestore.VMToRestore.MISSING_NETVM in \
if BackupRestore.VMToRestore.MISSING_NETVM in \
vm_info.problems:
there_are_missing_netvms = True
if qubesadmin.backup.BackupRestore.VMToRestore.ALREADY_EXISTS in \
if BackupRestore.VMToRestore.ALREADY_EXISTS in \
vm_info.problems:
there_are_conflicting_vms = True
if qubesadmin.backup.BackupRestore.Dom0ToRestore.USERNAME_MISMATCH in \
if BackupRestore.Dom0ToRestore.USERNAME_MISMATCH in \
vm_info.problems:
dom0_username_mismatch = True
@ -145,7 +145,7 @@ def handle_broken(app, args, restore_info):
"missing TemplateVMs will NOT be restored.")
elif args.ignore_missing:
app.log.warning("Ignoring missing entries: VMs that depend "
"on missing TemplateVMs will have default value "\
"on missing TemplateVMs will have default value "
"assigned.")
else:
raise qubesadmin.exc.QubesException(
@ -211,7 +211,7 @@ def main(args=None, app=None):
args.app.log.info("Checking backup content...")
try:
backup = qubesadmin.backup.BackupRestore(args.app, args.backup_location,
backup = BackupRestore(args.app, args.backup_location,
appvm, passphrase)
except qubesadmin.exc.QubesException as e:
parser.error_runtime(str(e))