Exemplo n.º 1
0
def Volume(doc: Dict) -> StorageVolume:
    """Factory pattern to create storage volume instances for the service API.

    Expects a serialization object that contains at least the volume type ``type``.

    Parameters
    ----------
    doc: dict
        Serialization dictionary that provides access to storage volume type and
        the implementation-specific volume parameters.

    Returns
    -------
    flowserv.volume.base.StorageVolume
    """
    volume_type = doc.get('type', FS_STORE)
    if volume_type == FS_STORE:
        return FileSystemStorage.from_dict(doc)
    elif volume_type == GC_STORE:
        return GCVolume.from_dict(doc)
    elif volume_type == S3_STORE:
        return S3Volume.from_dict(doc)
    elif volume_type == SFTP_STORE:
        return RemoteStorage.from_dict(doc)
    raise err.InvalidConfigurationError('storage volume type', volume_type)
Exemplo n.º 2
0
def test_fs_volume_serialization():
    """Test serialization for a file system storage volume object."""
    doc = FileSystemStorage(basedir='.', identifier='0000').to_dict()
    assert doc == {'type': FS_STORE, 'id': '0000', 'args': [{'key': 'basedir', 'value': '.'}]}
    fs = FileSystemStorage.from_dict(doc)
    assert isinstance(fs, FileSystemStorage)
    assert fs.identifier == '0000'
    assert fs.basedir == '.'