def start_nebula(nb, configs): if configs.address is not None and configs.address != "": print('test remote nebula graph, address is {}'.format( configs.address)) if len(configs.address.split(':')) != 2: raise Exception('Invalid address, address is {}'.format( configs.address)) address, port = configs.address.split(':') ports = [int(port)] else: nb.install() address = "localhost" debug = opt_is(configs.debug, "true") ports = nb.start(debug_log=debug, multi_graphd=configs.multi_graphd) # Load csv data pool = get_conn_pool("localhost", ports[0]) sess = pool.get_session(configs.user, configs.password) if not os.path.exists(TMP_DIR): os.mkdir(TMP_DIR) with open(SPACE_TMP_PATH, "w") as f: spaces = [] for space in ("nba", "nba_int_vid", "student"): data_dir = os.path.join(CURR_PATH, "data", space) space_desc = load_csv_data(sess, data_dir, space) spaces.append(space_desc.__dict__) f.write(json.dumps(spaces)) with open(NB_TMP_PATH, "w") as f: data = {"ip": "localhost", "port": ports, "work_dir": nb.work_dir} f.write(json.dumps(data)) print('Start nebula successfully')
def load_csv_data_once( tmp_path_factory, pytestconfig, worker_id, conn_pool: ConnectionPool, space: str, ): root_tmp_dir = tmp_path_factory.getbasetemp().parent fn = root_tmp_dir / f"csv-data-{space}" is_file = True with FileLock(str(fn) + ".lock"): if not fn.is_file(): data_dir = os.path.join(CURR_PATH, "data", space) user = pytestconfig.getoption("user") password = pytestconfig.getoption("password") sess = conn_pool.get_session(user, password) space_desc = load_csv_data(pytestconfig, sess, data_dir) sess.release() fn.write_text(json.dumps(space_desc.__dict__)) is_file = False else: space_desc = SpaceDesc.from_json(json.loads(fn.read_text())) if is_file: logging.info(f"session-{worker_id} need not to load {space} csv data") yield space_desc else: logging.info(f"session-{worker_id} load {space} csv data") yield space_desc os.remove(str(fn))
def import_csv_data(request, data, graph_spaces, session, pytestconfig): data_dir = os.path.join(DATA_DIR, normalize_outline_scenario(request, data)) space_desc = load_csv_data( session, data_dir, "I" + space_generator(), ) assert space_desc is not None graph_spaces["space_desc"] = space_desc graph_spaces["drop_space"] = True
def import_csv_data(data, graph_spaces, session, pytestconfig): data_dir = os.path.join(DATA_DIR, data) space_desc = load_csv_data( pytestconfig, session, data_dir, "I" + space_generator(), ) assert space_desc is not None graph_spaces["space_desc"] = space_desc graph_spaces["drop_space"] = True
def start_standalone(nb, configs): if configs.address is not None and configs.address != "": print('test remote nebula graph, address is {}'.format( configs.address)) if len(configs.address.split(':')) != 2: raise Exception('Invalid address, address is {}'.format( configs.address)) address, port = configs.address.split(':') ports = [int(port)] else: print('Start standalone version') nb.install_standalone() address = "localhost" ports = nb.start_standalone() is_graph_ssl = opt_is(configs.enable_ssl, "true") or opt_is( configs.enable_graph_ssl, "true") ca_signed = opt_is(configs.enable_ssl, "true") # Load csv data pool = get_conn_pool(address, ports[0], get_ssl_config(is_graph_ssl, ca_signed)) sess = pool.get_session(configs.user, configs.password) if not os.path.exists(TMP_DIR): os.mkdir(TMP_DIR) with open(SPACE_TMP_PATH, "w") as f: spaces = [] folder = os.path.join(CURR_PATH, "data") for space in os.listdir(folder): if not os.path.exists(os.path.join(folder, space, "config.yaml")): continue data_dir = os.path.join(folder, space) space_desc = load_csv_data(sess, data_dir, space) spaces.append(space_desc.__dict__) f.write(json.dumps(spaces)) with open(NB_TMP_PATH, "w") as f: data = { "ip": "localhost", "port": ports, "work_dir": nb.work_dir, "enable_ssl": configs.enable_ssl, "enable_graph_ssl": configs.enable_graph_ssl, "ca_signed": configs.ca_signed, } f.write(json.dumps(data)) print('Start standalone successfully')
def start_nebula(nb, configs): nb.install() port = nb.start() # Load csv data pool = get_conn_pool("localhost", port) sess = pool.get_session(configs.user, configs.password) if not os.path.exists(TMP_DIR): os.mkdir(TMP_DIR) with open(SPACE_TMP_PATH, "w") as f: spaces = [] for space in ("nba", "nba_int_vid", "student"): data_dir = os.path.join(CURR_PATH, "data", space) space_desc = load_csv_data(sess, data_dir, space) spaces.append(space_desc.__dict__) f.write(json.dumps(spaces)) with open(NB_TMP_PATH, "w") as f: data = {"ip": "localhost", "port": port, "work_dir": nb.work_dir} f.write(json.dumps(data))