'Test error handling.
Test error handling when attempting an import of a backup
record with a different service to that used to create the backup.'

def test_import_record_with_bad_service(self):

    export = self._create_exported_record_entry()
    export['backup_service'] = 'cinder.tests.unit.backup.bad_service'
    imported_record = self._create_export_record_db_entry()
    backup_hosts = []
    self.assertRaises(exception.ServiceNotFound, self.backup_mgr.import_record, self.ctxt, imported_record, export['backup_service'], export['backup_url'], backup_hosts)
    backup_hosts = ['fake1', 'fake2']
    backup_hosts_expect = list(backup_hosts)
    BackupAPI_import = 'cinder.backup.rpcapi.BackupAPI.import_record'
    with mock.patch(BackupAPI_import) as _mock_backup_import:
        self.backup_mgr.import_record(self.ctxt, imported_record, export['backup_service'], export['backup_url'], backup_hosts)
        next_host = backup_hosts_expect.pop()
        _mock_backup_import.assert_called_once_with(self.ctxt, next_host, imported_record, export['backup_service'], export['backup_url'], backup_hosts_expect)
