예제 #1
0
    def run(self):
        LOG.debug("Garbage collection begins")
        criteria = Criteria.and_(
            Criteria.with_field("notes.created", Matcher.exists()),
            Criteria.with_field("notes.pub_temp_repo", True),
        )

        # fetch repos for the criteria
        repos = self.pulp_client.search_repository(criteria).result()
        LOG.debug("repos fetched")

        gc_threshold = self.args.gc_threshold
        deleted_repos = []
        # initiate deletion task for the repos
        for repo in repos.as_iter():
            repo_age = datetime.utcnow() - repo.created
            if repo_age > timedelta(days=gc_threshold):
                LOG.info("Deleting %s (created on %s)", repo.id, repo.created)
                deleted_repos.append(repo.delete())

        if not deleted_repos:
            LOG.info("No repo(s) found older than %s day(s)", gc_threshold)

        # log for error during deletion
        for task in deleted_repos:
            out = task.result()[0]
            if out.error_details or out.error_summary:
                LOG.error(out.error_details or out.error_summary)

        LOG.info("Temporary repo(s) deletion completed")
예제 #2
0
def test_can_search_id_exists():
    """Can search for a repo using exists operator with fake client."""
    controller = FakeController()

    repo1 = Repository(id="repo1")
    repo2 = Repository(id="repo2")

    controller.insert_repository(repo1)
    controller.insert_repository(repo2)

    client = controller.client
    crit = Criteria.with_field("id", Matcher.exists())
    found = client.search_repository(crit).data

    assert sorted(found) == [repo1, repo2]
예제 #3
0
def test_search_created_exists():
    controller = FakeController()

    repo1 = Repository(id="repo1")
    repo2 = Repository(id="repo2", created=datetime.datetime.utcnow())
    repo3 = Repository(id="repo3", created=datetime.datetime.utcnow())

    controller.insert_repository(repo1)
    controller.insert_repository(repo2)
    controller.insert_repository(repo3)

    client = controller.client
    crit = Criteria.with_field("notes.created", Matcher.exists())
    found = client.search_repository(crit).data

    assert sorted(found) == [repo2, repo3]
예제 #4
0
def test_stringify_complex_criteria():
    crit = Criteria.and_(
        Criteria.with_field("must-exist", Matcher.exists()),
        Criteria.with_field("foo", Matcher.equals("bar")),
        Criteria.true(),
        Criteria.or_(
            Criteria.with_field("foo", Matcher.regex("quux")),
            Criteria.with_field("other", Matcher.in_(["x", "y", "z"])),
            Criteria.with_field("num", Matcher.less_than(9000)),
        ),
        Criteria.with_unit_type(FileUnit),
    )

    assert (str(crit) == "((must-exist EXISTS) AND foo=='bar' AND TRUE "
            "AND (foo=~/quux/ OR (other IN ['x', 'y', 'z']) OR num<9000) "
            "AND (content_type_id IN ['iso']))")
예제 #5
0
    def _get_rpms_criteria(self):
        criteria_values = []

        for package_pattern in self._ubi_config.packages.whitelist:
            # skip src packages, they are searched seprately
            if package_pattern.arch == "src":
                continue
            arch = (
                PulpLibMatcher.exists()
                if package_pattern.arch in ("*", None)
                else package_pattern.arch
            )
            criteria_values.append((package_pattern.name, arch))

        fields = ("name", "arch")
        or_criteria = self._create_or_criteria(fields, criteria_values)
        return or_criteria
예제 #6
0
def test_search_with_model_field():
    """search repos using model field 'created' in criteria.
    returns only those repos which has the field and value is
    not None
    """
    controller = FakeController()

    repo1 = Repository(id="repo1")
    repo2 = Repository(id="repo2", created=datetime.datetime.utcnow())
    repo3 = Repository(id="repo3", created=None)

    controller.insert_repository(repo1)
    controller.insert_repository(repo2)
    controller.insert_repository(repo3)

    client = controller.client
    crit = Criteria.with_field("created", Matcher.exists())
    found = client.search_repository(crit).result().data

    assert sorted(found) == [repo2]