From 7cb4e86de8a53edc5e288e1abb9f565d188f15c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois?= Date: Thu, 28 Nov 2024 12:01:58 +0100 Subject: [PATCH] Sync with release 2.5, allow many nodes to run locally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jean-François --- massa_test_framework/compile.py | 6 - .../k8s/massa_cluster_manager.py | 10 +- massa_test_framework/node.py | 108 +++++++++--------- 3 files changed, 61 insertions(+), 63 deletions(-) diff --git a/massa_test_framework/compile.py b/massa_test_framework/compile.py index 40109a0..d3fd4f8 100644 --- a/massa_test_framework/compile.py +++ b/massa_test_framework/compile.py @@ -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"), } ) diff --git a/massa_test_framework/k8s/massa_cluster_manager.py b/massa_test_framework/k8s/massa_cluster_manager.py index 5c83842..c69d779 100644 --- a/massa_test_framework/k8s/massa_cluster_manager.py +++ b/massa_test_framework/k8s/massa_cluster_manager.py @@ -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 simulator@massa.net" cluster_config = MassaClusterConfig( @@ -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 @@ -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}") @@ -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 @@ -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 diff --git a/massa_test_framework/node.py b/massa_test_framework/node.py index 4597f7c..56d38a1 100644 --- a/massa_test_framework/node.py +++ b/massa_test_framework/node.py @@ -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 @@ -38,6 +38,8 @@ # third party import requests import tomlkit +from tomlkit.toml_document import TOMLDocument + class Node: @@ -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_") @@ -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) @@ -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: @@ -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):