Skip to content

Commit

Permalink
Sync with release 2.5, allow many nodes to run locally
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-François <[email protected]>
  • Loading branch information
bilboquet committed Nov 29, 2024
1 parent bc1ba33 commit 52d7fc0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 63 deletions.
6 changes: 0 additions & 6 deletions massa_test_framework/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,10 @@ class CompileOpts:
"deferred_credits.json": Path(
"massa-node/base_config/deferred_credits.json"
),
"bootstrap_whitelist.json": Path(
"massa-node/base_config/bootstrap_whitelist.json"
),
"node_privkey.key": Path("massa-node/config/node_privkey.key"),
"abi_gas_costs.json": Path(
"massa-node/base_config/gas_costs/abi_gas_costs.json"
),
"wasm_gas_costs.json": Path(
"massa-node/base_config/gas_costs/wasm_gas_costs.json"
),
"client/config.toml": Path("massa-client/base_config/config.toml"),
}
)
Expand Down
10 changes: 6 additions & 4 deletions massa_test_framework/k8s/massa_cluster_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if __name__ == "__main__":
# Example usage:
external_i_ps = ["10.4.3.2"]
ssh_authorized_keys = "ssh-ed25519 XXX_MY_SSH_KEY_XXX [email protected]"
cluster_config = MassaClusterConfig(
Expand All @@ -35,9 +35,9 @@
launch_infos = manager.launch(cluster_config)
# Iterate through the LaunchInfo objects
for launch_info in launch_infos:
print(f"Service Name: {launch_info.service_info.name},
print(f"Service Name: {launch_info.service_info.name},
Cluster IP: {launch_info.service_info.cluster_i_ps[0]}")
print(f"Service Namespace: {launch_info.service_info.namespace},
print(f"Service Namespace: {launch_info.service_info.namespace},
External IP: {launch_info.service_info.external_i_ps[0]}")
# Iterate through the ports of the service and print their details
Expand All @@ -50,7 +50,7 @@
# Print container ports
for container_port in launch_info.pod_info.container_ports:
print(f"Container Port Name: {container_port.name},
print(f"Container Port Name: {container_port.name},
Container Port Number: {container_port.container_port}")
print(f"Protocol: {container_port.protocol}")
Expand Down Expand Up @@ -181,6 +181,7 @@ def launch(self, cluster_config: MassaClusterConfig) -> list[LaunchInfo]:
pod_configs.append(pod_config)

# Wait for pods to start
print("Waiting for pods to start...")
time.sleep(cluster_config.startup_pods_timeout)

# Create all services after pods have started
Expand All @@ -201,6 +202,7 @@ def launch(self, cluster_config: MassaClusterConfig) -> list[LaunchInfo]:
self.manager.create_service(service_config)

# Wait for services to start
print("Waiting for services to start...")
time.sleep(cluster_config.startup_services_timeout)

# Assuming you have already imported the LaunchInfo class
Expand Down
108 changes: 55 additions & 53 deletions massa_test_framework/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from urllib.parse import urlparse

from typing import List, Dict, Optional, Callable, Union
from typing import Container, Generator, List, Dict, Optional, Callable, Union

import betterproto
from grpclib.client import Channel
Expand Down Expand Up @@ -38,6 +38,8 @@
# third party
import requests
import tomlkit
from tomlkit.toml_document import TOMLDocument



class Node:
Expand Down Expand Up @@ -76,53 +78,6 @@ def __init__(self, server: Server, compile_unit: CompileUnit):
}
# print(self.config_files)

with self.server.open(self.config_files["config.toml"], "r") as fp:
cfg = tomlkit.load(fp)

pub_api_port = urlparse("http://" + cfg["api"]["bind_public"]).port
priv_api_port = urlparse("http://" + cfg["api"]["bind_private"]).port
pub_grpc_port = urlparse("http://" + cfg["grpc"]["public"]["bind"]).port
priv_grpc_port = urlparse("http://" + cfg["grpc"]["private"]["bind"]).port

if (
not pub_api_port
or not priv_api_port
or not pub_grpc_port
or not priv_grpc_port
):
raise RuntimeError("Could not get api & grpc port from config")

if server.server_opts.massa:
massa_server_opts: MassaNodeOpts = server.server_opts.massa
self.pub_api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(
self.server.host, massa_server_opts.jsonrpc_public_port
)
)
print("pub_api2 url:", self.pub_api2.url)
self.priv_api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(
self.server.host, massa_server_opts.jsonrpc_private_port
)
)
self.grpc_host = self.server.host
self.pub_grpc_port = massa_server_opts.grpc_public_port
self.pub_grpc_url = "{}:{}".format(self.server.host, pub_grpc_port)
self.priv_grpc_port = massa_server_opts.grpc_private_port
self.priv_grpc_url = "{}:{}".format(self.server.host, priv_grpc_port)

else:
self.pub_api2: Api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(self.server.host, pub_api_port)
)
self.priv_api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(self.server.host, priv_api_port)
)
self.grpc_host = self.server.host
self.pub_grpc_port = pub_grpc_port
self.pub_grpc_url = "{}:{}".format(self.server.host, pub_grpc_port)
self.priv_grpc_port = priv_grpc_port
self.priv_grpc_url = "{}:{}".format(self.server.host, priv_grpc_port)

def _install(self) -> Path | RemotePath:
tmp_folder = self.server.mkdtemp(prefix="massa_")
Expand Down Expand Up @@ -204,6 +159,55 @@ def start(
stderr: where to log node standard error output (default to sys.stderr)
"""

with self.server.open(self.config_files["config.toml"], "r") as fp:
cfg = tomlkit.load(fp)

pub_api_port = urlparse("http://" + cfg["api"]["bind_public"]).port
priv_api_port = urlparse("http://" + cfg["api"]["bind_private"]).port
pub_grpc_port = urlparse("http://" + cfg["grpc"]["public"]["bind"]).port
priv_grpc_port = urlparse("http://" + cfg["grpc"]["private"]["bind"]).port

if (
not pub_api_port
or not priv_api_port
or not pub_grpc_port
or not priv_grpc_port
):
raise RuntimeError("Could not get api & grpc port from config")

if self.server.server_opts.massa:
massa_server_opts: MassaNodeOpts = self.server.server_opts.massa
self.pub_api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(
self.server.host, massa_server_opts.jsonrpc_public_port
)
)
print("pub_api2 url:", self.pub_api2.url)
self.priv_api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(
self.server.host, massa_server_opts.jsonrpc_private_port
)
)
self.grpc_host = self.server.host
self.pub_grpc_port = massa_server_opts.grpc_public_port
self.pub_grpc_url = "{}:{}".format(self.server.host, pub_grpc_port)
self.priv_grpc_port = massa_server_opts.grpc_private_port
self.priv_grpc_url = "{}:{}".format(self.server.host, priv_grpc_port)

else:
self.pub_api2: Api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(self.server.host, pub_api_port)
)
self.priv_api2 = massa_jsonrpc_api.Api2(
"http://{}:{}".format(self.server.host, priv_api_port)
)
self.grpc_host = self.server.host
self.pub_grpc_port = pub_grpc_port
self.pub_grpc_url = "{}:{}".format(self.server.host, pub_grpc_port)
self.priv_grpc_port = priv_grpc_port
self.priv_grpc_url = "{}:{}".format(self.server.host, priv_grpc_port)
print("pub_api2 url:", self.pub_api2.url)

cmd = " ".join(self.node_start_cmd)
if args:
args_joined = " ".join(args)
Expand Down Expand Up @@ -267,11 +271,12 @@ def stop(self, process):
# fp.close()

@contextmanager
def edit_config(self):
def edit_config(self) -> Generator[TOMLDocument, None, None]:
"""Edit config.toml (as a context manager). Must be called before start()"""
# print("Editing config", self.config_path)
fp = self.server.open(self.config_files["config.toml"], "r+")
fp = self.server.open(str(self.config_files["config.toml"]), "r+")
cfg = tomlkit.load(fp)

try:
yield cfg
finally:
Expand Down Expand Up @@ -335,9 +340,6 @@ def edit_node_privkey(self):
def edit_bootstrap_whitelist(self):
return self.edit_json(self.config_files["bootstrap_whitelist.json"])

def remove_bootstrap_whitelist(self):
return self.server.remove(self.config_files["bootstrap_whitelist.json"])

# API

def get_status(self):
Expand Down

0 comments on commit 52d7fc0

Please sign in to comment.