예제 #1
0
    def test_config_default_override(self):
        """LFN2PFN: Test override of default LFN2PFN algorithm via config (Success)"""
        if not config.config_has_section('policy'):
            config.config_add_section('policy')
        try:
            orig_value = config.config_get('policy',
                                           'lfn2pfn_algorithm_default')
        except (NoOptionError, NoSectionError):
            orig_value = None

        def static_test(scope, name, rse, rse_attrs, proto_attrs):
            """Static test function for config override."""
            del scope
            del name
            del rse
            del rse_attrs
            del proto_attrs
            return "static_test_value"

        RSEDeterministicTranslation.register(static_test)
        try:
            config.config_set('policy', 'lfn2pfn_algorithm_default',
                              'static_test')
            RSEDeterministicTranslation._module_init_()  # pylint: disable=protected-access
            assert_equal(self.translator.path("foo", "bar"),
                         "static_test_value")
        finally:
            if orig_value is None:
                config.config_remove_option('policy',
                                            'lfn2pfn_algorithm_default')
            else:
                config.config_set('policy', 'lfn2pfn_algorithm_default',
                                  orig_value)
            RSEDeterministicTranslation._module_init_()  # pylint: disable=protected-access
예제 #2
0
def file_config_mock(request):
    """
    Fixture which allows to have an isolated in-memory configuration file instance which
    is not persisted after exiting the fixture.

    This override works only in tests which use config calls directly, not in the ones working
    via the API, as the server config is not changed.
    """
    from unittest import mock
    from rucio.common.config import Config, config_set, config_has_section, config_add_section

    # Get the fixture parameters
    overrides = []
    params = __get_fixture_param(request)
    if params:
        overrides = params.get("overrides", overrides)

    parser = Config().parser
    with mock.patch('rucio.common.config.get_config',
                    side_effect=lambda: parser):
        for section, option, value in (overrides or []):
            if not config_has_section(section):
                config_add_section(section)
            config_set(section, option, value)
        yield
예제 #3
0
def load_schema_for_vo(vo):
    GENERIC_FALLBACK = 'generic_multi_vo'
    if config.config_has_section('policy'):
        try:
            POLICY = config.config_get('policy',
                                       'package-' + vo,
                                       check_config_table=False) + ".schema"
        except (NoOptionError, NoSectionError):
            # fall back to old system for now
            try:
                POLICY = config.config_get('policy',
                                           'schema',
                                           check_config_table=False)
            except (NoOptionError, NoSectionError):
                POLICY = GENERIC_FALLBACK
            POLICY = 'rucio.common.schema.' + POLICY.lower()
    else:
        POLICY = 'rucio.common.schema.' + GENERIC_FALLBACK.lower()

    try:
        module = importlib.import_module(POLICY)
    except ImportError:
        raise exception.PolicyPackageNotFound('Module ' + POLICY +
                                              ' not found')

    schema_modules[vo] = module
예제 #4
0
def load_permission_for_vo(vo):
    GENERIC_FALLBACK = 'generic_multi_vo'
    if config.config_has_section('policy'):
        try:
            env_name = 'RUCIO_POLICY_PACKAGE_' + vo.upper()
            if env_name in environ:
                POLICY = environ[env_name] + ".permission"
            else:
                POLICY = config.config_get('policy',
                                           'package-' + vo) + ".permission"
        except (NoOptionError, NoSectionError):
            # fall back to old system for now
            try:
                POLICY = config.config_get('policy', 'permission')
            except (NoOptionError, NoSectionError):
                POLICY = GENERIC_FALLBACK
            POLICY = 'rucio.core.permission.' + POLICY.lower()
    else:
        POLICY = 'rucio.core.permission.' + GENERIC_FALLBACK.lower()

    try:
        module = importlib.import_module(POLICY)
    except ImportError:
        raise exception.PolicyPackageNotFound('Module ' + POLICY +
                                              ' not found')

    permission_modules[vo] = module
예제 #5
0
 def test_module_load(self):
     """LFN2PFN: Test ability to provide LFN2PFN functions via module (Success)"""
     if not config.config_has_section('policy'):
         config.config_add_section('policy')
     config.config_set('policy', 'lfn2pfn_module', 'rucio.tests.lfn2pfn_module_test')
     RSEDeterministicTranslation._module_init_()  # pylint: disable=protected-access
     self.rse_attributes['lfn2pfn_algorithm'] = 'lfn2pfn_module_algorithm'
     self.create_translator()
     assert self.translator.path("foo", "bar") == "lfn2pfn_module_algorithm_value"
예제 #6
0
파일: __init__.py 프로젝트: yiiyama/rucio
 - Thomas Beermann, <*****@*****.**>, 2017
 - Hannes Hansen, <*****@*****.**>, 2018
 - James Perry, <*****@*****.**>, 2019

 PY3K COMPATIBLE
"""

try:
    from ConfigParser import NoOptionError, NoSectionError
except ImportError:
    from configparser import NoOptionError, NoSectionError
from rucio.common import config, exception

import importlib

if config.config_has_section('permission'):
    try:
        FALLBACK_POLICY = config.config_get('permission', 'policy')
    except (NoOptionError, NoSectionError) as error:
        FALLBACK_POLICY = 'generic'
elif config.config_has_section('policy'):
    try:
        FALLBACK_POLICY = config.config_get('policy', 'permission')
    except (NoOptionError, NoSectionError) as error:
        FALLBACK_POLICY = 'generic'
else:
    FALLBACK_POLICY = 'generic'

if config.config_has_section('policy'):
    try:
        POLICY = config.config_get('policy', 'package') + ".permission"
예제 #7
0
# limitations under the License.
#
# Authors:
# - Ralph Vigne, <*****@*****.**>, 2013 - 2014
# - Vincent Garonne, <*****@*****.**>, 2013-2017
# - Cedric Serfon, <*****@*****.**>, 2017-2019
# - James Perry, <*****@*****.**>, 2019
#
# PY3K COMPATIBLE

from dogpile.cache import make_region

from rucio.rse import rsemanager
from rucio.common import config

if config.config_has_section('database'):
    setattr(rsemanager, 'CLIENT_MODE', False)
    setattr(rsemanager, 'SERVER_MODE', True)
elif config.config_has_section('client'):
    setattr(rsemanager, 'CLIENT_MODE', True)
    setattr(rsemanager, 'SERVER_MODE', False)
else:
    setattr(rsemanager, 'CLIENT_MODE', False)
    setattr(rsemanager, 'SERVER_MODE', True)


def get_rse_client(rse, **kwarg):
    '''
    get_rse_client
    '''
    from rucio.client.rseclient import RSEClient
예제 #8
0
# - Vincent Garonne, <*****@*****.**>, 2016
# - Mario Lassnig, <*****@*****.**>, 2016

import errno
import json
import os
import re
import urlparse

from rucio.common import exception, config
from rucio.rse.protocols import protocol

try:
    import gfal2
except:
    if not config.config_has_section('database'):
        raise exception.MissingDependency('Missing dependency : gfal2')


class Default(protocol.RSEProtocol):
    """ Implementing access to RSEs using the srm protocol."""
    def lfns2pfns(self, lfns):
        """
        Returns a fully qualified PFN for the file referred by path.

        :param path: The path to the file.

        :returns: Fully qualified PFN.
        """

        pfns = {}
예제 #9
0
import importlib

from rucio.common import config
from rucio.common.exception import PolicyPackageNotFound, InvalidMetadata
from rucio.db.sqla.session import read_session

try:
    from ConfigParser import NoOptionError, NoSectionError
except ImportError:
    from configparser import NoOptionError, NoSectionError

HARDCODED_METADATA_HANDLER_MODULE = "rucio.core.did_meta_plugins.did_column_meta.DidColumnMeta"
FALLBACK_METADATA_HANDLER_MODULE = "rucio.core.did_meta_plugins.json_meta.JSONDidMeta"

if config.config_has_section('metadata'):
    try:
        METADATA_HANDLER_MODULES = config.config_get('metadata', 'plugins')
    except (NoOptionError, NoSectionError):
        METADATA_HANDLER_MODULES = FALLBACK_METADATA_HANDLER_MODULE
else:
    METADATA_HANDLER_MODULES = FALLBACK_METADATA_HANDLER_MODULE

META_MODULE_PATHS = [HARDCODED_METADATA_HANDLER_MODULE
                     ] + METADATA_HANDLER_MODULES.split(",")

METADATA_HANDLERS = []
for meta_module_path in META_MODULE_PATHS:
    try:
        base_module = ".".join(meta_module_path.split(".")[:-1])
        base_class = meta_module_path.split(".")[-1]
예제 #10
0
"""
 Copyright European Organization for Nuclear Research (CERN)

 Licensed under the Apache License, Version 2.0 (the "License");
 You may not use this file except in compliance with the License.
 You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

 Authors:
 - Vincent Garonne, <*****@*****.**>, 2017
"""

from ConfigParser import NoOptionError, NoSectionError

from rucio.common import config

if config.config_has_section('policy'):
    try:
        POLICY = config.config_get('policy', 'schema')
    except (NoOptionError, NoSectionError) as error:
        POLICY = 'generic'
else:
    POLICY = 'generic'

if POLICY.lower() == 'generic':
    from .generic import *  # NOQA pylint:disable=wildcard-import
elif POLICY.lower() == 'atlas':
    from .atlas import *  # NOQA pylint:disable=wildcard-import
elif POLICY.lower() == 'cms':
    from .cms import *  # NOQA pylint:disable=wildcard-import
else:
    from .generic import *  # NOQA pylint:disable=wildcard-import
예제 #11
0
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Vincent Garonne, <*****@*****.**>, 2016
# - Thomas Beermann, <*****@*****.**>, 2017
"""
Init
"""

from ConfigParser import NoOptionError, NoSectionError

from rucio.common import config

if config.config_has_section('permission'):

    try:
        POLICY = config.config_get('permission', 'policy')
    except (NoOptionError, NoSectionError) as error:
        POLICY = 'generic'

    if POLICY.lower() == 'generic':
        from rucio.core.permission.generic import *  # NOQA
    elif POLICY.lower() == 'atlas':
        from rucio.core.permission.atlas import *  # NOQA
    else:
        from rucio.core.permission.generic import *  # NOQA
else:
    from rucio.core.permission.generic import *  # NOQA
예제 #12
0
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Ralph Vigne, <*****@*****.**>, 2013 - 2014
# - Vincent Garonne, <*****@*****.**>, 2013-2014


from dogpile.cache import make_region

from rucio.rse import rsemanager
from rucio.common import config


if config.config_has_section('database'):
    setattr(rsemanager, 'CLIENT_MODE', False)
    setattr(rsemanager, 'SERVER_MODE', True)
elif config.config_has_section('client'):
    setattr(rsemanager, 'CLIENT_MODE', True)
    setattr(rsemanager, 'SERVER_MODE', False)
else:
    setattr(rsemanager, 'CLIENT_MODE', False)
    setattr(rsemanager, 'SERVER_MODE', True)


def get_rse_client(rse, **kwarg):
    from rucio.client.rseclient import RSEClient
    return RSEClient().get_rse(rse)