def test_stop_backup_failed(tmp_backupdir, tmp_basedir): vm = FakeVm() dom = FakeDomainAdapter() dom.errors["abortJob"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR], "Fake libvirt error") fake_disks = create_fake_disks() config = {'backup_id': BACKUP_ID, 'disks': fake_disks} res = backup.start_backup(vm, dom, config) verify_scratch_disks_exists(vm) result_disks = res['result']['disks'] verify_backup_urls(BACKUP_ID, result_disks) with pytest.raises(exception.BackupError): backup.stop_backup(vm, dom, BACKUP_ID) # Failed to stop, backup still alive assert dom.backing_up # verify scratch disks weren't removed verify_scratch_disks_exists(vm)
def test_failed_delete_checkpoint(): error_msg = "Internal delete error" dom = FakeDomainAdapter() checkpoint_2 = FakeCheckpoint(CHECKPOINT_2_XML, CHECKPOINT_2_ID, dom=dom) # simulating an error that raised when calling the delete method # of a specific checkpoint checkpoint_2.errors["delete"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR, '', error_msg], "Fake libvirt error") dom.output_checkpoints = [ FakeCheckpoint(CHECKPOINT_1_XML, CHECKPOINT_1_ID, dom=dom), checkpoint_2 ] vm = FakeVm() res = backup.delete_checkpoints(vm, dom, [CHECKPOINT_1_ID, CHECKPOINT_2_ID]) expected_result = { 'checkpoint_ids': [CHECKPOINT_1_ID], 'error': { 'code': 1, 'message': error_msg } } assert res["result"] == expected_result res = backup.list_checkpoints(vm, dom) assert res["result"] == [CHECKPOINT_2_ID]
def test_start_backup_failed_get_checkpoint(tmp_backupdir, tmp_basedir): vm = FakeVm() dom = FakeDomainAdapter() dom.errors["checkpointLookupByName"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR], "Fake libvirt error") fake_disks = create_fake_disks() config = { 'backup_id': BACKUP_1_ID, 'disks': fake_disks, 'to_checkpoint_id': CHECKPOINT_1_ID } res = backup.start_backup(vm, dom, config) assert dom.backing_up verify_scratch_disks_exists(vm) # verify that the vm froze and thawed during the backup assert vm.froze assert vm.thawed assert 'checkpoint' not in res['result'] result_disks = res['result']['disks'] verify_backup_urls(BACKUP_1_ID, result_disks) backup.stop_backup(vm, dom, BACKUP_1_ID) assert not dom.backing_up verify_scratch_disks_removed(vm)
def checkpointLookupByName(self, checkpoint_id): for checkpoint in self.output_checkpoints: if checkpoint.getName() == checkpoint_id: return checkpoint raise fake.libvirt_error( [libvirt.VIR_ERR_NO_DOMAIN_CHECKPOINT], "Checkpoint not found")
def test_backup_info_get_xml_desc_failed(): vm = FakeVm() dom = FakeDomainAdapter() dom.errors["backupGetXMLDesc"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR], "Fakse libvirt error") with pytest.raises(exception.BackupError): backup.backup_info(vm, dom, BACKUP_ID)
def test_backup_info_no_backup_running(): vm = FakeVm() dom = FakeDomainAdapter() dom.errors["backupGetXMLDesc"] = fake.libvirt_error( [libvirt.VIR_ERR_NO_DOMAIN_BACKUP], "Fake libvirt error") with pytest.raises(exception.NoSuchBackupError): backup.backup_info(vm, dom, BACKUP_ID)
def test_stop_non_existing_backup(): vm = FakeVm() dom = FakeDomainAdapter() dom.errors["backupGetXMLDesc"] = fake.libvirt_error( [libvirt.VIR_ERR_NO_DOMAIN_BACKUP], "Fake libvirt error") # test that nothing is raised when stopping non-existing backup backup.stop_backup(vm, dom, BACKUP_ID)
def test_dump_checkpoint_lookup_failed(): dom = FakeDomainAdapter() dom.errors["checkpointLookupByName"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR], "Fake libvirt error") dom.output_checkpoints = [ FakeCheckpoint(CHECKPOINT_1_XML, CHECKPOINT_1_ID), FakeCheckpoint(CHECKPOINT_2_XML, CHECKPOINT_2_ID) ] with pytest.raises(libvirt.libvirtError) as e: backup.dump_checkpoint(dom, CHECKPOINT_1_ID) assert e.value.get_error_code() == libvirt.VIR_ERR_INTERNAL_ERROR
def test_dump_checkpoint_get_xml_failed(): checkpoint_2 = FakeCheckpoint(CHECKPOINT_2_XML, CHECKPOINT_2_ID) # simulating an error that raised when calling the getXMLDesc method # of a specific checkpoint checkpoint_2.errors["getXMLDesc"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR, '', 'Internal get XML error'], "Fake libvirt error") dom = FakeDomainAdapter() dom.output_checkpoints = [ FakeCheckpoint(CHECKPOINT_1_XML, CHECKPOINT_1_ID), checkpoint_2 ] with pytest.raises(libvirt.libvirtError) as e: backup.dump_checkpoint(dom, CHECKPOINT_2_ID) assert e.value.get_error_code() == libvirt.VIR_ERR_INTERNAL_ERROR
def checkpointCreateXML(self, checkpoint_xml, flags=None): assert flags == libvirt.VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE # validate the given checkpoint XML according to the # initialized output_checkpoints, in case output_checkpoints # isn't initialized the validation will be skipped if self.output_checkpoints: indented_checkpoint_xml = indented(checkpoint_xml) for checkpoint in self.output_checkpoints: expected_checkpoint_xml = indented(checkpoint.getXMLDesc()) if indented_checkpoint_xml == expected_checkpoint_xml: return raise fake.libvirt_error( [libvirt.VIR_ERR_INVALID_DOMAIN_CHECKPOINT, '', "Invalid checkpoint error"], "Fake checkpoint error")
def test_backup_begin_freeze_failed(tmp_backupdir, tmp_basedir): vm = FakeVm() vm.errors["freeze"] = fake.libvirt_error([libvirt.VIR_ERR_INTERNAL_ERROR], "Fake libvirt error") dom = FakeDomainAdapter() fake_disks = create_fake_disks() config = {'backup_id': BACKUP_ID, 'disks': fake_disks} with pytest.raises(libvirt.libvirtError): backup.start_backup(vm, dom, config) verify_scratch_disks_removed(vm) # verify that the vm didn't froze but thawed during the backup assert not vm.froze assert vm.thawed
def test_redefine_checkpoints_failed(): dom = FakeDomainAdapter() # simulating an error that raised during # checkpointCreateXML() method in libvirt. error_msg = "Create checkpoint XML Error" dom.errors["checkpointCreateXML"] = fake.libvirt_error( [libvirt.VIR_ERR_INTERNAL_ERROR, '', error_msg], "Fake libvirt error") vm = FakeVm() res = backup.redefine_checkpoints(vm, dom, FAKE_CHECKPOINT_CFG) expected_result = { 'checkpoint_ids': [], 'error': { 'code': 1, 'message': error_msg } } assert res["result"] == expected_result
def checkpointLookupByName(self, checkpoint_id): if self.checkpoint is None: raise fake.libvirt_error([libvirt.VIR_ERR_NO_DOMAIN_CHECKPOINT], "Checkpoint not found") return self.checkpoint