Ejemplo n.º 1
0
def test_get_unlinkable_objects():
    """When an object is no longer listed in any repositories we are able to remove it from disk."""
    registry_state = RegistryState()
    registry_state.dispatch_entries([
        [
            1,
            {
                "type": RegistryActions.BLOB_MOUNTED,
                "repository": "alpine",
                "hash": "base",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.BLOB_STORED,
                "hash": "base",
                "location": "node1",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_MOUNTED,
                "repository": "alpine",
                "hash": "layer2-a",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_STORED,
                "hash": "layer2-a",
                "location": "node1",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_INFO,
                "hash": "layer2-a",
                "content_type": "application/json",
                "dependencies": ["base"],
            },
        ],
        [
            1,
            {
                "type": RegistryActions.BLOB_UNMOUNTED,
                "repository": "alpine",
                "hash": "base",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_UNMOUNTED,
                "repository": "alpine",
                "hash": "layer2-a",
            },
        ],
    ])

    assert registry_state.get_orphaned_objects() == {"layer2-a"}

    registry_state.dispatch_entries([[
        1,
        {
            "type": RegistryActions.MANIFEST_UNSTORED,
            "hash": "layer2-a",
            "location": "node1",
        },
    ]])

    assert registry_state.get_orphaned_objects() == {"base"}

    registry_state.dispatch_entries([[
        1,
        {
            "type": RegistryActions.BLOB_UNSTORED,
            "hash": "base",
            "location": "node1",
        },
    ]])

    assert registry_state.get_orphaned_objects() == set()
Ejemplo n.º 2
0
def test_get_orphaned_objects():
    """
    A blob layer is published, then a manifest points at that is published. That manifest is tagged.
    Later a new manifest and tag are pushed. The blob layer is not orphaned, and the old tag is just
    overwritten. In this example, this leaves layer2-a as something that can be garbage collected.
    """
    registry_state = RegistryState()
    registry_state.dispatch_entries([
        [
            1,
            {
                "type": RegistryActions.BLOB_MOUNTED,
                "repository": "alpine",
                "hash": "base",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_MOUNTED,
                "repository": "alpine",
                "hash": "layer2-a",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_INFO,
                "hash": "layer2-a",
                "content_type": "application/json",
                "dependencies": ["base"],
            },
        ],
        [
            1,
            {
                "type": RegistryActions.HASH_TAGGED,
                "repository": "alpine",
                "tag": "3.11",
                "hash": "layer2-a",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_MOUNTED,
                "repository": "alpine",
                "hash": "layer2-b",
            },
        ],
        [
            1,
            {
                "type": RegistryActions.MANIFEST_INFO,
                "hash": "layer2-b",
                "content_type": "application/json",
                "dependencies": ["base"],
            },
        ],
        [
            1,
            {
                "type": RegistryActions.HASH_TAGGED,
                "repository": "alpine",
                "tag": "3.11",
                "hash": "layer2-b",
            },
        ],
    ])

    assert registry_state.get_orphaned_objects() == {"layer2-a"}