예제 #1
0
def register_nest_endpoints(flask_app, project_env, authenticator):
    db_engine = nest_db.get_global_sqlalchemy_engine()
    sqla_md = nest_db.get_global_sqlalchemy_metadata()
    if ProjectEnv.hello_world_instance() == project_env:
        import nest_py.hello_world.flask.hw_flask as hw_flask
        nest_endpoints = hw_flask.get_nest_endpoints(db_engine, sqla_md,
                                                     authenticator)
    elif ProjectEnv.mmbdb_instance() == project_env:
        import nest_py.omix.flask.omix_flask as omix_flask
        nest_endpoints = omix_flask.get_nest_endpoints(db_engine, sqla_md,
                                                       authenticator)
    elif ProjectEnv.knoweng_instance() == project_env:
        import nest_py.knoweng.flask.knoweng_flask as knoweng_flask
        nest_endpoints = knoweng_flask.get_nest_endpoints(
            db_engine, sqla_md, authenticator)
    else:
        raise Exception("Unknown project when registering endpoints")

    for flask_ep in nest_endpoints.get_flask_endpoints():
        nest_ep = nest_endpoints.get_endpoint(flask_ep)
        relative_flask_rule = nest_ep.get_flask_rule()
        rule = API_PREFIX + relative_flask_rule
        print('registering flask rule: ' + str(rule))
        flask_ep = nest_ep.get_flask_endpoint()
        renderer = nest_ep.handle_request
        flask_app.add_url_rule(rule,
                               flask_ep,
                               view_func=renderer,
                               methods=['GET', 'POST', 'PATCH', 'DELETE'])
    return
예제 #2
0
def _run_seed_script(project_env, target_site, flavor_name, subsample):
    """
    runs a seeding job. logs the final result and returns
    a 0/1 exit code based on whether all walkthroughs worked.
    """
    http_client = target_site.build_http_client()

    data_projects_dir = '/code_live/data/projects/'

    if project_env == ProjectEnv.hello_world_instance():
        data_dir = data_projects_dir + 'hello_world/'
        exit_code = hello_world_seed_job.run(http_client, data_dir)
    elif project_env == ProjectEnv.knoweng_instance():
        db_engine = _make_db_engine(project_env)
        data_dir = data_projects_dir + 'knoweng/'
        exit_code = knoweng_seed_job.run(http_client, db_engine, data_dir,
                                         subsample, flavor_name)
    elif project_env == ProjectEnv.mmbdb_instance():
        data_dir = data_projects_dir + 'mmbdb/'
        db_engine = _make_db_engine(project_env)
        exit_code = mmbdb_seed_job.run(http_client, db_engine, data_dir,
                                       subsample, flavor_name)
        pass
    else:
        raise Exception("Project's seed job not implemented")
    return exit_code
예제 #3
0
def _perform_project_stages(project_env, project_root_dir):
    """
    performs the stages of an individual project: docker startup,
    seed_users, smoke_tests, docker teardown

    takes a ProjectEnv 
    Returns a list of stage_results (the objects returned
        by _perform_stage)
    """
    stage_results = list()
    project_name = project_env.get_project_name()
    stage_name = project_name + ' web_assets:dist'
    client_dist_stage = _perform_stage(stage_name, compile_ops._compile,
                                       project_root_dir, 'web_assets:dist',
                                       ProjectEnv.hello_world_instance(),
                                       RunLevel.development_instance())
    stage_results.append(client_dist_stage)

    stage_name = project_name + ' startup containers'
    startup_containers_stage = _perform_stage(stage_name,
                                              docker_ops._docker_action,
                                              'startup', 'all', project_env,
                                              RunLevel.development_instance(),
                                              NestSite.localhost_instance(),
                                              project_root_dir)
    stage_results.append(startup_containers_stage)

    stage_name = project_name + ' ensure db tables'
    db_tables_project_stage = _perform_stage(stage_name, db_ops._run_db_action,
                                             'ensure_tables', project_env,
                                             NestSite.localhost_instance())
    stage_results.append(db_tables_project_stage)

    stage_name = project_name + ' seed_users'
    seed_users_project_stage = _perform_stage(
        stage_name, seed_users_ops._run_seed_users_script, project_env,
        RunLevel.development_instance())
    stage_results.append(seed_users_project_stage)

    stage_name = project_name + ' smoke_test'
    smoke_project_stage = _perform_stage(stage_name,
                                         smoke_test_ops._run_smoke_test,
                                         project_env,
                                         NestSite.localhost_instance())
    stage_results.append(smoke_project_stage)

    stage_name = project_name + ' teardown containers'
    teardown_containers_stage = _perform_stage(stage_name,
                                               docker_ops._docker_action,
                                               'teardown', 'all', project_env,
                                               RunLevel.development_instance(),
                                               NestSite.localhost_instance(),
                                               project_root_dir)
    stage_results.append(teardown_containers_stage)

    return stage_results
예제 #4
0
def prep_db():
    """
    test_users has methods to point the nest_users clients to a
    different table so that any existing user entries aren't disturbed
    on the local postgres instance. We also seed the hello_world project
    users into the testing table.
    """
    test_users.setup_db()
    runlevel = RunLevel.development_instance()
    project_env = ProjectEnv.hello_world_instance()
    db_ops_utils.seed_users(project_env, runlevel)
    return
예제 #5
0
def run_project_scripts(project_env, http_client):
    """
    runs the smoke test for the current project.
    """
    if project_env == ProjectEnv.hello_world_instance():
        smoke_res = hw_api_clients.run_all_smoke_tests(http_client)
    elif project_env == ProjectEnv.knoweng_instance():
        smoke_res = knoweng_api_clients.run_all_smoke_tests(http_client)
    elif project_env == ProjectEnv.mmbdb_instance():
        smoke_res = omix_api_clients.run_all_smoke_tests(http_client)
    else:
        raise Exception("Project smoke scripts not implemented")
    return smoke_res
예제 #6
0
def _generate_project_params(project_env, runlevel):
    if project_env == ProjectEnv.hello_world_instance():
        import nest_py.hello_world.hw_config as hw_config
        project_params = hw_config.generate_project_params(runlevel)
    elif project_env == ProjectEnv.knoweng_instance():
        import nest_py.knoweng.knoweng_config as knoweng_config
        project_params = knoweng_config.generate_project_params(runlevel)
    elif project_env == ProjectEnv.mmbdb_instance():
        import nest_py.omix.omix_config as omix_config
        project_params = omix_config.generate_project_params(runlevel)
    else:
        raise Exception("Unsupported project env: " + str(project_env))
    return project_params
예제 #7
0
def generate_db_config(project_env=None, runlevel=None):
    if project_env is None:
        project_env = ProjectEnv.hello_world_instance()
    if runlevel is None:
        runlevel = RunLevel.development_instance()
    config = {
        "user":os.getenv('POSTGRES_USERNAME', "nest"),
        "port": os.getenv('POSTGRES_PORT', 5432), #exported in docker startup
        "password":os.getenv('POSTGRES_PASSWORD', "GARBAGESECRET"),
        "db_name":os.getenv('POSTGRES_DATABASE', "nest"),
        #"verbose_logging":True
        "verbose_logging":False
    }
    host = os.getenv('POSTGRES_HOST', NestSite.localhost_instance().get_server_ip_address())
    config['host'] = host
    return config
예제 #8
0
def _run_wipe(project_env, target_site):
    """
    runs a seeding job. logs the final result and returns
    a 0/1 exit code based on whether all walkthroughs worked.
    """
    http_client = target_site.build_http_client()
    jobs_auth.login_jobs_user(http_client)

    if project_env == ProjectEnv.hello_world_instance():
        cms = hw_api_clients.get_api_client_makers()
    elif project_env == ProjectEnv.knoweng_instance():
        # TODO add option to govern handling of user data
        cms = knoweng_api_clients.get_api_client_makers()
    elif project_env == ProjectEnv.mmbdb_instance():
        cms = omix_api_clients.get_api_client_makers()
    else:
        raise Exception("Project's wipe job not implemented")
    exit_code = wipe_by_api_clients(cms, http_client)
    return exit_code
예제 #9
0
def build_and_test(project_root_dir):
    """
    run all compilation and unit tests
    """

    stage_results = list()

    log("START ci_ops.BUILD_AND_TEST")

    py_compile_stage = _perform_stage('python compilation    ',
                                      compile_ops._compile, project_root_dir,
                                      'python', ProjectEnv.default_instance(),
                                      RunLevel.development_instance())
    stage_results.append(py_compile_stage)

    js_compile_stage = _perform_stage('web_assets compilation',
                                      compile_ops._compile, project_root_dir,
                                      'web_assets',
                                      ProjectEnv.hello_world_instance(),
                                      RunLevel.development_instance())
    stage_results.append(js_compile_stage)

    build_containers_stage = _perform_stage('build containers      ',
                                            docker_ops._docker_action, 'build',
                                            'all',
                                            ProjectEnv.hello_world_instance(),
                                            RunLevel.development_instance(),
                                            NestSite.localhost_instance(),
                                            project_root_dir)
    stage_results.append(build_containers_stage)

    #run pytests and clienttests against the hello_world_app containers
    startup_containers_stage = _perform_stage(
        'startup containers    ', docker_ops._docker_action, 'startup', 'all',
        ProjectEnv.hello_world_instance(), RunLevel.development_instance(),
        NestSite.localhost_instance(), project_root_dir)
    stage_results.append(startup_containers_stage)

    clienttest_stage = _perform_stage('clienttest            ',
                                      clienttest_ops._run_unit_test,
                                      project_root_dir)
    stage_results.append(clienttest_stage)

    pytest_stage = _perform_stage('pytest tests/unit/    ',
                                  pytest_ops._run_unit_test, project_root_dir,
                                  True)
    stage_results.append(pytest_stage)

    teardown_containers_stage = _perform_stage(
        'teardown containers   ', docker_ops._docker_action, 'teardown', 'all',
        ProjectEnv.hello_world_instance(), RunLevel.development_instance(),
        NestSite.localhost_instance(), project_root_dir)
    stage_results.append(teardown_containers_stage)

    #test the lifecycle and smoke scripts of all projects
    project_names = nest_envs.VALID_PROJECT_NAMES
    for project_name in project_names:
        project_env = ProjectEnv(project_name)
        project_stage_results = _perform_project_stages(
            project_env, project_root_dir)
        stage_results += project_stage_results

    exit_code = _finalize_build(stage_results)
    log("BUILD_AND_TESTS returning exit_code: " + str(exit_code))
    return exit_code
예제 #10
0
def test_hello_world_seed_users():
    project_env = ProjectEnv.hello_world_instance()
    _test_seed_users_for_project(project_env)
    return