Exemple #1
0
def load_app_test(app_started, app_tests_list):

    from base_common.importer import import_from_settings
    from base_common.importer import get_installed_apps
    from base_common.importer import get_app
    import base_tests.test_list
    imported_modules = []
    installed_apps = {}
    get_installed_apps(installed_apps)
    import_from_settings(imported_modules, app_started)

    _installed_app = get_app()
    _pm = _installed_app['pkg']
    import importlib
    app_tests = importlib.import_module(_pm.TESTS)

    for itest in app_tests.tests_included:

        app_test = getattr(app_tests, itest)

        if hasattr(base_tests.test_list, itest):
            log_info('OVERLOADING {}'.format(itest), '', None)
            setattr(base_tests.test_list, itest, app_test)

        else:
            log_info('LOADING {}'.format(itest), '', None)
            app_tests_list.append(app_test)
Exemple #2
0
def load_app_test(app_started, app_tests_list):

    from base_common.importer import import_from_settings
    from base_common.importer import get_installed_apps
    from base_common.importer import get_app
    import base_tests.test_list
    imported_modules = []
    installed_apps = {}
    get_installed_apps(installed_apps)
    import_from_settings(imported_modules, app_started)

    _installed_app = get_app()
    _pm = _installed_app['pkg']
    import importlib
    app_tests = importlib.import_module(_pm.TESTS)

    for itest in app_tests.tests_included:

        app_test = getattr(app_tests, itest)

        if hasattr(base_tests.test_list, itest):
            log_info('OVERLOADING {}'.format(itest), '', None)
            setattr(base_tests.test_list, itest, app_test)

        else:
            log_info('LOADING {}'.format(itest), '', None)
            app_tests_list.append(app_test)
Exemple #3
0
def load_app_test(app_started, app_tests_list, stage):
    from base_common.importer import import_from_settings
    from base_common.importer import get_installed_apps
    from base_common.importer import get_app
    import base_tests.test_list

    imported_modules = {}
    installed_apps = {}
    get_installed_apps(installed_apps)
    import_from_settings(imported_modules, app_started)

    _installed_app = get_app()
    _pm = _installed_app["pkg"]
    import importlib

    app_tests = importlib.import_module(_pm.TESTS)

    _last_stage = 0
    for itest in app_tests.tests_included:

        t_s = itest[0]
        t_n = itest[1]

        if t_s < _last_stage:
            log_warning("Exiting after: {}".format(t_n), "", None)
            break

        if t_s < stage:
            continue

        app_test = getattr(app_tests, t_n)

        if hasattr(base_tests.test_list, t_n):
            log_info("OVERLOADING {}".format(t_n), "", None)
            setattr(base_tests.test_list, t_n, app_test)

        else:
            log_info("LOADING {}".format(t_n), "", None)
            app_tests_list.append((app_test, t_s))

        _last_stage = t_s
Exemple #4
0
def load_app_test(app_started, app_tests_list, stage):
    from base_common.importer import import_from_settings
    from base_common.importer import get_installed_apps
    from base_common.importer import get_app
    import base_tests.test_list
    imported_modules = {}
    installed_apps = {}
    get_installed_apps(installed_apps)
    import_from_settings(imported_modules, app_started)

    _installed_app = get_app()
    _pm = _installed_app['pkg']
    import importlib
    app_tests = importlib.import_module(_pm.TESTS)

    _last_stage = 0
    for itest in app_tests.tests_included:

        t_s = itest[0]
        t_n = itest[1]

        if t_s < _last_stage:
            log_warning('Exiting after: {}'.format(t_n), '', None)
            break

        if t_s < stage:
            continue

        app_test = getattr(app_tests, t_n)

        if hasattr(base_tests.test_list, t_n):
            log_info('OVERLOADING {}'.format(t_n), '', None)
            setattr(base_tests.test_list, t_n, app_test)

        else:
            log_info('LOADING {}'.format(t_n), '', None)
            app_tests_list.append((app_test, t_s))

        _last_stage = t_s
Exemple #5
0
def start_base_service():
    close_stdout(csettings.DEBUG)

    imported_modules = {}
    installed_apps = {}

    try:
        get_installed_apps(installed_apps)
    except ApplicationNameUsed as e:
        log.critical('Application name collision, check installed applications: {}'.format(e))
        print('Application name collision, check installed applications: {}'.format(e))
        sys.exit(4)

    b_args = check_args(installed_apps)

    svc_port = b_args.port if b_args.port else installed_apps[b_args.app]['svc_port']
    check_test_port_is_used(svc_port, b_args.app)

    if not svc_port:
        log.critical('No svc port provided, lok in app config or add in commandline')
        print('Please provide svc_port in app init or trough commandline')
        sys.exit(3)

    from base_common.dbaexc import BalancingAppException
    try:
        import_from_settings(imported_modules, b_args.app)
    except BalancingAppException as e:
        log.critical('Error loading balance servers: {}'.format(e))
        sys.exit(5)

    entry_points = [entry_point(p, m) for p, m in imported_modules.items()]

    if b_args.test:
        setattr(csettings, 'TEST_MODE', True)
        prepare_test_env()
        svc_port = csettings.TEST_PORT
        start_tests(b_args.app, b_args.test, b_args.keep)

    baseapi_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    tpl_dir = os.path.join(baseapi_dir, 'templates')
    st_dir = os.path.join(baseapi_dir, 'static')

    application = tornado.web.Application([
        (r'^/$', base_svc.comm.MainHandler),
        (r'^/spec.*$', base_svc.comm.MainHandler),
        *entry_points
    ],
        template_path=tpl_dir,
        static_path=st_dir,
        cookie_secret="d1g1t4l", debug=csettings.DEBUG)

    try:
        application.listen(svc_port)
        log.info('Starting base_svc v({}) on port {}'.format(csettings.__VERSION__, svc_port))
        tornado.ioloop.IOLoop.instance().start()

    except gaierror:
        log.critical("Missing port for service, port = {}".format(svc_port))
        print("Missing port for service, port = {}".format(svc_port))

    except Exception as e:
        log.critical("Exception: {}".format(e))
        print("Critical exception: {}".format(e), file=sys.stderr)