示例#1
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
示例#2
0
def test_manifest_v2_shared_config_and_blobs(app, default_tag_policy):
    """
    Test that GCing a tag that refers to a V2 manifest with the same config and some shared blobs as
    another manifest ensures that the config blob and shared blob are NOT GCed.
    """
    repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest1, built1 = create_manifest_for_testing(repo,
                                                    differentiation_field="1",
                                                    include_shared_blob=True)
    manifest2, built2 = create_manifest_for_testing(repo,
                                                    differentiation_field="2",
                                                    include_shared_blob=True)

    assert set(built1.local_blob_digests).intersection(
        built2.local_blob_digests)
    assert built1.config.digest == built2.config.digest

    # Create tags pointing to the manifests.
    model.oci.tag.retarget_tag("tag1", manifest1)
    model.oci.tag.retarget_tag("tag2", manifest2)

    with assert_gc_integrity(expect_storage_removed=True):
        # Delete tag2.
        model.oci.tag.delete_tag(repo, "tag2")
        assert gc_now(repo)

    # Ensure the blobs for manifest1 still all exist.
    preferred = storage.preferred_locations[0]
    for blob_digest in built1.local_blob_digests:
        storage_row = ImageStorage.get(content_checksum=blob_digest)

        assert storage_row.cas_path
        storage.get_content({preferred},
                            storage.blob_path(storage_row.content_checksum))
示例#3
0
def test_get_current_tag_with_multiple_expired_tags(initialized_db):
    repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest, _ = create_manifest_for_testing(repo, "1")
    nowms = get_epoch_timestamp_ms()
    count = (Tag.update(
        lifetime_start_ms=nowms - timedelta(hours=24).total_seconds() * 1000,
        lifetime_end_ms=nowms - timedelta(hours=12).total_seconds() * 1000,
    ).where(Tag.manifest == manifest.id).execute())
    expired_tag = create_temporary_tag_if_necessary(manifest, 3600)
    expired_tag = Tag.create(
        name="v6.6.6",
        repository=repo.id,
        lifetime_start_ms=nowms - timedelta(hours=10).total_seconds() * 1000,
        lifetime_end_ms=nowms - timedelta(hours=8).total_seconds() * 1000,
        reversion=False,
        hidden=False,
        manifest=manifest,
        tag_kind=Tag.tag_kind.get_id("tag"),
    )
    tag = Tag.create(
        name="v6.6.6",
        repository=repo.id,
        lifetime_start_ms=nowms - timedelta(hours=5).total_seconds() * 1000,
        lifetime_end_ms=nowms + timedelta(hours=5).total_seconds() * 1000,
        reversion=False,
        hidden=False,
        manifest=manifest,
        tag_kind=Tag.tag_kind.get_id("tag"),
    )
    current_tag = get_current_tag(repo.id, tag.name)
    assert current_tag.id == tag.id
示例#4
0
def test_get_current_tag_with_expired_tag(initialized_db):
    repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest, _ = create_manifest_for_testing(repo, "1")
    before_ms = get_epoch_timestamp_ms() - timedelta(
        hours=24).total_seconds() * 1000
    count = (Tag.update(
        lifetime_start_ms=before_ms,
        lifetime_end_ms=before_ms + 5,
    ).where(Tag.manifest == manifest.id).execute())
    assert count == 1
示例#5
0
def test_get_tag_by_manifest_id_multiple_tags_returns_latest(initialized_db):
    repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest, _ = create_manifest_for_testing(repo, "1")
    before_ms = get_epoch_timestamp_ms() - timedelta(
        hours=24).total_seconds() * 1000
    count = (Tag.update(
        lifetime_start_ms=before_ms,
        lifetime_end_ms=before_ms + 5,
    ).where(Tag.manifest == manifest.id).execute())
    assert count == 1
    expired_tag = get_tag_by_manifest_id(repo.id, manifest.id)
    new_tag = create_temporary_tag_if_necessary(
        manifest,
        get_epoch_timestamp_ms() + 3600 * 1000)
    tag = get_tag_by_manifest_id(repo.id, manifest.id)
    assert tag is not None
    assert tag.id == new_tag.id
    assert tag.lifetime_end_ms > expired_tag.lifetime_end_ms
示例#6
0
def test_get_current_tag_with_single_existing_tag(initialized_db):
    repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest, _ = create_manifest_for_testing(repo, "1")
    t = manifest.tag_set.get()
    tag = get_current_tag(repo.id, t.name)
    assert tag.id == t.id
示例#7
0
def test_get_tag_by_manifest_id_valid_tag(initialized_db):
    repo = model.repository.create_repository("devtable", "newrepo", None)
    manifest, _ = create_manifest_for_testing(repo, "1")
    tag = get_tag_by_manifest_id(repo.id, manifest.id)
    assert tag is not None