Пример #1
0
 def test_001_selected_vms(self, mock_backup, mock_getpass, mock_input):
     mock_getpass.return_value = 'testpass'
     mock_input.return_value = 'Y'
     vm1 = BackupVM()
     vm1.name = 'test-vm'
     vm1.backup_path = 'path/in/backup'
     vm1.template = None
     vm1.klass = 'StandaloneVM'
     vm1.label = 'red'
     vm2 = BackupVM()
     vm2.name = 'test-vm2'
     vm2.backup_path = 'path/in/backup2'
     vm2.template = None
     vm2.klass = 'StandaloneVM'
     vm2.label = 'red'
     mock_restore_info = {
         1: BackupRestore.VMToRestore(vm1),
         2: BackupRestore.VMToRestore(vm2),
     }
     exclude_list = []
     mock_backup.configure_mock(
         **{
             'return_value.get_restore_summary.return_value': '',
             'return_value.options.exclude': exclude_list,
             'return_value.get_restore_info.return_value':
             mock_restore_info,
         })
     qubesadmin.tools.qvm_backup_restore.main(['/some/path', 'test-vm'],
                                              app=self.app)
     mock_backup.assert_called_once_with(self.app, '/some/path', None,
                                         'testpass')
     self.assertEqual(exclude_list, ['test-vm2'])
     self.assertAllCalled()
Пример #2
0
 def test_000_simple(self, mock_backup, mock_getpass, mock_input):
     mock_getpass.return_value = 'testpass'
     mock_input.return_value = 'Y'
     vm1 = BackupVM()
     vm1.name = 'test-vm'
     vm1.backup_path = 'path/in/backup'
     vm1.template = None
     vm1.klass = 'StandaloneVM'
     vm1.label = 'red'
     mock_restore_info = {
         1: BackupRestore.VMToRestore(vm1),
     }
     mock_backup.configure_mock(
         **{
             'return_value.get_restore_summary.return_value': '',
             'return_value.get_restore_info.return_value':
             mock_restore_info,
         })
     with mock.patch('qubesadmin.tools.qvm_backup_restore.handle_broken') \
             as mock_handle_broken:
         qubesadmin.tools.qvm_backup_restore.main(['/some/path'],
                                                  app=self.app)
         mock_handle_broken.assert_called_once_with(self.app, mock.ANY,
                                                    mock_restore_info)
     mock_backup.assert_called_once_with(self.app, '/some/path', None,
                                         'testpass')
     self.assertAllCalled()
Пример #3
0
 def test_010_handle_broken_no_problems(self):
     vm1 = BackupVM()
     vm1.name = 'test-vm'
     vm1.backup_path = 'path/in/backup'
     vm1.template = None
     vm1.klass = 'StandaloneVM'
     vm1.label = 'red'
     mock_restore_info = {
         1: BackupRestore.VMToRestore(vm1),
     }
     mock_args = mock.Mock()
     self.app.log = mock.Mock()
     qubesadmin.tools.qvm_backup_restore.handle_broken(
         self.app, mock_args, mock_restore_info)
     self.assertEqual(self.app.log.mock_calls, [
         mock.call.info(
             'The above VMs will be copied and added to your system.'),
         mock.call.info('Exisiting VMs will NOT be removed.'),
     ])
 def test_012_handle_broken_missing_netvm(self):
     vm1 = BackupVM()
     vm1.name = 'test-vm'
     vm1.backup_path = 'path/in/backup'
     vm1.netvm = 'not-existing-netvm'
     vm1.klass = 'StandaloneVM'
     vm1.label = 'red'
     mock_restore_info = {
         1: BackupRestore.VMToRestore(vm1),
     }
     mock_restore_info[1].problems.add(
         BackupRestore.VMToRestore.MISSING_NETVM)
     with self.subTest('skip_broken'):
         mock_args = mock.Mock()
         mock_args.skip_broken = True
         mock_args.verify_only = False
         self.app.log = mock.Mock()
         qubesadmin.tools.qvm_backup_restore.handle_broken(
             self.app, mock_args, mock_restore_info)
         self.assertAppropriateLogging('NetVM', 'skip_broken')
     with self.subTest('ignore_missing'):
         mock_args = mock.Mock()
         mock_args.skip_broken = False
         mock_args.ignore_missing = True
         mock_args.verify_only = False
         self.app.log = mock.Mock()
         qubesadmin.tools.qvm_backup_restore.handle_broken(
             self.app, mock_args, mock_restore_info)
         self.assertAppropriateLogging('NetVM', 'ignore_missing')
     with self.subTest('error'):
         mock_args = mock.Mock()
         mock_args.skip_broken = False
         mock_args.ignore_missing = False
         mock_args.verify_only = False
         self.app.log = mock.Mock()
         with self.assertRaises(qubesadmin.exc.QubesException):
             qubesadmin.tools.qvm_backup_restore.handle_broken(
                 self.app, mock_args, mock_restore_info)
         self.assertAppropriateLogging('NetVM', 'error')