Beispiel #1
0
def client(backend, request, tmpdir, namespace_string):
    config_path = str(request.fspath.dirpath('config_{0}.yaml'.format(backend)))
    statsfile = StringIO.StringIO()
    params = dict(
        app_name='kvlayer',
        namespace=namespace_string,
        log_stats=statsfile,
        log_stats_interval_ops=1,
        blagh='hoo haa',
    )

    # this is hacky but must go somewhere
    if backend == 'filestorage':
        local = tmpdir.join('local')
        with local.open('w') as f: pass
        params['kvlayer_filename'] = str(local)

    if backend == 'redis':
        params['storage_addresses'] = [ redis_address(request) ]

    with yakonfig.defaulted_config([kvlayer], filename=config_path,
                                   params=params):
        client = kvlayer.client()
        client.delete_namespace()
        yield client
        client.delete_namespace()
Beispiel #2
0
def client(backend, request, tmpdir, namespace_string):
    if backend in _extension_test_configs:
        file_config = yaml.load(_extension_test_configs[backend])
    else:
        config_path = str(request.fspath.dirpath('config_{0}.yaml'
                                                 .format(backend)))
        # read and parse the config file, insert an object
        with open(config_path, 'r') as f:
            file_config = yaml.load(f)

    # Insert an object into the config which stats will write to.
    # Below we can get the stats text and log it here.
    # (Normal stats flow logs to file.)
    file_config['kvlayer']['log_stats'] = StringIO()
    file_config['kvlayer']['encoder'] = 'packed'

    params = dict(
        app_name='kvlayer',
        namespace=namespace_string,
    )

    # this is hacky but must go somewhere
    if backend == 'filestorage':
        local = tmpdir.join('local')
        with local.open('w') as f:
            pass
        params['kvlayer_filename'] = str(local)

    if backend == 'redis':
        params['storage_addresses'] = [redis_address(request)]

    with yakonfig.defaulted_config(
            [kvlayer],
            config=file_config,
            params=params):
        client = kvlayer.client()
        client.delete_namespace()
        yield client
        if client._log_stats is not None:
            client._log_stats.flush()
            logger.info('storage stats (%s %s):\n%s',
                        backend, request.function.__name__,
                        file_config['kvlayer']['log_stats'].getvalue())
        client.delete_namespace()