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:
parent
8d884a52e6
commit
d8af76ed60
@ -8,7 +8,6 @@ disable=
|
|||||||
bad-continuation,
|
bad-continuation,
|
||||||
duplicate-code,
|
duplicate-code,
|
||||||
fixme,
|
fixme,
|
||||||
cyclic-import,
|
|
||||||
locally-disabled,
|
locally-disabled,
|
||||||
locally-enabled
|
locally-enabled
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
1908
qubesadmin/backup/restore.py
Normal file
1908
qubesadmin/backup/restore.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -25,7 +25,7 @@ import os
|
|||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import qubesadmin.backup
|
import qubesadmin.backup.restore
|
||||||
import qubesadmin.exc
|
import qubesadmin.exc
|
||||||
import qubesadmin.tests
|
import qubesadmin.tests
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ class BackupTestCase(qubesadmin.tests.QubesTestCase):
|
|||||||
backupfile = source
|
backupfile = source
|
||||||
|
|
||||||
with self.assertNotRaises(qubesadmin.exc.QubesException):
|
with self.assertNotRaises(qubesadmin.exc.QubesException):
|
||||||
restore_op = qubesadmin.backup.BackupRestore(
|
restore_op = qubesadmin.backup.restore.BackupRestore(
|
||||||
self.app, backupfile, appvm, passphrase)
|
self.app, backupfile, appvm, passphrase)
|
||||||
if options:
|
if options:
|
||||||
for key, value in options.items():
|
for key, value in options.items():
|
||||||
|
@ -1414,7 +1414,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
|
|||||||
mock.patch('qubesadmin.storage.Volume',
|
mock.patch('qubesadmin.storage.Volume',
|
||||||
functools.partial(MockVolume, qubesd_calls_queue)),
|
functools.partial(MockVolume, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
|
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
|
||||||
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.firewall.Firewall',
|
'qubesadmin.firewall.Firewall',
|
||||||
@ -1476,7 +1476,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
|
|||||||
mock.patch('qubesadmin.storage.Volume',
|
mock.patch('qubesadmin.storage.Volume',
|
||||||
functools.partial(MockVolume, qubesd_calls_queue)),
|
functools.partial(MockVolume, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
|
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
|
||||||
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.firewall.Firewall',
|
'qubesadmin.firewall.Firewall',
|
||||||
@ -1539,7 +1539,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
|
|||||||
mock.patch('qubesadmin.storage.Volume',
|
mock.patch('qubesadmin.storage.Volume',
|
||||||
functools.partial(MockVolume, qubesd_calls_queue)),
|
functools.partial(MockVolume, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
|
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
|
||||||
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.firewall.Firewall',
|
'qubesadmin.firewall.Firewall',
|
||||||
@ -1603,7 +1603,7 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase):
|
|||||||
mock.patch('qubesadmin.storage.Volume',
|
mock.patch('qubesadmin.storage.Volume',
|
||||||
functools.partial(MockVolume, qubesd_calls_queue)),
|
functools.partial(MockVolume, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.backup.BackupRestore._handle_appmenus_list',
|
'qubesadmin.backup.restore.BackupRestore._handle_appmenus_list',
|
||||||
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
functools.partial(self.mock_appmenus, qubesd_calls_queue)),
|
||||||
mock.patch(
|
mock.patch(
|
||||||
'qubesadmin.firewall.Firewall',
|
'qubesadmin.firewall.Firewall',
|
||||||
|
@ -21,7 +21,8 @@ import qubesadmin.tests
|
|||||||
import qubesadmin.tests.tools
|
import qubesadmin.tests.tools
|
||||||
import qubesadmin.tools.qvm_backup_restore
|
import qubesadmin.tools.qvm_backup_restore
|
||||||
from unittest import mock
|
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):
|
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('qubesadmin.tools.qvm_backup_restore.input', create=True)
|
||||||
@mock.patch('getpass.getpass')
|
@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):
|
def test_000_simple(self, mock_backup, mock_getpass, mock_input):
|
||||||
mock_getpass.return_value = 'testpass'
|
mock_getpass.return_value = 'testpass'
|
||||||
mock_input.return_value = 'Y'
|
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('qubesadmin.tools.qvm_backup_restore.input', create=True)
|
||||||
@mock.patch('getpass.getpass')
|
@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):
|
def test_001_selected_vms(self, mock_backup, mock_getpass, mock_input):
|
||||||
mock_getpass.return_value = 'testpass'
|
mock_getpass.return_value = 'testpass'
|
||||||
mock_input.return_value = 'Y'
|
mock_input.return_value = 'Y'
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
import getpass
|
import getpass
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import qubesadmin.backup
|
from qubesadmin.backup.restore import BackupRestore
|
||||||
import qubesadmin.exc
|
import qubesadmin.exc
|
||||||
import qubesadmin.tools
|
import qubesadmin.tools
|
||||||
import qubesadmin.utils
|
import qubesadmin.utils
|
||||||
@ -96,20 +96,20 @@ def handle_broken(app, args, restore_info):
|
|||||||
dom0_username_mismatch = False
|
dom0_username_mismatch = False
|
||||||
|
|
||||||
for vm_info in restore_info.values():
|
for vm_info in restore_info.values():
|
||||||
assert isinstance(vm_info, qubesadmin.backup.BackupRestore.VMToRestore)
|
assert isinstance(vm_info, BackupRestore.VMToRestore)
|
||||||
if qubesadmin.backup.BackupRestore.VMToRestore.EXCLUDED in \
|
if BackupRestore.VMToRestore.EXCLUDED in \
|
||||||
vm_info.problems:
|
vm_info.problems:
|
||||||
continue
|
continue
|
||||||
if qubesadmin.backup.BackupRestore.VMToRestore.MISSING_TEMPLATE in \
|
if BackupRestore.VMToRestore.MISSING_TEMPLATE in \
|
||||||
vm_info.problems:
|
vm_info.problems:
|
||||||
there_are_missing_templates = True
|
there_are_missing_templates = True
|
||||||
if qubesadmin.backup.BackupRestore.VMToRestore.MISSING_NETVM in \
|
if BackupRestore.VMToRestore.MISSING_NETVM in \
|
||||||
vm_info.problems:
|
vm_info.problems:
|
||||||
there_are_missing_netvms = True
|
there_are_missing_netvms = True
|
||||||
if qubesadmin.backup.BackupRestore.VMToRestore.ALREADY_EXISTS in \
|
if BackupRestore.VMToRestore.ALREADY_EXISTS in \
|
||||||
vm_info.problems:
|
vm_info.problems:
|
||||||
there_are_conflicting_vms = True
|
there_are_conflicting_vms = True
|
||||||
if qubesadmin.backup.BackupRestore.Dom0ToRestore.USERNAME_MISMATCH in \
|
if BackupRestore.Dom0ToRestore.USERNAME_MISMATCH in \
|
||||||
vm_info.problems:
|
vm_info.problems:
|
||||||
dom0_username_mismatch = True
|
dom0_username_mismatch = True
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ def handle_broken(app, args, restore_info):
|
|||||||
"missing TemplateVMs will NOT be restored.")
|
"missing TemplateVMs will NOT be restored.")
|
||||||
elif args.ignore_missing:
|
elif args.ignore_missing:
|
||||||
app.log.warning("Ignoring missing entries: VMs that depend "
|
app.log.warning("Ignoring missing entries: VMs that depend "
|
||||||
"on missing TemplateVMs will have default value "\
|
"on missing TemplateVMs will have default value "
|
||||||
"assigned.")
|
"assigned.")
|
||||||
else:
|
else:
|
||||||
raise qubesadmin.exc.QubesException(
|
raise qubesadmin.exc.QubesException(
|
||||||
@ -211,7 +211,7 @@ def main(args=None, app=None):
|
|||||||
args.app.log.info("Checking backup content...")
|
args.app.log.info("Checking backup content...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backup = qubesadmin.backup.BackupRestore(args.app, args.backup_location,
|
backup = BackupRestore(args.app, args.backup_location,
|
||||||
appvm, passphrase)
|
appvm, passphrase)
|
||||||
except qubesadmin.exc.QubesException as e:
|
except qubesadmin.exc.QubesException as e:
|
||||||
parser.error_runtime(str(e))
|
parser.error_runtime(str(e))
|
||||||
|
Loading…
Reference in New Issue
Block a user