def test_redefine_checkpoints_failed_no_xml_or_config(): dom = FakeDomainAdapter(output_checkpoints=[CHECKPOINT_1, CHECKPOINT_2]) vm = FakeVm() checkpoint_cfg = [ { 'id': CHECKPOINT_1_ID, }, ] with pytest.raises(exception.CheckpointError): backup.redefine_checkpoints(vm, dom, checkpoint_cfg)
def test_redefine_checkpoints_succeeded(): dom = FakeDomainAdapter(output_checkpoints=[CHECKPOINT_1, CHECKPOINT_2]) vm = FakeVm() res = backup.redefine_checkpoints(vm, dom, FAKE_CHECKPOINT_CFG) expected_result = { 'checkpoint_ids': [CHECKPOINT_1.getName(), CHECKPOINT_2.getName()], } assert res["result"] == expected_result
def test_redefine_checkpoints_failed_after_one_succeeded(): dom = FakeDomainAdapter(output_checkpoints=[CHECKPOINT_1, CHECKPOINT_2]) vm = FakeVm() # Add non existing checkpoint to FAKE_CHECKPOINT_CFG # to fail the validation in checkpointCreateXML cfg = list(FAKE_CHECKPOINT_CFG) cfg.append({'id': make_uuid(), 'xml': "<xml/>"}) res = backup.redefine_checkpoints(vm, dom, cfg) expected_result = { 'checkpoint_ids': [CHECKPOINT_1.getName(), CHECKPOINT_2.getName()], 'error': { 'code': 102, 'message': "Invalid checkpoint error" } } assert res["result"] == expected_result
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 test_redefine_diskless_checkpoints_using_config(): diskless_checkpoint = FakeCheckpoint(DISKLESS_CHECKPOINT_XML, DISKLESS_CHECKPOINT_ID) dom = FakeDomainAdapter(output_checkpoints=[diskless_checkpoint]) vm = FakeVm() fake_checkpoint_config_cfg = [ { 'id': DISKLESS_CHECKPOINT_ID, 'config': { 'backup_id': BACKUP_1_ID, 'disks': [], 'to_checkpoint_id': DISKLESS_CHECKPOINT_ID, 'creation_time': 1 } }, ] res = backup.redefine_checkpoints(vm, dom, fake_checkpoint_config_cfg) expected_result = { 'checkpoint_ids': [diskless_checkpoint.getName()], } assert res["result"] == expected_result
def test_redefine_checkpoints_using_config(): checkpoint_1 = FakeCheckpoint(CHECKPOINT_1_WITH_CREATION_TIME_XML, CHECKPOINT_1_ID) checkpoint_2 = FakeCheckpoint(CHECKPOINT_2_WITH_CREATION_TIME_XML, CHECKPOINT_2_ID) dom = FakeDomainAdapter(output_checkpoints=[checkpoint_1, checkpoint_2]) vm = FakeVm() fake_disks = create_fake_disks() fake_checkpoint_config_cfg = [ { 'id': CHECKPOINT_1_ID, 'config': { 'backup_id': BACKUP_1_ID, 'disks': fake_disks, 'to_checkpoint_id': CHECKPOINT_1_ID, 'creation_time': 1 } }, { 'id': CHECKPOINT_2_ID, 'config': { 'backup_id': BACKUP_2_ID, 'disks': fake_disks, 'from_checkpoint_id': CHECKPOINT_1_ID, 'to_checkpoint_id': CHECKPOINT_2_ID, 'creation_time': 2 } }, ] res = backup.redefine_checkpoints(vm, dom, fake_checkpoint_config_cfg) expected_result = { 'checkpoint_ids': [checkpoint_1.getName(), checkpoint_2.getName()], } assert res["result"] == expected_result