Exemplo n.º 1
0
    def get_data_paths(persistences):
        import conf
        from stores.validators import validate_persistence_data

        persistence_data = validate_persistence_data(
            persistence_data=persistences)
        persistence_paths = {}
        for persistence in persistence_data:
            if persistence not in conf.get('PERSISTENCE_DATA'):
                raise VolumeNotFoundError(
                    'Data volume with name `{}` was defined in specification, '
                    'but was not found'.format(persistence))
            persistence_type_condition = (
                'mountPath' not in conf.get('PERSISTENCE_DATA')[persistence]
                and 'bucket' not in conf.get('PERSISTENCE_DATA')[persistence])
            if persistence_type_condition:
                raise VolumeNotFoundError(
                    'Data volume with name `{}` '
                    'does not define a mountPath or bucket.'.format(
                        persistence))

            persistence_paths[persistence] = (
                conf.get('PERSISTENCE_DATA')[persistence].get('mountPath')
                or conf.get('PERSISTENCE_DATA')[persistence].get('bucket'))

        return persistence_paths
Exemplo n.º 2
0
def _set_persistence(instance,
                     default_persistence_data=None,
                     default_persistence_outputs=None):
    if instance.persistence:
        return

    data_refs = None
    artifact_refs = None

    cond = (instance.specification and instance.specification.environment
            and instance.specification.environment.data_refs)
    if cond:
        data_refs = instance.specification.environment.data_refs

    cond = (instance.specification and instance.specification.environment
            and instance.specification.environment.artifact_refs)
    if cond:
        # TODO: this is a temp workaround until the finalized Polyflow version
        artifact_refs = to_list(
            instance.specification.environment.artifact_refs)[0]

    if not data_refs and default_persistence_data:
        data_refs = default_persistence_data

    if not artifact_refs and default_persistence_outputs:
        artifact_refs = default_persistence_outputs

    persistence_data = validate_persistence_data(persistence_data=data_refs)
    persistence_outputs = validate_persistence_outputs(
        persistence_outputs=artifact_refs)
    persistence_config = PersistenceConfig(data=persistence_data,
                                           outputs=persistence_outputs)
    instance.persistence = persistence_config.to_dict()
Exemplo n.º 3
0
def _set_persistence(instance,
                     default_persistence_data=None,
                     default_persistence_outputs=None):
    if instance.persistence:
        return

    data_refs = None
    artifact_refs = None

    cond = (instance.specification and instance.specification.environment
            and instance.specification.environment.data_refs)
    if cond:
        data_refs = instance.specification.environment.data_refs

    cond = (instance.specification and instance.specification.environment
            and instance.specification.environment.artifact_refs)
    if cond:
        artifact_refs = instance.specification.environment.artifact_refs

    if not data_refs and default_persistence_data:
        data_refs = default_persistence_data

    if not artifact_refs and default_persistence_outputs:
        artifact_refs = default_persistence_outputs

    persistence_data = validate_persistence_data(persistence_data=data_refs)
    persistence_outputs = validate_persistence_outputs(
        persistence_outputs=artifact_refs)
    persistence_config = PersistenceConfig(data=persistence_data,
                                           outputs=persistence_outputs)
    instance.persistence = persistence_config.to_dict()
Exemplo n.º 4
0
def get_pod_data_volume(persistence_data):
    persistence_data = validate_persistence_data(
        persistence_data=persistence_data)
    volumes = []
    volume_mounts = []
    for persistence_name in persistence_data:
        persistence_volumes, persistence_volume_mounts = get_volume_from_definition(
            volume_name=persistence_name,
            volume_settings=conf.get(PERSISTENCE_DATA))
        volumes += persistence_volumes
        volume_mounts += persistence_volume_mounts
    return volumes, volume_mounts
Exemplo n.º 5
0
def get_data_store_secrets(persistence_data, data_paths):
    persistence_data = validate_persistence_data(
        persistence_data=persistence_data)
    secrets = set([])
    secret_items = {}
    for persistence_name in persistence_data:
        store, persistence_secret, persistence_secret_key = get_store_secret_for_persistence(
            volume_name=persistence_name,
            volume_settings=conf.get(PERSISTENCE_DATA))
        if persistence_secret and persistence_secret_key and persistence_name in data_paths:
            secrets.add((persistence_secret, persistence_secret_key))
            secret_items[data_paths[persistence_name]] = {
                'store': store,
                'secret_key': persistence_secret_key
            }
    return secrets, secret_items
Exemplo n.º 6
0
def _set_persistence(instance, default_persistence_data=None, default_persistence_outputs=None):
    if instance.persistence:
        return

    persistence_data = None
    persistence_outputs = None
    if instance.specification and instance.specification.persistence:
        persistence_data = instance.specification.persistence.data
        persistence_outputs = instance.specification.persistence.outputs
    if not persistence_data and default_persistence_data:
        persistence_data = default_persistence_data

    if not persistence_outputs and default_persistence_outputs:
        persistence_outputs = default_persistence_outputs

    persistence_data = validate_persistence_data(persistence_data=persistence_data)
    persistence_outputs = validate_persistence_outputs(persistence_outputs=persistence_outputs)
    persistence_config = PersistenceConfig(data=persistence_data, outputs=persistence_outputs)
    instance.persistence = persistence_config.to_dict()
Exemplo n.º 7
0
    def get_data_paths(persistence_data):
        persistence_data = validate_persistence_data(
            persistence_data=persistence_data)
        persistence_paths = {}
        for persistence in persistence_data:
            if persistence not in settings.PERSISTENCE_DATA:
                raise VolumeNotFoundError(
                    'Data volume with name `{}` was defined in specification, '
                    'but was not found'.format(persistence))
            persistence_type_condition = (
                'mountPath' not in settings.PERSISTENCE_DATA[persistence]
                and 'bucket' not in settings.PERSISTENCE_DATA[persistence])
            if persistence_type_condition:
                raise VolumeNotFoundError(
                    'Data volume with name `{}` '
                    'does not define a mountPath or bucket.'.format(
                        persistence))

            persistence_paths[persistence] = (
                settings.PERSISTENCE_DATA[persistence].get('mountPath')
                or settings.PERSISTENCE_DATA[persistence].get('bucket'))

        return persistence_paths
Exemplo n.º 8
0
 def test_validate_persistence_data(self):
     assert validate_persistence_data(['path1',
                                       'path2']) == ['path1', 'path2']
     assert validate_persistence_data(
         None) == settings.PERSISTENCE_DATA.keys()