Beispiel #1
0
def get_ssl_config_from_tmp():
    with open(NB_TMP_PATH, "r") as f:
        data = json.loads(f.readline())
        is_graph_ssl = (data.get("enable_ssl", "false").upper() == "TRUE"
                        or data.get("enable_graph_ssl",
                                    "false").upper() == "TRUE")
        ca_signed = data.get("ca_signed", "false").upper() == "TRUE"
        return get_ssl_config(is_graph_ssl, ca_signed)
Beispiel #2
0
    def start_standalone(self):
        os.chdir(self.work_dir)
        start_time = time.time()
        for p in self.all_processes:
            print('start stand alone process')
            p.start()

        config = Config()
        config.max_connection_pool_size = 20
        config.timeout = 60000
        # init connection pool
        client_pool = ConnectionPool()
        # assert client_pool.init([("127.0.0.1", int(self.graphd_port))], config)
        ssl_config = get_ssl_config(self.is_graph_ssl, self.ca_signed)
        print("begin to add hosts")
        ok = False
        # wait graph is ready, and then add hosts
        for _ in range(20):
            try:
                ok = client_pool.init(
                    [("127.0.0.1", self.graphd_processes[0].tcp_port)],
                    config,
                    ssl_config,
                )
                if ok:
                    break
            except:
                pass
            time.sleep(1)

        assert ok, "graph is not ready"
        # get session from the pool
        client = client_pool.get_session('root', 'nebula')

        hosts = ",".join([
            "127.0.0.1:{}".format(str(storaged.storage_port))
            for storaged in self.graphd_processes
        ])
        cmd = "ADD HOSTS {}".format(hosts)
        print("add hosts cmd is {}".format(cmd))
        resp = client.execute(cmd)
        assert resp.is_succeeded(), resp.error_msg()
        client.release()

        # wait nebula start
        server_ports = [p.tcp_port for p in self.all_processes]
        if not self._check_servers_status(server_ports):
            self._collect_pids()
            self.kill_all(signal.SIGKILL)
            elapse = time.time() - start_time
            raise Exception(f'nebula servers not ready in {elapse}s')

        self._collect_pids()

        return [p.tcp_port for p in self.graphd_processes]
Beispiel #3
0
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')