예제 #1
0
def conn_pool(pytestconfig, worker_id, tmp_path_factory):
    addr = pytestconfig.getoption("address")
    if addr:
        addrsplit = addr.split(":")
        assert len(addrsplit) == 2
        pool = get_conn_pool(addrsplit[0], addrsplit[1])
        yield pool
        pool.close()
        return

    build_dir = pytestconfig.getoption("build_dir")
    rm_dir = pytestconfig.getoption("rm_dir")
    project_dir = os.path.dirname(CURR_PATH)

    root_tmp_dir = tmp_path_factory.getbasetemp().parent
    fn = root_tmp_dir / "nebula-test"
    nb = None
    with FileLock(str(fn) + ".lock"):
        if fn.is_file():
            data = json.loads(fn.read_text())
            port = data["port"]
            logging.info(f"session-{worker_id} read the port: {port}")
            pool = get_conn_pool("localhost", port)
            data["num_workers"] += 1
            fn.write_text(json.dumps(data))
        else:
            nb = NebulaService(build_dir, project_dir,
                               rm_dir.lower() == "true")
            nb.install()
            port = nb.start()
            pool = get_conn_pool("localhost", port)
            data = dict(port=port, num_workers=1, finished=0)
            fn.write_text(json.dumps(data))
            logging.info(f"session-{worker_id} write the port: {port}")

    yield pool
    pool.close()

    if nb is None:
        with FileLock(str(fn) + ".lock"):
            data = json.loads(fn.read_text())
            data["finished"] += 1
            fn.write_text(json.dumps(data))
    else:
        # TODO(yee): improve this option format, only specify it by `--stop_nebula`
        stop_nebula = pytestconfig.getoption("stop_nebula")
        while stop_nebula.lower() == "true":
            data = json.loads(fn.read_text())
            if data["finished"] + 1 == data["num_workers"]:
                nb.stop()
                break
            time.sleep(1)
        os.remove(str(fn))
예제 #2
0
def given_nebulacluster_with_param(
    request,
    params,
    graphd_num,
    metad_num,
    storaged_num,
    class_fixture_variables,
    pytestconfig,
):
    graphd_param, metad_param, storaged_param = {}, {}, {}
    if params is not None:
        for param in params.splitlines():
            module, config = param.strip().split(":")
            assert module.lower() in ["graphd", "storaged", "metad"]
            key, value = config.strip().split("=")
            if module.lower() == "graphd":
                graphd_param[key] = value
            elif module.lower() == "storaged":
                storaged_param[key] = value
            else:
                metad_param[key] = value

    user = pytestconfig.getoption("user")
    password = pytestconfig.getoption("password")
    build_dir = pytestconfig.getoption("build_dir")
    src_dir = pytestconfig.getoption("src_dir")
    nebula_svc = NebulaService(
        build_dir,
        src_dir,
        int(metad_num),
        int(storaged_num),
        int(graphd_num),
    )
    for process in nebula_svc.graphd_processes:
        process.update_param(graphd_param)
    for process in nebula_svc.storaged_processes:
        process.update_param(storaged_param)
    for process in nebula_svc.metad_processes:
        process.update_param(metad_param)
    work_dir = os.path.join(
        build_dir,
        "C" + space_generator() +
        time.strftime('%Y-%m-%dT%H-%M-%S', time.localtime()),
    )
    nebula_svc.install(work_dir)
    nebula_svc.start()
    graph_ip = nebula_svc.graphd_processes[0].host
    graph_port = nebula_svc.graphd_processes[0].tcp_port
    # TODO add ssl pool if tests needed
    pool = get_conn_pool(graph_ip, graph_port, None)
    sess = pool.get_session(user, password)
    class_fixture_variables["current_session"] = sess
    class_fixture_variables["sessions"].append(sess)
    class_fixture_variables["cluster"] = nebula_svc
    class_fixture_variables["pool"] = pool
예제 #3
0
        data = json.loads(f.readline())
        nb.set_work_dir(data["work_dir"])
    nb.stop()
    shutil.rmtree(TMP_DIR, ignore_errors=True)
    print('nebula services have been stopped.')


def opt_is(val, expect):
    return type(val) == str and val.lower() == expect


if __name__ == "__main__":
    try:
        parser = init_parser()
        (configs, opts) = parser.parse_args()

        # Setup nebula graph service
        cleanup = opt_is(configs.rm_dir, "true")
        nebula_svc = NebulaService(configs.build_dir, NEBULA_HOME, cleanup)

        if opt_is(configs.cmd, "start"):
            start_nebula(nebula_svc, configs)
        elif opt_is(configs.cmd, "stop"):
            stop_nebula(nebula_svc)
        else:
            raise ValueError(f"Invalid parser args: {configs.cmd}")
    except Exception as x:
        print('\033[31m' + str(x) + '\033[0m')
        import traceback
        print(traceback.format_exc())
예제 #4
0
        try:
            error_code = pytest.main(args)
        except Exception:
            sys.stderr.write(
                "Unexpected exception with pytest {0}".format(args))
            error_code = 1
        return error_code


if __name__ == "__main__":
    # If the user is just asking for --help, just print the help test and then exit.
    executor = TestExecutor()
    if '-h' in sys.argv[1:] or '--help' in sys.argv[1:]:
        executor.run_tests(sys.argv[1:])
        sys.exit(0)
    nebula_svc = NebulaService(NEBULA_BUILD_DIR, NEBULA_SOURCE_DIR)
    stop_nebula = True
    error_code = 1
    configs = None
    try:
        # Init args
        parser = init_configs()
        (configs, opts) = parser.parse_args()

        # Create the test result directory if it doesn't already exist.
        if not os.path.exists(RESULT_DIR):
            os.makedirs(RESULT_DIR)

        commandline_args = itertools.chain(
            *[arg.split('=') for arg in sys.argv[1:]])
        current_time = strftime("%Y-%m-%d-%H:%M:%S", localtime())
예제 #5
0
    shutil.rmtree(TMP_DIR, ignore_errors=True)
    print('nebula services have been stopped.')


if __name__ == "__main__":
    try:
        parser = init_parser()
        (configs, opts) = parser.parse_args()

        # Setup nebula graph service
        nebula_svc = NebulaService(
            configs.build_dir,
            NEBULA_HOME,
            graphd_num=2,
            storaged_num=1,
            debug_log=opt_is(configs.debug, "true"),
            ca_signed=opt_is(configs.ca_signed, "true"),
            enable_ssl=configs.enable_ssl,
            enable_graph_ssl=configs.enable_graph_ssl,
            enable_meta_ssl=configs.enable_meta_ssl,
            containerized=configs.containerized,
        )

        if opt_is(configs.cmd, "start"):
            start_nebula(nebula_svc, configs)
        elif opt_is(configs.cmd, "stop"):
            stop_nebula(nebula_svc, configs)
        else:
            raise ValueError(f"Invalid parser args: {configs.cmd}")
    except Exception as x:
        print('\033[31m' + str(x) + '\033[0m')
        import traceback