Exemple #1
0
def test_invalidate(storage):
    data = EXAMPLE_DATA[(storage.block_size, storage.alignment)]
    with open(storage.path, "wb") as f:
        f.write(data.encode("utf-8"))

    # Read initial metadata.
    md = fileSD.FileSDMetadata(storage.path)
    initial_metadata = md.copy()

    # Simulate another host changing data on storage...
    other_md = fileSD.FileSDMetadata(storage.path)
    other_md[sd.DMDK_VERSION] = 6
    new_metadata = other_md.copy()

    # Check that reading return cached data.
    assert md.copy() == initial_metadata

    # Check that invalidating read data from storage.
    md.invalidate()
    assert md.copy() == new_metadata
Exemple #2
0
def test_read(storage):
    data = EXAMPLE_DATA[(storage.block_size, storage.alignment)]
    with open(storage.path, "wb") as f:
        f.write(data.encode("utf-8"))

    # Check that metadata loaded from storage.
    md = fileSD.FileSDMetadata(storage.path)

    metadata = make_metadata(storage)
    assert md.copy() == metadata
    assert md[sd.DMDK_VERSION] == metadata[sd.DMDK_VERSION]
Exemple #3
0
def test_transaction(storage):
    data = EXAMPLE_DATA[(storage.block_size, storage.alignment)]
    with open(storage.path, "wb") as f:
        f.write(data.encode("utf-8"))

    # Prepare metadata with some changes.
    metadata = make_metadata(storage)
    metadata[sd.DMDK_VERSION] = 6
    metadata[sd.DMDK_DESCRIPTION] = "better domain"

    # Change mulitple keys in one transaction.
    md = fileSD.FileSDMetadata(storage.path)
    with md.transaction():
        md[sd.DMDK_VERSION] = metadata[sd.DMDK_VERSION]
        md[sd.DMDK_DESCRIPTION] = metadata[sd.DMDK_DESCRIPTION]

    # Check that memory state was changed.
    assert md.copy() == metadata

    # Check that changes written to storage.
    md = fileSD.FileSDMetadata(storage.path)
    assert md.copy() == metadata
Exemple #4
0
def make_filesd_manifest(mnt_dir, sd_version=3):
    spuuid = make_uuid()
    sduuid = make_uuid()

    domain_path = os.path.join(mnt_dir, sduuid)
    metafile = get_metafile_path(domain_path)
    make_file(metafile)
    metadata = fileSD.FileSDMetadata(metafile)
    metadata.update(
        make_sd_metadata(sduuid, version=sd_version, pools=[spuuid]))

    manifest = fileSD.FileStorageDomainManifest(domain_path, metadata)
    os.makedirs(os.path.join(manifest.domaindir, sd.DOMAIN_IMAGES))
    return manifest
Exemple #5
0
def test_update(storage):
    data = EXAMPLE_DATA[(storage.block_size, storage.alignment)]
    with open(storage.path, "wb") as f:
        f.write(data.encode("utf-8"))

    # Prepare metadata with some changes.
    metadata = make_metadata(storage)
    changes = {
        sd.DMDK_VERSION: 6,
        sd.DMDK_DESCRIPTION: "better domain",
    }
    metadata.update(changes)

    # Update md.
    md = fileSD.FileSDMetadata(storage.path)
    md.update(changes)

    # Check that memory state was changed.
    assert md.copy() == metadata

    # Check that changes written to storage.
    md = fileSD.FileSDMetadata(storage.path)
    assert md.copy() == metadata
Exemple #6
0
def test_read_strip_zero_padding(storage):
    data = EXAMPLE_DATA[(storage.block_size, storage.alignment)]

    # With Gluster we may get extra padding when reading metadata from storage.
    # Simulate this by padding file data when writing.
    # https://bugzilla.redhat.com/1737141
    padded = data.ljust(storage.block_size, "\0")

    with open(storage.path, "wb") as f:
        f.write(padded.encode("utf-8"))

    # Check that metadata loaded from storage.
    md = fileSD.FileSDMetadata(storage.path)

    metadata = make_metadata(storage)
    assert md.copy() == metadata
    assert md[sd.DMDK_VERSION] == metadata[sd.DMDK_VERSION]
Exemple #7
0
def test_write(storage):
    metadata = make_metadata(storage)

    # Check that md is empty when storage is empty.
    md = fileSD.FileSDMetadata(storage.path)
    assert md.copy() == {}

    # Update metadata.
    md.update(metadata)

    # Check that memory state was modifed.
    assert md.copy() == metadata

    # Check that storage was modifed.
    with open(storage.path, "rb") as f:
        data = f.read().decode("utf-8")
    assert data == EXAMPLE_DATA[(storage.block_size, storage.alignment)]