Exemplo n.º 1
0
def add_exception(dids, account, pattern, comments, expires_at, vo='def'):
    """
    Add exceptions to Lifetime Model.

    :param dids:        The list of dids
    :param account:     The account of the requester.
    :param pattern:     The account.
    :param comments:    The comments associated to the exception.
    :param expires_at:  The expiration date of the exception.
    :param vo:          The VO to act on.

    returns:            The id of the exception.
    """

    account = InternalAccount(account, vo=vo)
    for did in dids:
        did['scope'] = InternalScope(did['scope'], vo=vo)
    exceptions = lifetime_exception.add_exception(dids=dids, account=account, pattern=pattern, comments=comments, expires_at=expires_at)

    for key in exceptions:
        if key == 'exceptions':
            for reqid in exceptions[key]:
                for did in exceptions[key][reqid]:
                    did['scope'] = did['scope'].external
                    did['did_type'] = did['did_type'].name
        else:
            for did in exceptions[key]:
                did['scope'] = did['scope'].external
                did['did_type'] = did['did_type'].name

    return exceptions
Exemplo n.º 2
0
def add_exception(dids, account, pattern, comments, expires_at):
    """
    Add exceptions to Lifetime Model.

    :param dids:        The list of dids
    :param account:     The account of the requester.
    :param pattern:     The account.
    :param comments:    The comments associated to the exception.
    :param expires_at:  The expiration date of the exception.

    returns:            The id of the exception.
    """
    return lifetime_exception.add_exception(dids=dids, account=account, pattern=pattern, comments=comments, expires_at=expires_at)
Exemplo n.º 3
0
def add_exception(dids, account, pattern, comments, expires_at, vo='def'):
    """
    Add exceptions to Lifetime Model.

    :param dids:        The list of dids
    :param account:     The account of the requester.
    :param pattern:     The account.
    :param comments:    The comments associated to the exception.
    :param expires_at:  The expiration date of the exception.
    :param vo:          The VO to act on.

    returns:            The id of the exception.
    """

    account = InternalAccount(account, vo=vo)
    for d in dids:
        d['scope'] = InternalScope(d['scope'], vo=vo)
    return lifetime_exception.add_exception(dids=dids, account=account, pattern=pattern, comments=comments, expires_at=expires_at)
Exemplo n.º 4
0
def test_lifetime_creation_core(root_account, rse_factory, mock_scope,
                                did_factory):
    """
    Test the creation of a lifetime exception on the core side
    """
    nb_datatype = 3
    nb_datasets = 2 * nb_datatype
    yesterday = datetime.now() - timedelta(days=1)
    tomorrow = datetime.now() + timedelta(days=1)
    rse, rse_id = rse_factory.make_posix_rse()
    datasets = [did_factory.make_dataset() for _ in range(nb_datasets)]
    metadata = [str(uuid()) for _ in range(nb_datatype)]
    list_dids = []
    for cnt, meta in enumerate(metadata):
        dids = []
        for dataset in datasets[2 * cnt:2 * (cnt + 1)]:
            set_metadata(dataset['scope'], dataset['name'], 'datatype', meta)
            if cnt < nb_datatype - 1:
                set_metadata(dataset['scope'], dataset['name'], 'eol_at',
                             yesterday)
            dids.append((dataset['scope'], dataset['name']))
        dids.sort()
        list_dids.append(dids)
    datasets.extend([{
        'scope': mock_scope,
        'name': 'dataset_%s' % str(uuid()),
        'did_type': DIDType.DATASET
    } for _ in range(2)])

    # Test with cutoff_date not defined
    try:
        config_core.remove_option('lifetime_model', 'cutoff_date')
    except (ConfigNotFound, NoSectionError):
        pass

    with pytest.raises(UnsupportedOperation):
        add_exception(datasets,
                      root_account,
                      pattern='wekhewfk',
                      comments='This is a comment',
                      expires_at=datetime.now())

    # Test with cutoff_date wrongly defined
    config_core.set(section='lifetime_model',
                    option='cutoff_date',
                    value='wrong_value')
    config_core.get(section='lifetime_model',
                    option='cutoff_date',
                    default=None,
                    use_cache=False)
    with pytest.raises(UnsupportedOperation):
        add_exception(datasets,
                      root_account,
                      pattern='wekhewfk',
                      comments='This is a comment',
                      expires_at=datetime.now())

    # Test with cutoff_date properly defined
    tomorrow = tomorrow.strftime('%Y-%m-%d')
    config_core.set(section='lifetime_model',
                    option='cutoff_date',
                    value=tomorrow)
    config_core.get(section='lifetime_model',
                    option='cutoff_date',
                    default=None,
                    use_cache=False)
    result = add_exception(datasets,
                           root_account,
                           pattern='wekhewfk',
                           comments='This is a comment',
                           expires_at=datetime.now())

    # Check if the Not Existing DIDs are identified
    result_unknown = [(entry['scope'], entry['name'])
                      for entry in result['unknown']]
    result_unknown.sort()
    unknown = [(entry['scope'], entry['name'])
               for entry in datasets[nb_datasets:nb_datasets + 2]]
    unknown.sort()
    assert result_unknown == unknown

    # Check if the DIDs not affected by the Lifetime Model are identified
    result_not_affected = [(entry['scope'], entry['name'])
                           for entry in result['not_affected']]
    result_not_affected.sort()
    not_affected = list_dids[-1]
    assert result_not_affected == not_affected

    # Check if an exception was done for each datatype
    list_exceptions = list()
    for exception_id in result['exceptions']:
        dids = [(entry['scope'], entry['name'])
                for entry in result['exceptions'][exception_id]]
        dids.sort()
        list_exceptions.append(dids)

    for did in list_dids[:nb_datatype - 1]:
        assert did in list_exceptions