Ejemplo n.º 1
0
 def test_location_interpolation(self):
     config = Config(self.file_one)
     # file_one is a StringIO, so it has no location.
     self.assertEquals(config.get('one', 'location'), '%(here)s')
     # file_two is a real file, so it has a location.
     file_two_loc = os.path.dirname(self.file_two)
     self.assertEquals(config.get('three', 'location'), file_two_loc)
Ejemplo n.º 2
0
 def test_location_interpolation(self):
     config = Config(self.file_one)
     # file_one is a StringIO, so it has no location.
     self.assertEquals(config.get('one', 'location'), '${HERE}')
     # file_two is a real file, so it has a location.
     file_two_loc = os.path.dirname(self.file_two)
     self.assertEquals(config.get('three', 'location'), file_two_loc)
Ejemplo n.º 3
0
def get_crypto_worker(cls, config_file=None, **kwargs):
    """Builds a crypto worker with the given arguments.

    :param cls: the Worker class to use.
    :param config_file: the configuration file to read the values from.

    Additional keyword arguments are used to override the configuration read
    from the file. If no file is given, the keyword arguments will be used
    instead.
    """
    env_vars = ('http_proxy', 'https_proxy')
    config = {}
    if config_file is not None:
        conf = Config(config_file)
        section = 'crypto-worker'
        # bools
        for option in ('loadtest_mode', 'verify_ssl'):
            if conf.has_option(section, option):
                config[option] = bool(conf.get(section, option))

        # ints
        for option in ('memory_ttl', 'memcache_ttl'):
            if conf.has_option(section, option):
                config[option] = conf.getint(section, option)

        # strings
        if conf.has_option(section, 'memcache_host'):
            config['memcache_host'] = conf.get(section, 'memcache_host')

        # read the proxy configuration from the settings
        for env_var in env_vars:
            if conf.has_option(section, env_var):
                config[env_var] = conf.get(section, env_var)

    config.update(kwargs)

    # set the environment variables if they have been defined
    for var in env_vars:
        if var in config:
            os.environ[var.upper()] = config[var]

    mc_host = config.get('memcache_host', None)
    if mc_host is not None:
        mc_ttl = config['memcache_ttl']
        memcache = MemcachedClientWithTTL((mc_host,), ttl=mc_ttl)
    else:
        memcache = False

    memory = TTLedDict(ttl=config['memory_ttl'])
    loadtest_mode = config.get('loadtest_mode', False)
    verify = config.get('verify_ssl', True)

    supportdocs = SupportDocumentManagerWithCache(
        loadtest_mode=loadtest_mode,
        memory=memory,
        memcache=memcache,
        verify=verify
    )
    return cls(supportdocs=supportdocs)
Ejemplo n.º 4
0
def get_crypto_worker(cls, config_file=None, **kwargs):
    """Builds a crypto worker with the given arguments.

    :param cls: the Worker class to use.
    :param config_file: the configuration file to read the values from.

    Additional keyword arguments are used to override the configuration read
    from the file. If no file is given, the keyword arguments will be used
    instead.
    """
    env_vars = ('http_proxy', 'https_proxy')
    config = {}
    if config_file is not None:
        conf = Config(config_file)
        section = 'crypto-worker'
        # bools
        for option in ('loadtest_mode', 'verify_ssl'):
            if conf.has_option(section, option):
                config[option] = bool(conf.get(section, option))

        # ints
        for option in ('memory_ttl', 'memcache_ttl'):
            if conf.has_option(section, option):
                config[option] = conf.getint(section, option)

        # strings
        if conf.has_option(section, 'memcache_host'):
            config['memcache_host'] = conf.get(section, 'memcache_host')

        # read the proxy configuration from the settings
        for env_var in env_vars:
            if conf.has_option(section, env_var):
                config[env_var] = conf.get(section, env_var)

    config.update(kwargs)

    # set the environment variables if they have been defined
    for var in env_vars:
        if var in config:
            os.environ[var.upper()] = config[var]

    mc_host = config.get('memcache_host', None)
    if mc_host is not None:
        mc_ttl = config['memcache_ttl']
        memcache = MemcachedClientWithTTL((mc_host, ), ttl=mc_ttl)
    else:
        memcache = False

    memory = TTLedDict(ttl=config['memory_ttl'])
    loadtest_mode = config.get('loadtest_mode', False)
    verify = config.get('verify_ssl', True)

    supportdocs = SupportDocumentManagerWithCache(loadtest_mode=loadtest_mode,
                                                  memory=memory,
                                                  memcache=memcache,
                                                  verify=verify)
    return cls(supportdocs=supportdocs)
Ejemplo n.º 5
0
    def test_reader(self):
        config = Config(self.file_one)

        # values conversion
        self.assertEquals(config.get('one', 'foo'), 'bar')
        self.assertEquals(config.get('one', 'num'), -12)
        self.assertEquals(config.get('one', 'st'), 'o=k')
        self.assertEquals(config.get('one', 'lines'), [1, 'two', 3])
        self.assertEquals(config.get('one', 'env'), 'some stuff')

        # getting a map
        map = config.get_map()
        self.assertEquals(map['one.foo'], 'bar')

        map = config.get_map('one')
        self.assertEquals(map['foo'], 'bar')

        # extends
        self.assertEquals(config.get('three', 'more'), 'stuff')
        self.assertEquals(config.get('one', 'two'), 'a')
Ejemplo n.º 6
0
    def test_reader(self):
        config = Config(self.file_one)

        # values conversion
        self.assertEqual(config.get('one', 'foo'), 'bar')
        self.assertEqual(config.get('one', 'num'), -12)
        self.assertEqual(config.get('one', 'st'), 'o=k')
        self.assertEqual(config.get('one', 'lines'), [1, 'two', 3])
        self.assertEqual(config.get('one', 'env'), 'some stuff')

        # getting a map
        map = config.get_map()
        self.assertEqual(map['one.foo'], 'bar')

        map = config.get_map('one')
        self.assertEqual(map['foo'], 'bar')

        # extends
        self.assertEqual(config.get('three', 'more'), 'stuff')
        self.assertEqual(config.get('one', 'two'), 'a')
Ejemplo n.º 7
0
    def test_reader(self):
        config = Config(self.file_one)

        # values conversion
        self.assertEquals(config.get('one', 'foo'), 'bar')
        self.assertEquals(config.get('one', 'num'), -12)
        self.assertEquals(config.get('one', 'st'), 'o=k')
        self.assertEquals(config.get('one', 'lines'), [1, 'two', 3])
        self.assertEquals(config.get('one', 'env'), 'some stuff')

        # getting a map
        map = config.get_map()
        self.assertEquals(map['one.foo'], 'bar')

        map = config.get_map('one')
        self.assertEquals(map['foo'], 'bar')

        del os.environ['__STUFF__']
        self.assertRaises(EnvironmentNotFoundError, config.get, 'one', 'env')

        # extends
        self.assertEquals(config.get('three', 'more'), 'stuff')
        self.assertEquals(config.get('one', 'two'), 'a')
Ejemplo n.º 8
0
    def test_reader(self):
        config = Config(self.file_one)

        # values conversion
        self.assertEquals(config.get('one', 'foo'), 'bar')
        self.assertEquals(config.get('one', 'num'), -12)
        self.assertEquals(config.get('one', 'st'), 'o=k')
        self.assertEquals(config.get('one', 'lines'), [1, 'two', 3])
        self.assertEquals(config.get('one', 'env'), 'some stuff')

        # getting a map
        map = config.get_map()
        self.assertEquals(map['one.foo'], 'bar')

        map = config.get_map('one')
        self.assertEquals(map['foo'], 'bar')

        del os.environ['__STUFF__']
        self.assertRaises(EnvironmentNotFoundError, config.get, 'one', 'env')

        # extends
        self.assertEquals(config.get('three', 'more'), 'stuff')
        self.assertEquals(config.get('one', 'two'), 'a')