Esempio n. 1
0
def test_get_did_details__no_force_fetch__attached_files_cached__all_replicas_cached__all_dids_available___should_not_fetch(
        rucio, mocker):
    mock_db = setup_common_mocks(mocker)
    mocker.patch.object(mock_db,
                        "get_attached_files",
                        return_value=MOCK_ATTACHED_FILES)
    mocker.patch.object(mock_db,
                        "get_file_replica",
                        side_effect=create_mock_db_get_file_replica())

    mock_scope = 'scope'
    mock_name = 'name'

    handler = ReplicaModeHandler(namespace='atlas', rucio=rucio)
    result = handler.get_did_details(mock_scope, mock_name, False)

    expected_result = [{
        'status': 'OK',
        'did': 'scope:name1',
        'path': '/eos/user/rucio/scope:name1',
        'size': 123
    }, {
        'status': 'OK',
        'did': 'scope:name2',
        'path': '/eos/user/rucio/scope:name2',
        'size': 123
    }, {
        'status': 'OK',
        'did': 'scope:name3',
        'path': '/eos/user/rucio/scope:name3',
        'size': 123
    }]

    assert result == expected_result, "Invalid return value"
Esempio n. 2
0
def test_make_available__lifetime_not_specified__should_call_add_rule__lifetime_none(mocker, rucio):
    mocker.patch.dict(rucio.instance_config, {'destination_rse': 'SWAN-EOS'})
    mocker.patch.object(rucio, 'add_replication_rule', return_value={})

    handler = ReplicaModeHandler(namespace='atlas', rucio=rucio)
    handler.make_available(scope='scope', name='name')

    expected_dids = [{'scope': 'scope', 'name': 'name'}]
    rucio.add_replication_rule.assert_called_once_with(dids=expected_dids, rse_expression='SWAN-EOS', copies=1, lifetime=None)
Esempio n. 3
0
def test_get_did_details__no_force_fetch__attached_files_cached__some_replicas_cached__not_all_dids_available___should_fetch_replica_and_rule(
        rucio, mocker):
    mock_db = setup_common_mocks(mocker)
    mocker.patch.object(mock_db,
                        "get_attached_files",
                        return_value=MOCK_ATTACHED_FILES)
    mocker.patch.object(mock_db,
                        "get_file_replica",
                        side_effect=create_mock_db_get_file_replica(
                            exist=[True, True, False],
                            missing=[True, False, False]))
    mocker.patch.object(rucio,
                        'get_rules',
                        return_value=mock_rucio_rule_status_replicating)
    mocker.patch.object(rucio,
                        "get_replicas",
                        return_value=mock_rucio_replicas_some_available)

    mock_scope = 'scope'
    mock_name = 'name'

    handler = ReplicaModeHandler(namespace='atlas', rucio=rucio)
    result = handler.get_did_details(mock_scope, mock_name, False)

    rucio.get_replicas.assert_called_once()
    rucio.get_rules.assert_called_once()

    expected_result = [{
        'status': 'OK',
        'did': 'scope:name1',
        'path': '/eos/user/rucio/scope:name1',
        'size': 123
    }, {
        'status': 'REPLICATING',
        'did': 'scope:name2',
        'path': None,
        'size': 123
    }, {
        'status': 'REPLICATING',
        'did': 'scope:name3',
        'path': None,
        'size': 123
    }]

    assert result == expected_result, "Invalid return value"
    def get(self):
        namespace = self.get_query_argument('namespace')
        poll = self.get_query_argument('poll', '0') == '1'
        did = self.get_query_argument('did')
        scope, name = did.split(':')

        rucio_instance = self.rucio.for_instance(namespace)
        mode = rucio_instance.instance_config.get('mode', 'replica')

        if mode == 'replica':
            handler = ReplicaModeHandler(namespace, rucio_instance)
        elif mode == 'download':
            handler = DownloadModeHandler(namespace, rucio_instance)

        try:
            output = handler.get_did_details(scope, name, poll)
            self.finish(json.dumps(output))
        except RucioAuthenticationException:
            self.set_status(401)
            self.finish(json.dumps({'error': 'Authentication error '}))
Esempio n. 5
0
    def post(self):
        namespace = self.get_query_argument('namespace')
        json_body = self.get_json_body()
        did = json_body['did']
        scope, name = did.split(':')

        rucio_instance = self.rucio.for_instance(namespace)
        mode = rucio_instance.instance_config.get('mode', 'replica')

        if mode == 'replica':
            handler = ReplicaModeHandler(namespace, rucio_instance)
        elif mode == 'download':
            handler = DownloadModeHandler(namespace, rucio_instance)

        try:
            output = handler.make_available(scope, name)
        except RucioAuthenticationException:
            self.set_status(401)
            output = {'error': 'Authentication error'}

        self.finish(json.dumps(output))
Esempio n. 6
0
def test_get_did_details__no_force_fetch__attached_files_not_cached__no_replicas_cached__all_dids_available___should_fetch_replica(
        rucio, mocker):
    mock_db = setup_common_mocks(mocker)
    mocker.patch.object(mock_db, "get_attached_files", return_value=None)
    mocker.patch.object(mock_db, "get_file_replica", return_value=None)
    mocker.patch.object(rucio,
                        'get_rules',
                        return_value=mock_rucio_rule_status_ok)
    mocker.patch.object(rucio,
                        "get_replicas",
                        return_value=mock_rucio_replicas_all_available)

    mock_scope = 'scope'
    mock_name = 'name'

    handler = ReplicaModeHandler(namespace='atlas', rucio=rucio)
    result = handler.get_did_details(mock_scope, mock_name, False)

    rucio.get_replicas.assert_called_once()
    rucio.get_rules.assert_not_called()

    expected_result = [{
        'status': 'OK',
        'did': 'scope:name1',
        'path': '/eos/user/rucio/scope:name1',
        'size': 123
    }, {
        'status': 'OK',
        'did': 'scope:name2',
        'path': '/eos/user/rucio/scope:name2',
        'size': 123
    }, {
        'status': 'OK',
        'did': 'scope:name3',
        'path': '/eos/user/rucio/scope:name3',
        'size': 123
    }]

    assert result == expected_result, "Invalid return value"