Exemplo n.º 1
0
def create_tracker_collection():
    parser = ArgumentParser(description="Create tracker collection")
    parser.add_argument('-s',
                        '--size',
                        default=1000000000,
                        dest='size',
                        help="size of the collection in bytes, default is 1GB")
    parser.add_argument(
        '-c',
        '--config',
        dest='config',
        help='Path to configuration file (defaults to $CWD/etc/dev.ini)',
        metavar='FILE')

    args = parser.parse_args()
    size = int(args.size)
    config = args.config or get_default_config()
    logging.config.fileConfig(config)
    db = init_mongo()
    log.info('creating tracker collection: size={0}b in db={1}'.format(
        size, db.name))
    args = {'capped': True, 'size': size}
    try:
        db.create_collection("tracker", **args)
    except CollectionInvalid, e:
        log.fatal(e)
        sys.exit(-1)
Exemplo n.º 2
0
def read_config(config_file_path=None, section=None):
    config_file_path = config_file_path or get_default_config()
    check_config_path(config_file_path)
    config = ConfigParser.ConfigParser()
    log.info('reading config from file: {0}'.format(config_file_path))

    with open(config_file_path, 'r') as config_file:
        content = config_file.read()
        content = run_template(content, getenv=lambda x: os.environ.get(x, ''))

    config.readfp(StringIO(content))
    section = section or 'DEFAULT'
    return dict(config.items(section))
Exemplo n.º 3
0
def read_config(config_file_path=None, section=None):
    config_file_path = config_file_path or get_default_config()
    check_config_path(config_file_path)
    config = ConfigParser.ConfigParser()
    log.info('reading config from file: {0}'.format(config_file_path))

    with open(config_file_path, 'r') as config_file:
        content = config_file.read()
        content = run_template(content, getenv=lambda x: os.environ.get(x, ''))

    config.readfp(StringIO(content))
    section = section or 'DEFAULT'
    return dict(config.items(section))
Exemplo n.º 4
0
def main():
    """

    Launches application
    """
    parser = ArgumentParser(
        description="Run Mirage app"
    )
    parser.add_argument('-c', '--config', dest='config',
                        help="Path to configuration file (defaults to $CWD/etc/dev.ini)")

    args = parser.parse_args()
    # looking for configuration path
    config_path = args.config
    if not config_path:
        # if path not provided - looking at default directory - project root
        config_path = get_default_config()
    try:
        fileConfig(config_path)
    except Exception, e:
        print "Unable to load config file: {0}, error={1}".format(config_path, e)
        sys.exit(-1)
Exemplo n.º 5
0
def create_tracker_collection():
    parser = ArgumentParser(
        description="Create tracker collection"
    )
    parser.add_argument('-s', '--size', default=1000000000,
                        dest='size', help="size of the collection in bytes, default is 1GB")
    parser.add_argument('-c', '--config', dest='config',
                        help='Path to configuration file (defaults to $CWD/etc/dev.ini)',
                        metavar='FILE')

    args = parser.parse_args()
    size = int(args.size)
    config = args.config or get_default_config()
    logging.config.fileConfig(config)
    db = init_mongo()
    log.info('creating tracker collection: size={0}b in db={1}'.format(size,
                                                                       db.name))
    args = {'capped': True, 'size': size}
    try:
        db.create_collection("tracker", **args)
    except CollectionInvalid, e:
        log.fatal(e)
        sys.exit(-1)
Exemplo n.º 6
0
def main():
    """

    Launches application
    """
    parser = ArgumentParser(description="Run Mirage app")
    parser.add_argument(
        '-c',
        '--config',
        dest='config',
        help="Path to configuration file (defaults to $CWD/etc/dev.ini)")

    args = parser.parse_args()
    # looking for configuration path
    config_path = args.config
    if not config_path:
        # if path not provided - looking at default directory - project root
        config_path = get_default_config()
    try:
        fileConfig(config_path)
    except Exception, e:
        print "Unable to load config file: {0}, error={1}".format(
            config_path, e)
        sys.exit(-1)
Exemplo n.º 7
0
def purge_stubs():
    # importing helper handler from testing deps
    from stubo.testing import DummyRequestHandler
    parser = ArgumentParser(
        description="Purge stubs older than given expiry date."
    )
    parser.add_argument('-l', '--list', action='store_const', const=True,
                        dest='list_only', help="Just list the stubs to delete.")
    parser.add_argument('-e', '--expiry', default=14, dest='expiry',
                        help="expiry is number of days from now (default is 14).")
    parser.add_argument('--host', default='all', dest='host',
                        help="specify the host uri to use (defaults to all)")
    parser.add_argument('-c', '--config', dest='config',
                        help='Path to configuration file (defaults to $CWD/etc/dev.ini)',
                        metavar='FILE')

    args = parser.parse_args()
    list_only = args.list_only or False
    expiry_days = args.expiry
    expiry = datetime.today().date() - timedelta(int(expiry_days))
    host = args.host
    config = args.config or get_default_config()
    logging.config.fileConfig(config)

    settings = read_config(config)
    dbenv = default_env.copy()
    dbenv.update((k[6:], coerce_mongo_param(k[6:], v)) for k, v in \
                 settings.iteritems() if k.startswith('mongo.'))
    log.debug('mongo params: {0}'.format(dbenv))

    log.info('purge stubs whereby all sessions in the scenario were last used before {0}'.format(expiry))

    db_conn = init_mongo(dbenv).connection
    slave, master = start_redis(settings)
    response = list_scenarios(host)
    if 'error' in response:
        print response['error']
        sys.exit(-1)

    handler = DummyRequestHandler()
    session_handler = DummyRequestHandler()

    for scenario_key in response['data']['scenarios']:
        log.debug("*** scenario '{0}' ***".format(scenario_key))
        hostname, scenario = scenario_key.split(':')
        if host != 'all' and host != hostname:
            continue
        handler.host = hostname
        handler.request.host = '{0}:8001'.format(hostname)
        session_handler.host = hostname
        session_handler.request.host = '{0}:8001'.format(hostname)
        handler.request.arguments['scenario'] = [scenario]
        status = get_status(handler)
        if 'error' in status:
            log.warn('get_status error: {0}'.format(status['error']))
        else:
            scenario_last_used = []
            sessions = status['data']['sessions']
            for session in zip(*sessions)[0]:
                log.debug("*** -> session '{0}' ***".format(session))
                session_handler.request.arguments['session'] = [session]
                session_status = get_status(session_handler)
                if 'error' in session_status:
                    log.warn('get_status error: {0}'.format(status['error']))
                else:
                    last_used = session_status['data']['session'].get('last_used', '-')
                    if last_used != '-':
                        scenario_last_used.append(as_date(last_used[0:10]))

            if scenario_last_used and (max(scenario_last_used) < expiry):
                log.info("sessions in scenario '{0}' were last used '{1}' which"
                         " is before expiry date '{2}'".format(scenario_key,
                                                               max(scenario_last_used), expiry))
                if not list_only:
                    response = delete_stubs(handler, scenario_name=scenario,
                                            force=True)
                    if 'error' in response:
                        log.error('delete stubs error: {0}'.format(response['error']))
                    else:
                        log.info('deleted stubs: {0}'.format(response['data']))