def test_clean_broken(self, build_backup_directory, build_mock_domain,
                          build_mock_libvirtconn, mocker):
        build_mock_libvirtconn._domains.append(build_mock_domain)
        backup_dir = build_backup_directory["backup_dir"]
        group = CompleteBackupGroup(name="test",
                                    backup_dir=str(backup_dir),
                                    hosts=["r:.*"],
                                    conn=build_mock_libvirtconn)

        dombkup = DomBackup(dom=build_mock_domain,
                            target_dir=str(
                                backup_dir.mkdir(build_mock_domain.name())))
        dombkup.pending_info["domain_name"] = build_mock_domain.name()
        dombkup.pending_info["date"] = 0
        dombkup._dump_pending_info()

        group.scan_backup_dir()
        nb_initial_backups = sum(len(b) for b in group.broken_backups.values())
        assert nb_initial_backups == 1

        broken_backup = group.broken_backups[build_mock_domain.name()][0]
        mocker.spy(broken_backup, "clean_aborted")

        group.clean_broken_backups()
        assert not group.broken_backups[build_mock_domain.name()]
        assert broken_backup.clean_aborted.called
    def test_clean_pending_info(self, build_mock_domain, tmpdir):
        target_dir = tmpdir.mkdir("clean_pending_info")
        dombkup = DomBackup(dom=build_mock_domain, target_dir=str(target_dir))
        dombkup.pending_info["date"] = 0

        dombkup._dump_pending_info()
        assert len(target_dir.listdir()) == 1
        dombkup._clean_pending_info()
        assert len(target_dir.listdir()) == 0
    def test_clean_pending_info(self, build_mock_domain, tmpdir):
        target_dir = tmpdir.mkdir("clean_pending_info")
        dombkup = DomBackup(dom=build_mock_domain, target_dir=str(target_dir))
        dombkup.pending_info["date"] = 0

        dombkup._dump_pending_info()
        assert len(target_dir.listdir()) == 1
        dombkup._clean_pending_info()
        assert len(target_dir.listdir()) == 0
    def test_clean_broken(self, build_backup_directory, build_mock_domain,
                          build_mock_libvirtconn, mocker):
        build_mock_libvirtconn._domains.append(build_mock_domain)
        callbacks_registrer = DomExtSnapshotCallbackRegistrer(
            build_mock_libvirtconn)
        backup_dir = build_backup_directory["backup_dir"]
        group = CompleteBackupGroup(
            name="test",
            backup_dir=str(backup_dir),
            hosts=["r:.*"],
            conn=build_mock_libvirtconn,
            callbacks_registrer=callbacks_registrer,
        )

        dombkup = DomBackup(
            dom=build_mock_domain,
            backup_dir=str(backup_dir.mkdir(build_mock_domain.name())),
            callbacks_registrer=callbacks_registrer,
        )
        dombkup.pending_info = dombkup.get_definition()
        dombkup.pending_info["domain_name"] = build_mock_domain.name()
        dombkup.pending_info["date"] = 0
        dombkup.pending_info["disks"] = {}
        dombkup.pending_info["name"] = "test"
        dombkup.pending_info["packager"] = {"type": "directory", "opts": {}}
        dombkup._dump_pending_info()

        group.scan_backup_dir()
        nb_initial_backups = sum(len(b) for b in group.broken_backups.values())
        assert nb_initial_backups == 1

        broken_backup = group.broken_backups[build_mock_domain.name()][0]
        mocker.spy(broken_backup, "clean_aborted")

        group.clean_broken_backups()
        assert not group.broken_backups[build_mock_domain.name()]
        assert broken_backup.clean_aborted.called