Exemplo 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)
Exemplo n.º 2
0
    def test_loading_from_config(self):
        config = Config(StringIO(dedent("""
        [test1]
        enabled=true
        backend = mozsvc.metrics.MetlogPlugin
        sender_class=metlog.senders.ZmqPubSender
        sender_bindstrs=tcp://localhost:5585
                        tcp://localhost:5586

        [test2]
        dontusethis =  seriously
        """)))
        settings = {"config": config}
        plugin = load_from_config("test1", config)
        config = Configurator(settings=settings)
        config.commit()
        self.failUnless(isinstance(plugin, MetlogPlugin))
        self.failUnless(isinstance(plugin.client, MetlogClient))
        self.failUnless(isinstance(plugin.client.sender, ZmqPubSender))

        client = plugin.client
        sender = client.sender

        self.assertEquals(sender.bindstrs, \
                ['tcp://localhost:5585', 'tcp://localhost:5586'])
Exemplo n.º 3
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)
Exemplo 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)
Exemplo n.º 5
0
 def setUp(self):
     config = Config(StringIO(dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     sender_class=metlog.senders.DebugCaptureSender
     """)))
     settings = {"config": config}
     self.plugin = load_from_config("test1", config)
     config = Configurator(settings=settings)
     config.commit()
Exemplo n.º 6
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)
 def setUp(self):
     config = Config(StringIO(dedent("""
     [test1]
     enabled=true
     backend = mozsvc.metrics.MetlogPlugin
     sender_class=metlog.senders.DebugCaptureSender
     disable_timeit=true
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     self.plugin = load_and_register("test1", config)
     config.commit()
 def setUp(self):
     if not metlog:
         raise(unittest2.SkipTest('no metlog'))
     self.orig_globals = CLIENT_HOLDER.global_config.copy()
     config = Config(StringIO(dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     logger = test
     sender_class=metlog.senders.DebugCaptureSender
     global_disabled_decorators = timeit
                                  something
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     self.plugin = load_and_register("test1", config)
     config.commit()
Exemplo n.º 9
0
 def setUp(self):
     if not metlog:
         raise (unittest2.SkipTest('no metlog'))
     self.orig_globals = CLIENT_HOLDER.global_config.copy()
     config = Config(
         StringIO(
             dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     logger = test
     sender_class=metlog.senders.DebugCaptureSender
     global_disabled_decorators = timeit
                                  something
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     self.plugin = load_and_register("test1", config)
     config.commit()
Exemplo n.º 10
0
 def test_loading_from_config(self):
     config = Config(StringIO(dedent("""
     [test1]
     backend = mozsvc.tests.test_plugin.Test1
     arg1 = 1
     hello = world
     [test2]
     dontusethis =  seriously
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     plugin = load_and_register("test1", config)
     config.commit()
     self.failUnless(verifyObject(ITest1, plugin))
     self.failUnless(isinstance(plugin, Test1))
     self.assertEquals(plugin.kwds["arg1"], 1)
     self.assertEquals(plugin.kwds["hello"], "world")
     self.assertEquals(len(plugin.kwds), 2)
     self.failUnless(config.registry.queryUtility(ITest1) is plugin)
Exemplo n.º 11
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')
Exemplo n.º 12
0
 def setUp(self):
     if not metlog:
         raise(unittest2.SkipTest('no metlog'))
     mozconfig = Config(StringIO(dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     sender_class=metlog.senders.DebugCaptureSender
     """)))
     settings = {"config": mozconfig}
     self.plugin = load_from_config("test1", mozconfig)
     config = Configurator(settings=settings)
     config.commit()
Exemplo n.º 13
0
 def test_loading_from_config(self):
     config = Config(
         StringIO(
             dedent("""
     [test1]
     backend = mozsvc.tests.test_plugin.Test1
     arg1 = 1
     hello = world
     [test2]
     dontusethis =  seriously
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     plugin = load_and_register("test1", config)
     config.commit()
     self.assertTrue(verifyObject(ITest1, plugin))
     self.assertTrue(isinstance(plugin, Test1))
     self.assertEqual(plugin.kwds["arg1"], 1)
     self.assertEqual(plugin.kwds["hello"], "world")
     self.assertEqual(len(plugin.kwds), 2)
     self.assertTrue(config.registry.queryUtility(ITest1) is plugin)
Exemplo n.º 14
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')
Exemplo n.º 15
0
 def setUp(self):
     if not metlog:
         raise(unittest2.SkipTest('no metlog'))
     mozconfig = Config(StringIO(dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     sender_class=metlog.senders.DebugCaptureSender
     """)))
     settings = {"config": mozconfig}
     self.plugin = load_from_config("test1", mozconfig)
     self.config = Configurator(settings=settings)
     self.config.include("cornice")
     self.config.scan("mozsvc.tests.test_service_definition")
     self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
Exemplo n.º 16
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')
Exemplo n.º 17
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')
Exemplo n.º 18
0
def main(global_config, **settings):
    config_file = global_config['__file__']
    config_file = os.path.abspath(
        os.path.normpath(os.path.expandvars(os.path.expanduser(config_file))))

    settings['config'] = config = Config(config_file)

    # Put values from the config file into the pyramid settings dict.
    for section in config.sections():
        setting_prefix = section.replace(":", ".")
        for name, value in config.get_map(section).iteritems():
            settings[setting_prefix + "." + name] = value

    config = Configurator(root_factory=Root,
                          settings=settings,
                          authentication_policy=QueueyAuthenticationPolicy(),
                          authorization_policy=ACLAuthorizationPolicy())

    config.registry['backend_storage'] = configure_from_settings(
        'storage', settings['config'].get_map('storage'))
    config.registry['backend_metadata'] = configure_from_settings(
        'metadata', settings['config'].get_map('metadata'))

    # Load the Metlog Client instance
    config.registry['metlog_client'] = client_from_dict_config(
        settings['config'].get_map('metlog'))

    # Load the application keys
    app_vals = settings['config'].get_map('application_keys')
    app_keys = {}
    for k, v in app_vals.items():
        for item in v:
            app_keys[item] = k
    config.registry['app_keys'] = app_keys
    config.registry['app_names'] = app_vals.keys()

    # adds Mozilla default views
    config.include("mozsvc")

    config.scan('queuey.views')

    # Replace default renderer with ujson rendering
    config.add_renderer(None, 'queuey.views.UJSONRendererFactory')
    return config.make_wsgi_app()
Exemplo n.º 19
0
    def test_loading_from_config(self):
        mozconfig = Config(StringIO(dedent("""
        [test1]
        backend = mozsvc.metrics.MetlogPlugin
        sender_class=metlog.senders.UdpSender
        sender_host=localhost
        sender_port=23456

        [test2]
        dontusethis =  seriously
        """)))
        settings = {"config": mozconfig}
        plugin = load_from_config("test1", mozconfig)
        config = Configurator(settings=settings)
        config.commit()
        self.failUnless(isinstance(plugin, MetlogPlugin))
        self.failUnless(isinstance(plugin.client, MetlogClient))
        self.failUnless(isinstance(plugin.client.sender, UdpSender))

        client = plugin.client
        sender = client.sender
        destination = sender._destinations[0]

        self.assertEquals(destination, ("localhost", 23456))