Skip to content

Commit

Permalink
Better error reporting if backup file not found
Browse files Browse the repository at this point in the history
qvm-backup-restore will now show a File Not Found message
if specified backup file is not found.

fixes QubesOS/qubes-issues#3446
  • Loading branch information
marmarta committed Sep 9, 2021
1 parent f186f7a commit 9912ceb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions qubesadmin/tests/tools/qvm_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def tearDown(self):
@mock.patch('qubesadmin.tools.qvm_backup_restore.input', create=True)
@mock.patch('getpass.getpass')
@mock.patch('qubesadmin.tools.qvm_backup_restore.BackupRestore')
def test_000_simple(self, mock_backup, mock_getpass, mock_input):
@mock.patch('os.path.exists', return_value=True)
def test_000_simple(self, _mock_exists,
mock_backup, mock_getpass, mock_input):
mock_getpass.return_value = 'testpass'
mock_input.return_value = 'Y'
vm1 = BackupVM()
Expand Down Expand Up @@ -68,7 +70,9 @@ def test_000_simple(self, mock_backup, mock_getpass, mock_input):
@mock.patch('qubesadmin.tools.qvm_backup_restore.input', create=True)
@mock.patch('getpass.getpass')
@mock.patch('qubesadmin.tools.qvm_backup_restore.BackupRestore')
def test_001_selected_vms(self, mock_backup, mock_getpass, mock_input):
@mock.patch('os.path.exists', return_value=True)
def test_001_selected_vms(self, _mock_exist,
mock_backup, mock_getpass, mock_input):
mock_getpass.return_value = 'testpass'
mock_input.return_value = 'Y'
vm1 = BackupVM()
Expand Down Expand Up @@ -235,6 +239,14 @@ def test_012_handle_broken_missing_netvm(self):
self.app, mock_args, mock_restore_info)
self.assertAppropriateLogging('NetVM', 'error')

@mock.patch('argparse.ArgumentParser.error')
def test_013_missing_file(self, mock_argparse):
mock_argparse.side_effect = qubesadmin.exc.QubesException('Error')
with self.assertRaises(qubesadmin.exc.QubesException):
qubesadmin.tools.qvm_backup_restore.main(['/some/path'],
app=self.app)
mock_argparse.assert_called_once_with("File not found: '/some/path'")

def test_100_restore_in_dispvm_parser(self):
"""Verify if qvm-backup-restore tool options matches un-parser
for paranoid restore mode"""
Expand Down
3 changes: 3 additions & 0 deletions qubesadmin/tools/qvm_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ def main(args=None, app=None):
if args.location_is_service and not args.appvm:
parser.error('--location-is-service option requires -d')

if not os.path.exists(args.backup_location):
parser.error('File not found: {!r}'.format(args.backup_location))

if args.paranoid_mode:
args.dom0_home = False
args.app.log.info("Starting restore process in a DisposableVM...")
Expand Down

0 comments on commit 9912ceb

Please sign in to comment.