Esempio n. 1
0
def _lookup_manifest(repository_id, manifest_digest, allow_dead=False):
    query = (Manifest.select().where(
        Manifest.repository == repository_id).where(
            Manifest.digest == manifest_digest))

    if allow_dead:
        try:
            return query.get()
        except Manifest.DoesNotExist:
            return None

    # Try first to filter to those manifests referenced by an alive tag,
    try:
        return filter_to_alive_tags(query.join(Tag)).get()
    except Manifest.DoesNotExist:
        pass

    # Try referenced as the child of a manifest that has an alive tag.
    query = query.join(ManifestChild,
                       on=(ManifestChild.child_manifest == Manifest.id)).join(
                           Tag, on=(Tag.manifest == ManifestChild.manifest))

    query = filter_to_alive_tags(query)

    try:
        return query.get()
    except Manifest.DoesNotExist:
        return None
Esempio n. 2
0
def test_delete_tags_for_manifest(initialized_db):
    for tag in list(filter_to_visible_tags(filter_to_alive_tags(Tag.select()))):
        repo = tag.repository
        assert get_tag(repo, tag.name) == tag

        with assert_query_count(4):
            assert delete_tags_for_manifest(tag.manifest) == [tag]

        assert get_tag(repo, tag.name) is None
Esempio n. 3
0
def test_get_tag(initialized_db):
    found = False
    for tag in filter_to_visible_tags(filter_to_alive_tags(Tag.select())):
        repo = tag.repository

        with assert_query_count(1):
            assert get_tag(repo, tag.name) == tag
        found = True

    assert found
Esempio n. 4
0
def test_delete_tag(initialized_db):
    found = False
    for tag in list(filter_to_visible_tags(filter_to_alive_tags(Tag.select()))):
        repo = tag.repository

        assert get_tag(repo, tag.name) == tag
        assert tag.lifetime_end_ms is None

        with assert_query_count(3):
            assert delete_tag(repo, tag.name) == tag

        assert get_tag(repo, tag.name) is None
        found = True

    assert found
Esempio n. 5
0
def test_lookup_alive_tags_shallow(initialized_db):
    found = False
    for tag in filter_to_visible_tags(filter_to_alive_tags(Tag.select())):
        tags = lookup_alive_tags_shallow(tag.repository)
        found = True
        assert tag in tags

    assert found

    # Ensure hidden tags cannot be listed.
    tag = Tag.get()
    tag.hidden = True
    tag.save()

    tags = lookup_alive_tags_shallow(tag.repository)
    assert tag not in tags
Esempio n. 6
0
def test_lookup_manifest(initialized_db):
    found = False
    for tag in filter_to_alive_tags(Tag.select()):
        found = True
        repo = tag.repository
        digest = tag.manifest.digest
        with assert_query_count(1):
            assert lookup_manifest(repo, digest) == tag.manifest

    assert found

    for tag in Tag.select():
        repo = tag.repository
        digest = tag.manifest.digest
        with assert_query_count(1):
            assert lookup_manifest(repo, digest,
                                   allow_dead=True) == tag.manifest
Esempio n. 7
0
def test_list_alive_tags(initialized_db):
    found = False
    for tag in filter_to_visible_tags(filter_to_alive_tags(Tag.select())):
        tags = list_alive_tags(tag.repository)
        assert tag in tags

        with assert_query_count(1):
            legacy_images = get_legacy_images_for_tags(tags)

        for tag in tags:
            assert ManifestLegacyImage.get(manifest=tag.manifest).image == legacy_images[tag.id]

        found = True

    assert found

    # Ensure hidden tags cannot be listed.
    tag = Tag.get()
    tag.hidden = True
    tag.save()

    tags = list_alive_tags(tag.repository)
    assert tag not in tags