Пример #1
0
    def setUp(self):
        initialize_database(":memory:", reset=True)

        self.source = BaseBootstrapSource()

        def lookup_host(hostname):
            return {
                'the.host': {
                    'hostname': 'the.host',
                    'uses_ssl': True,
                    'cdn': 'thecdn'
                },
                'missingcdn.host': {
                    'hostname': 'missingcdn.host',
                    'cdn': 'missingcdn'
                },
                'invalid.host': {
                    'hostname': 'invalid.host',
                    'uses_ssl': True,
                },
                'mismatch.host': {
                    'hostname': 'the.host',
                    'uses_ssl': True,
                    'cdn': 'thecdn'
                },
                'badcdn.host': {
                    'hostname': 'badcdn.host',
                    'cdn': 'invalidcdn'
                }
            }.get(hostname, None)

        def lookup_cdn(cdn_id):
            return {
                'thecdn': {
                    'id': 'thecdn',
                    'name': 'The CDN',
                    'edge_server': '1.2.3.4'
                },
                'invalidcdn': {
                    'name': 'The CDN',
                    'edge_server': '1.2.3.4'
                },
            }.get(cdn_id, None)

        self.source.lookup_host = lookup_host
        self.source.lookup_cdn = lookup_cdn

        self.bootstrapper = Bootstrapper()
        self.bootstrapper.add_source(self.source)
Пример #2
0
def main():
    parse_arguments()
    init_logging()
    models.initialize_database(settings['database'])
    bootstrap.initialize_bootstrapper()

    command = settings.get('command', None)
    if command:
        run_command(command)
        return

    if settings.get('daemon', False):
        daemon = Daemon('/tmp/cachebrowser.pid', run_cachebrowser)
        daemon.start()
    else:
        run_cachebrowser()
Пример #3
0
def main():
    parse_arguments()
    init_logging()
    models.initialize_database(settings['database'])
    bootstrap.initialize_bootstrapper()

    command = settings.get('command', None)
    if command:
        run_command(command)
        return

    if settings.get('daemon', False):
        daemon = Daemon('/tmp/cachebrowser.pid', run_cachebrowser)
        daemon.start()
    else:
        run_cachebrowser()
Пример #4
0
    def test_database(self):
        initialize_database(":memory:", reset=True)

        cdn1 = CDN.create(id="cdn1", name="Sample CDN", edge_server="1.2.3.4")
        cdn2 = CDN.create(id="cdn2", name="Sample CDN2", edge_server="1.2.3.5")
        host1 = Host.create(hostname="first.host", cdn=cdn1)
        host2 = Host.create(hostname="second.host", cdn=cdn2)
        host3 = Host.create(hostname="third.host", cdn=cdn1)

        self.assertEqual([host1, host2, host3], list(Host.select()))
        self.assertEqual([host1, host3], Host.select().where(Host.cdn == cdn1))
        self.assertEqual([host1, host3], Host.select().join(CDN).where(CDN.id == 'cdn1'))
        self.assertEqual(host2, Host.get(Host.cdn == cdn2))

        self.assertEqual([], CDN.select().where(CDN.id == "doesntexist"))
        with self.assertRaises(DoesNotExist):
            CDN.get(CDN.id == "doesntexist")
Пример #5
0
def cachebrowser(click_context, config, verbose, reset_db, dev, **kwargs):
    settings = DevelopmentSettings() if dev else ProductionSettings()

    if config is None and os.path.isfile(settings.data_path('config.yaml')):
        config = open(settings.data_path('config.yaml'))

    try:
        settings.update_with_settings_file(config)
        settings.update_with_args(kwargs)
        settings.validate()
    except SettingsValidationError as e:
        print("Error parsing settings")
        print(e.message)
        sys.exit(1)

    initialize_logging(verbose)

    if not dev:
        check_data_files(settings)

    logger.debug("Initializing database {}".format(settings.database))
    initialize_database(settings.database, reset_db)

    logger.debug("Initializing bootstrapper")
    bootstrapper = Bootstrapper(settings)

    context = Context()
    context.bootstrapper = bootstrapper
    context.settings = settings
    context.click = click_context

    click_context.obj = context

    if click_context.invoked_subcommand is None:
        logger.debug("No command specified, starting CacheBrowser server")
        click_context.invoke(start_cachebrowser_server)
Пример #6
0
def cachebrowser(click_context, config, verbose, reset_db, dev, **kwargs):
    settings = DevelopmentSettings() if dev else ProductionSettings()

    if config is None and os.path.isfile(settings.data_path('config.yaml')):
        config = open(settings.data_path('config.yaml'))

    try:
        settings.update_with_settings_file(config)
        settings.update_with_args(kwargs)
        settings.validate()
    except SettingsValidationError as e:
        print("Error parsing settings")
        print(e.message)
        sys.exit(1)

    initialize_logging(verbose)

    if not dev:
        check_data_files(settings)

    logger.debug("Initializing database")
    initialize_database(settings.database, reset_db)

    logger.debug("Initializing bootstrapper")
    bootstrapper = Bootstrapper(settings)

    context = Context()
    context.bootstrapper = bootstrapper
    context.settings = settings
    context.click = click_context

    click_context.obj = context

    if click_context.invoked_subcommand is None:
        logger.debug("No command specified, starting CacheBrowser server")
        click_context.invoke(start_cachebrowser_server)