Beispiel #1
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
Beispiel #2
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
Beispiel #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
Beispiel #4
0
def test_delete_tags_for_manifest_same_manifest(initialized_db):
    new_repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest_1, _ = create_manifest_for_testing(new_repo, "1")
    manifest_2, _ = create_manifest_for_testing(new_repo, "2")

    assert manifest_1.digest != manifest_2.digest

    # Add some tag history, moving a tag back and forth between two manifests.
    retarget_tag("latest", manifest_1)
    retarget_tag("latest", manifest_2)
    retarget_tag("latest", manifest_1)
    retarget_tag("latest", manifest_2)

    retarget_tag("another1", manifest_1)
    retarget_tag("another2", manifest_2)

    # Delete all tags pointing to the first manifest.
    delete_tags_for_manifest(manifest_1)

    assert get_tag(new_repo, "latest").manifest == manifest_2
    assert get_tag(new_repo, "another1") is None
    assert get_tag(new_repo, "another2").manifest == manifest_2

    # Delete all tags pointing to the second manifest, which should actually delete the `latest`
    # tag now.
    delete_tags_for_manifest(manifest_2)
    assert get_tag(new_repo, "latest") is None
    assert get_tag(new_repo, "another1") is None
    assert get_tag(new_repo, "another2") is None
Beispiel #5
0
def test_get_or_create_manifest_invalid_image(initialized_db):
    repository = get_repository("devtable", "simple")

    latest_tag = get_tag(repository, "latest")
    parsed = DockerSchema1Manifest(Bytes.for_string_or_unicode(
        latest_tag.manifest.manifest_bytes),
                                   validate=False)

    builder = DockerSchema1ManifestBuilder("devtable", "simple", "anothertag")
    builder.add_layer(parsed.blob_digests[0],
                      '{"id": "foo", "parent": "someinvalidimageid"}')
    sample_manifest_instance = builder.build(docker_v2_signing_key)

    created_manifest = get_or_create_manifest(repository,
                                              sample_manifest_instance,
                                              storage)
    assert created_manifest is None