diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index cbd88ccf79db96b5b650756f46c09ee1ea5c8181..40c3fad1d38d86274c60d93f477b5c930f871a83 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -9,8 +9,7 @@ open Types type t = { (* The name initially is the same as [vm_name] and can be changed dynamically by the scenario. *) - mutable name : string; - vm_name : string; + name : string; zone : string option; point : (string * int) option; runner : Runner.t option; @@ -44,11 +43,18 @@ let configuration_encoding = let open Data_encoding in let open Configuration in conv - (fun {machine_type; binaries_path; docker_image; max_run_duration = _; os} -> - (machine_type, binaries_path, docker_image, os)) - (fun (machine_type, binaries_path, docker_image, os) -> - make ~os ~machine_type ~binaries_path ~docker_image ()) - (obj4 + (fun { + name; + machine_type; + binaries_path; + docker_image; + max_run_duration = _; + os; + } -> (name, machine_type, binaries_path, docker_image, os)) + (fun (name, machine_type, binaries_path, docker_image, os) -> + make ~os ~machine_type ~binaries_path ~docker_image ~name ()) + (obj5 + (req "name" string) (req "machine_type" string) (req "binaries_path" string) (req "docker_image" docker_image_encoding) @@ -57,17 +63,9 @@ let configuration_encoding = let encoding = let open Data_encoding in conv - (fun { - name; - vm_name; - zone; - point; - runner = _; - next_available_port; - configuration; - } -> - (name, vm_name, zone, point, next_available_port (), configuration)) - (fun (name, vm_name, zone, point, next_available_port, configuration) -> + (fun {name; zone; point; runner = _; next_available_port; configuration} -> + (name, zone, point, next_available_port (), configuration)) + (fun (name, zone, point, next_available_port, configuration) -> let next_available_port = let current_port = ref (next_available_port - 1) in fun () -> @@ -82,10 +80,9 @@ let encoding = Runner.create ~ssh_user:"root" ~ssh_id ~ssh_port ~address () |> Option.some in - {name; vm_name; zone; point; runner; next_available_port; configuration}) - (obj6 + {name; zone; point; runner; next_available_port; configuration}) + (obj5 (req "name" string) - (req "vm_name" string) (req "zone" (option string)) (req "point" (option (tup2 string int31))) (req "next_available_port" int31) @@ -95,8 +92,6 @@ let encoding = let name {name; _} = name -let vm_name {vm_name; _} = vm_name - let point {point; _} = point let next_available_port t = t.next_available_port () @@ -105,12 +100,15 @@ let runner {runner; _} = runner let configuration {configuration; _} = configuration -(* Setters *) - -let set_name agent name = agent.name <- name +let names_table = Hashtbl.create 3 let make ?zone ?ssh_id ?point ~configuration ~next_available_port ~name () = let ssh_user = "root" in + let () = + match Hashtbl.find_opt names_table name with + | None -> Hashtbl.add names_table name () + | Some () -> Test.fail "Duplicate agent name: %s" name + in let runner = match (point, ssh_id) with | None, None -> None @@ -119,17 +117,9 @@ let make ?zone ?ssh_id ?point ~configuration ~next_available_port ~name () = | Some (address, ssh_port), Some ssh_id -> Runner.create ~ssh_user ~ssh_id ~ssh_port ~address () |> Option.some in - { - point; - runner; - name; - vm_name = name; - next_available_port; - configuration; - zone; - } + {point; runner; name; next_available_port; configuration; zone} -let cmd_wrapper {zone; vm_name; _} = +let cmd_wrapper {zone; name; _} = match zone with | None -> None | Some zone -> @@ -138,7 +128,7 @@ let cmd_wrapper {zone; vm_name; _} = Env.ssh_private_key_filename ~home:"$HOME" () else Env.ssh_private_key_filename () in - Some (Gcloud.cmd_wrapper ~zone ~vm_name ~ssh_private_key_filename) + Some (Gcloud.cmd_wrapper ~zone ~vm_name:name ~ssh_private_key_filename) let path_of agent binary = agent.configuration.binaries_path // binary diff --git a/tezt/lib_cloud/agent.mli b/tezt/lib_cloud/agent.mli index a5debf3a986cd6ede0f7b92c208d95ae0445ea97..48a917c3d4190e41b403fd1c10c39c007f2ba7e6 100644 --- a/tezt/lib_cloud/agent.mli +++ b/tezt/lib_cloud/agent.mli @@ -28,12 +28,10 @@ val make : (** Encode an agent configuration. *) val encoding : t Data_encoding.t -(** [name agent] returns the name of the agent. *) +(** [name agent] returns the name of the agent. This is the same as + the name provided in the agent configuration. *) val name : t -> string -(** [vm_name agent] returns the vm name of the agent. *) -val vm_name : t -> string - (** [point agent] returns the point asociated with the agent. *) val point : t -> (string * int) option @@ -47,9 +45,6 @@ val runner : t -> Runner.t option (** [configuration t] the configuration of the agent. *) val configuration : t -> Configuration.t -(** [set_name agent name] sets the name of the agent to [name]. *) -val set_name : t -> string -> unit - (** A wrapper to run a command on the VM of the agent. *) val cmd_wrapper : t -> Gcloud.cmd_wrapper option diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index 2d877580497ca893bc9ac9718e386052e067cf0d..b7b891f4e6e151f7cb6615802c2a073853d10ddc 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -325,14 +325,7 @@ let try_reattach () = |> Deployement.of_agents in let agents = Deployement.agents deployement in - let proxy_agent = - agents - |> List.find (fun agent -> - let proxy_agent_prefix = - Format.asprintf "%s-proxy" Env.tezt_cloud - in - String.starts_with ~prefix:proxy_agent_prefix (Agent.name agent)) - in + let proxy_agent = Proxy.get_agent agents in let* is_ssh_server_running = Lwt.pick [ @@ -373,12 +366,7 @@ let try_reattach () = let init_proxy ?(proxy_files = []) ?(proxy_args = []) deployement = let agents = Deployement.agents deployement in - let proxy_agent = - agents - |> List.find (fun agent -> - let proxy_agent_prefix = Format.asprintf "%s-proxy" Env.tezt_cloud in - String.starts_with ~prefix:proxy_agent_prefix (Agent.name agent)) - in + let proxy_agent = Proxy.get_agent agents in let* () = wait_ssh_server_running proxy_agent in let destination = (Agent.configuration proxy_agent).binaries_path @@ -514,14 +502,15 @@ let register ?proxy_files ?proxy_args ?vms ~__FILE__ ~title ~tags ?seed ?alerts match vms with | None -> let default_agent = + let configuration = Configuration.make () in Agent.make - ~configuration:(Configuration.make ()) + ~configuration ~next_available_port: (let cpt = ref 30_000 in fun () -> incr cpt ; !cpt) - ~name:"default agent" + ~name:configuration.name () in f @@ -589,21 +578,21 @@ let agents t = match Env.mode with | `Orchestrator -> ( let proxy_agent = Proxy.get_agent t.agents in - let proxy_vm_name = Agent.vm_name proxy_agent in + let proxy_name = Agent.name proxy_agent in match - t.agents - |> List.filter (fun agent -> Agent.vm_name agent <> proxy_vm_name) + t.agents |> List.filter (fun agent -> Agent.name agent <> proxy_name) with | [] -> + let configuration = Configuration.make () in let default_agent = Agent.make - ~configuration:(Configuration.make ()) + ~configuration ~next_available_port: (let cpt = ref 30_000 in fun () -> incr cpt ; !cpt) - ~name:"default agent" + ~name:configuration.name () in [default_agent] @@ -617,13 +606,6 @@ let write_website t = | None -> Lwt.return_unit | Some website -> Web.write website ~agents:t.agents -let set_agent_name t agent name = - Agent.set_name agent name ; - let* () = write_website t in - match t.prometheus with - | None -> Lwt.return_unit - | Some prometheus -> Prometheus.reload prometheus - let push_metric t ?help ?typ ?labels ~name value = match t.website with | None -> () diff --git a/tezt/lib_cloud/cloud.mli b/tezt/lib_cloud/cloud.mli index c71cdcba94cb5d6b82e9c306510460e7b7c3e16c..a1ec1c9942f3cafc2ebf0d2ba3572f4ed55e48b1 100644 --- a/tezt/lib_cloud/cloud.mli +++ b/tezt/lib_cloud/cloud.mli @@ -37,8 +37,6 @@ val push_metric : val write_website : t -> unit Lwt.t -val set_agent_name : t -> Agent.t -> string -> unit Lwt.t - type target = {agent : Agent.t; port : int; app_name : string} val add_prometheus_source : diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml index 962482edf70a71e4e7c213d8f98371ec9f0c7ab5..103a28bcf303da59b8e7f6af00fda9c1bb6ba4b3 100644 --- a/tezt/lib_cloud/configuration.ml +++ b/tezt/lib_cloud/configuration.ml @@ -8,6 +8,7 @@ include Types type t = { + name : string; machine_type : string; docker_image : Env.docker_image; max_run_duration : int option; @@ -15,7 +16,14 @@ type t = { os : Os.t; } -let make ?os ?binaries_path ?max_run_duration ?machine_type ?docker_image () = +let gen_name = + let cpt = ref (-1) in + fun () -> + incr cpt ; + Format.asprintf "agent-%03d" !cpt + +let make ?os ?binaries_path ?max_run_duration ?machine_type ?docker_image + ?(name = gen_name ()) () = let os = Option.value ~default:Os.default os in let docker_image = Option.value ~default:Env.docker_image docker_image in let machine_type = Option.value ~default:Env.machine_type machine_type in @@ -33,4 +41,4 @@ let make ?os ?binaries_path ?max_run_duration ?machine_type ?docker_image () = if Env.no_max_run_duration then None else Some Env.max_run_duration | Some max_run_duration -> Some max_run_duration in - {os; machine_type; docker_image; max_run_duration; binaries_path} + {os; machine_type; docker_image; max_run_duration; binaries_path; name} diff --git a/tezt/lib_cloud/configuration.mli b/tezt/lib_cloud/configuration.mli index 2c1699c1be28c4b30440da04f68fb903da94af6b..8c1ee15aaa0a50ce0703fc6eda8c55e07db15873 100644 --- a/tezt/lib_cloud/configuration.mli +++ b/tezt/lib_cloud/configuration.mli @@ -6,6 +6,7 @@ (*****************************************************************************) type t = private { + name : string; machine_type : string; docker_image : Env.docker_image; max_run_duration : int option; @@ -19,5 +20,6 @@ val make : ?max_run_duration:int -> ?machine_type:string -> ?docker_image:Env.docker_image -> + ?name:string -> unit -> t diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index 292bb30fb996faf4431c54606bfd80cae3f1143d..5a95ef8fa534b616c5c7d0f79bd8555cb3a9410c 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -104,7 +104,7 @@ module Remote = struct ~point ~configuration ~next_available_port - ~name:vm_name + ~name:configuration.name () |> Lwt.return in @@ -130,7 +130,7 @@ module Remote = struct let deploy_proxy () = let workspace_name = Format.asprintf "%s-proxy" Env.tezt_cloud in - let configuration = Configuration.make () in + let configuration = Proxy.make_config () in let tezt_cloud = Env.tezt_cloud in let* () = Terraform.VM.Workspace.init ~tezt_cloud [workspace_name] in let* agents = @@ -265,7 +265,11 @@ module Localhost = struct agents : Agent.t list; } - let vm_name i = Format.asprintf "%s-%03d" Env.tezt_cloud (i + 1) + let container_name configuration = + Format.asprintf + "teztcloud-%s-%s" + Env.tezt_cloud + configuration.Configuration.name let macosx_docker_network = Env.tezt_cloud ^ "-net" @@ -285,7 +289,6 @@ module Localhost = struct let* processes = List.to_seq configurations |> Seq.mapi (fun i configuration -> - let name = vm_name i in let start = base_port + (i * ports_per_vm) |> string_of_int in let stop = base_port + ((i + 1) * ports_per_vm) - 1 |> string_of_int @@ -303,7 +306,7 @@ module Localhost = struct let process = Docker.run ~rm:true - ~name + ~name:(container_name configuration) ?network ~publish_ports docker_image @@ -312,7 +315,7 @@ module Localhost = struct Lwt.return process) |> List.of_seq |> Lwt.all in - let address i = + let address configuration = let* output = Process.run_and_read_stdout "docker" @@ -320,7 +323,7 @@ module Localhost = struct "inspect"; "-f"; "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"; - vm_name i; + container_name configuration; ] in Lwt.return (String.trim output) @@ -328,43 +331,40 @@ module Localhost = struct (* We need to wait a little the machine is up. As for the remote case, we could be more robust to handle that. *) let* () = Lwt_unix.sleep 5. in - let addresses = Hashtbl.create number_of_vms in + let addresses_table = Hashtbl.create number_of_vms in + let ports_table = Hashtbl.create number_of_vms in let* () = - List.init number_of_vms Fun.id - |> Lwt_list.iter_s (fun i -> - let* addr = address i in - Hashtbl.replace addresses i addr ; - Lwt.return_unit) + Lwt_list.iteri_s + (fun i configuration -> + let* addr = address configuration in + let () = Hashtbl.replace addresses_table i addr in + let port = base_port + (i * ports_per_vm) in + let () = Hashtbl.replace ports_table (addr, port) (port + 1) in + Lwt.return_unit) + configurations in - let next_port = Hashtbl.create number_of_vms in - Seq.ints 0 |> Seq.take number_of_vms - |> Seq.iter (fun i -> - let port = base_port + (i * ports_per_vm) in - let addr = Hashtbl.find addresses i in - Hashtbl.replace next_port (addr, port) (port + 1)) ; let ssh_id = Env.ssh_private_key_filename () in let get_point i = let port = base_port + (i * ports_per_vm) in - let addr = Hashtbl.find addresses i in + let addr = Hashtbl.find addresses_table i in (addr, port) in let next_port point = - let port = Hashtbl.find next_port point in - Hashtbl.replace next_port point (port + 1) ; + let port = Hashtbl.find ports_table point in + Hashtbl.replace ports_table point (port + 1) ; port in let* () = if Env.monitoring then Monitoring.run () else Lwt.return_unit in let agents = configurations |> List.mapi (fun i configuration -> - let name = Format.asprintf "localhost_docker_%d" i in let point = get_point i in Agent.make ~ssh_id ~point ~configuration ~next_available_port:(fun () -> next_port point) - ~name + ~name:configuration.Configuration.name ()) in Lwt.return @@ -390,8 +390,11 @@ module Localhost = struct Log.report "Terminate test: tearing down docker containers..." ; let* () = t.agents - |> List.mapi (fun i _agent -> - let* _ = Docker.kill (vm_name i) |> Process.wait in + |> List.map (fun agent -> + let* _ = + Docker.kill (container_name (Agent.configuration agent)) + |> Process.wait + in Lwt.return_unit) |> Lwt.join in diff --git a/tezt/lib_cloud/proxy.ml b/tezt/lib_cloud/proxy.ml index d274675e034ce5b4448a92f7383e509966461cbd..6cbbce56c09d07debb329270d4033260ec5b9a3a 100644 --- a/tezt/lib_cloud/proxy.ml +++ b/tezt/lib_cloud/proxy.ml @@ -5,13 +5,14 @@ (* *) (*****************************************************************************) -let find_agent agents = - let proxy_agent_prefix = Format.asprintf "%s-proxy" Env.tezt_cloud in - agents - |> List.find_opt (fun agent -> - String.starts_with ~prefix:proxy_agent_prefix (Agent.name agent)) +let agent_name = Format.asprintf "%s-proxy" Env.tezt_cloud -let get_agent agents = find_agent agents |> Option.get +let make_config () = Configuration.make ~name:agent_name () + +let get_agent agents = + match List.find_opt (fun agent -> Agent.name agent = agent_name) agents with + | None -> Test.fail ~__LOC__ "Cannot find agent %s" agent_name + | Some agent -> agent let copy_files proxy_agent ~scenario_files ~proxy_deployement = (* This file is necessary to get the agents configurations. *) diff --git a/tezt/lib_cloud/proxy.mli b/tezt/lib_cloud/proxy.mli index ce6a3ba220e000c91dc7701bc3e0c7e770203db7..0aa0c9b8e7ceefd5a517e918db2e097abf033c17 100644 --- a/tezt/lib_cloud/proxy.mli +++ b/tezt/lib_cloud/proxy.mli @@ -5,6 +5,9 @@ (* *) (*****************************************************************************) +(** Create a configuration for the proxy *) +val make_config : unit -> Configuration.t + (** [get_agent agents] returns the proxy agent. It raises [Not_found] if the proxy agent was not found. This function should be safe to call when [Env.mode] is [`Orchestrator] or [`Host]. *) diff --git a/tezt/lib_cloud/tezt_cloud.mli b/tezt/lib_cloud/tezt_cloud.mli index 5975aabef9ec069792d7982924bf9a74c0513dfc..54df7634d7a90be4eae128296a59b57a82b9b20f 100644 --- a/tezt/lib_cloud/tezt_cloud.mli +++ b/tezt/lib_cloud/tezt_cloud.mli @@ -14,6 +14,7 @@ module Configuration : sig | Octez_release of {tag : string} type t = private { + name : string; machine_type : string; docker_image : docker_image; max_run_duration : int option; @@ -30,13 +31,18 @@ module Configuration : sig Default value for [docker_image] is [Custom {tezt_cloud}] where [tezt_cloud] is the value provided by the environement variable [$TEZT_CLOUD]. - *) + + Default value for [name] is ["agent-x"] where [x] is a counter + which is incremented every time this function is used with a + default name (there is no check so if you override the ?name + field with "agent-x", two agents can have the same name). *) val make : ?os:Types.Os.t -> ?binaries_path:string -> ?max_run_duration:int -> ?machine_type:string -> ?docker_image:docker_image -> + ?name:string -> unit -> t end @@ -87,7 +93,7 @@ module Alert : sig (** [make ?route ?for_ ?description ?summary ?severity ~name ~expr] defines a new Prometheus alert with name [name] and promQL [expr]. Optionally a severity, summary and description of the - alert can be defined. + alert can be defined. If [route] is provided, the alert can be routed to a receiver (Slack, webhook, ...). @@ -150,10 +156,6 @@ module Cloud : sig (** [agents t] returns the list of agents deployed. *) val agents : t -> Agent.t list - (** [set_agent_name t agent name] sets the name of the agent [agent] to - [name]. *) - val set_agent_name : t -> Agent.t -> string -> unit Lwt.t - type target = {agent : Agent.t; port : int; app_name : string} (** [add_prometheus_source t ?metrics_path ~name targets] allows to add a new diff --git a/tezt/lib_cloud/web.ml b/tezt/lib_cloud/web.ml index 8ddfbcc89766bd81d3fff58c6fc66fae4271c44c..fd84d56c9dc21fd88b1856e0bd9bd6e5fd21ffe0 100644 --- a/tezt/lib_cloud/web.ml +++ b/tezt/lib_cloud/web.ml @@ -55,12 +55,13 @@ let string_vm_command agent = let agent_jingo_template agent = let open Jingoo.Jg_types in let Configuration. - {machine_type; docker_image; max_run_duration; binaries_path; os} = + {machine_type; docker_image; max_run_duration; binaries_path; os; name} + = Agent.configuration agent in Tobj [ - ("name", Tstr (Agent.name agent)); + ("name", Tstr name); ("machine_type", Tstr machine_type); ("docker_image", Tstr (Format.asprintf "%a" pp_docker_image docker_image)); ( "max_run_duration", diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 97e30fbd925372c396f3ddd24f37035416186df8..6a9a38aa18e3521170c4460e65aee82531d8f16a 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -1673,8 +1673,8 @@ let init_observer cloud configuration ~bootstrap teztale ~topic i agent = in Lwt.return {node; dal_node; topic} -let init_etherlink_dal_node ~bootstrap ~next_agent ~name ~dal_slots ~network - ~otel ~memtrace = +let init_etherlink_dal_node ~bootstrap ~next_agent ~dal_slots ~network ~otel + ~memtrace = match dal_slots with | [] -> toplog "Etherlink will run without DAL support" ; @@ -1684,7 +1684,7 @@ let init_etherlink_dal_node ~bootstrap ~next_agent ~name ~dal_slots ~network this index on a dedicated VM and give it directly as endpoint to the rollup node. *) toplog "Etherlink sequencer will run its own DAL node" ; - let name = Format.asprintf "etherlink-%s-dal-operator" name in + let name = Format.asprintf "etherlink-dal-operator" in let* agent = next_agent ~name in let* node = Node.init @@ -1717,8 +1717,7 @@ let init_etherlink_dal_node ~bootstrap ~next_agent ~name ~dal_slots ~network Format.pp_print_int) dal_slots ; toplog "Etherlink sequencer will use a reverse proxy" ; - - let name = Format.asprintf "etherlink-%s-dal-operator" name in + let name = Format.asprintf "etherlink-dal-operator" in let* agent = next_agent ~name in let* node = Node.init @@ -1742,7 +1741,7 @@ let init_etherlink_dal_node ~bootstrap ~next_agent ~name ~dal_slots ~network dal_slots |> Lwt_list.map_p (fun slot_index -> let name = - Format.asprintf "etherlink-%s-dal-operator-%d" name slot_index + Format.asprintf "etherlink-dal-operator-%d" slot_index in let* agent = next_agent ~name in let* node = @@ -1827,7 +1826,6 @@ let init_etherlink_operator_setup cloud configuration etherlink_configuration init_etherlink_dal_node ~bootstrap ~next_agent - ~name ~dal_slots:etherlink_configuration.etherlink_dal_slots ~network:configuration.network ~otel @@ -2016,7 +2014,7 @@ let init_etherlink_producer_setup cloud operator name account ~bootstrap agent = let init_etherlink cloud configuration etherlink_configuration ~bootstrap etherlink_rollup_operator_key ~dal_slots next_agent = let () = toplog "Initializing an Etherlink operator" in - let* operator_agent = next_agent ~name:"etherlink-operator-agent" in + let* operator_agent = next_agent ~name:"etherlink-operator" in let* operator = init_etherlink_operator_setup cloud @@ -2107,35 +2105,34 @@ let init ~(configuration : configuration) etherlink_configuration cloud else Lwt.return_none in let* attesters_agents = - List.init (List.length configuration.stake) (fun i -> - let name = Format.asprintf "attester-%d" i in - next_agent ~name) + configuration.stake + |> List.map (fun stake -> + let name = Format.asprintf "attester-%d" stake in + next_agent ~name) |> Lwt.all in let* producers_agents = configuration.dal_node_producers - |> List.mapi (fun i slot_index -> - let name = Format.asprintf "producer-%d" i in + |> List.map (fun slot_index -> + let name = Format.asprintf "dal-producer-%d" slot_index in let* name = next_agent ~name in return (name, slot_index)) |> Lwt.all in let* observers_slot_index_agents = - List.map - (fun i -> - let name = Format.asprintf "observer-%d" i in - let* agent = next_agent ~name in - return (`Slot_index i, agent)) - configuration.observer_slot_indices + configuration.observer_slot_indices + |> List.map (fun slot_index -> + let name = Format.asprintf "dal-observer-%d" slot_index in + let* agent = next_agent ~name in + return (`Slot_index slot_index, agent)) |> Lwt.all in let* observers_bakers_agents = - List.map - (fun pkh -> - let name = Format.asprintf "observer-%s" pkh in - let* agent = next_agent ~name in - return (`Pkh pkh, agent)) - configuration.observer_pkhs + configuration.observer_pkhs + |> List.map (fun pkh -> + let name = Format.asprintf "observer-%s" (String.sub pkh 0 8) in + let* agent = next_agent ~name in + return (`Pkh pkh, agent)) |> Lwt.all in let* teztale = @@ -2560,53 +2557,88 @@ let configuration, etherlink_configuration = in (t, etherlink) +type agent_kind = + | Bootstrap + | Baker of int + | Producer of int + | Observer of [`Index of int | `Pkh of string] + | Reverse_proxy + | Etherlink_operator + | Etherlink_dal_operator + | Etherlink_dal_observer of {slot_index : int} + | Etherlink_producer of int + let benchmark () = toplog "Parsing CLI done" ; let vms = [ - (if configuration.bootstrap then [`Bootstrap] else []); - List.map (fun i -> `Baker i) configuration.stake; - List.map (fun _ -> `Producer) configuration.dal_node_producers; - List.map (fun _ -> `Observer) configuration.observer_slot_indices; - List.map (fun _ -> `Observer_pkh) configuration.observer_pkhs; - (if etherlink_configuration <> None then [`Etherlink_operator] else []); + (if configuration.bootstrap then [Bootstrap] else []); + List.map (fun i -> Baker i) configuration.stake; + List.map (fun i -> Producer i) configuration.dal_node_producers; + List.map + (fun index -> Observer (`Index index)) + configuration.observer_slot_indices; + List.map (fun pkh -> Observer (`Pkh pkh)) configuration.observer_pkhs; + (if etherlink_configuration <> None then [Etherlink_operator] else []); (match etherlink_configuration with | None | Some {etherlink_dal_slots = []; _} -> [] - | Some {etherlink_dal_slots = [_]; _} -> [`Etherlink_dal_node] + | Some {etherlink_dal_slots = [_]; _} -> [Etherlink_dal_operator] | Some {etherlink_dal_slots; _} -> - `Reverse_proxy - :: List.map (fun _ -> `Etherlink_dal_node) etherlink_dal_slots); + Reverse_proxy :: Etherlink_dal_operator + :: List.map + (fun slot_index -> Etherlink_dal_observer {slot_index}) + etherlink_dal_slots); (match etherlink_configuration with | None -> [] | Some {etherlink_producers; _} -> - List.init etherlink_producers (fun i -> `Etherlink_producer i)); + List.init etherlink_producers (fun i -> Etherlink_producer i)); ] |> List.concat in let docker_image = Option.map (fun tag -> Configuration.Octez_release {tag}) Cli.octez_release in - let default_vm_configuration = Configuration.make ?docker_image () in + let default_vm_configuration ~name = + Configuration.make ?docker_image ~name () + in + let name_of = function + | Bootstrap -> "bootstrap" + | Baker i -> Format.asprintf "attester-%d" i + | Producer i -> Format.asprintf "dal-producer-%d" i + | Observer (`Index i) -> Format.asprintf "dal-observer-%d" i + | Observer (`Pkh pkh) -> + (* Shorting the pkh enables to get better logs. *) + Format.asprintf "dal-observer-%s" (String.sub pkh 0 8) + | Reverse_proxy -> "dal-reverse-proxy" + | Etherlink_operator -> "etherlink-operator" + | Etherlink_dal_operator -> Format.asprintf "etherlink-dal-operator" + | Etherlink_dal_observer {slot_index} -> + Format.asprintf "etherlink-dal-observer-%d" slot_index + | Etherlink_producer i -> Format.asprintf "etherlink-producer-%d" i + in let vms = vms - |> List.map (function - | `Bootstrap -> default_vm_configuration - | `Baker i -> ( + |> List.map (fun agent_kind -> + let name = name_of agent_kind in + match agent_kind with + | Bootstrap -> default_vm_configuration ~name + | Baker i -> ( match configuration.stake_machine_type with - | None -> default_vm_configuration + | None -> default_vm_configuration ~name | Some list -> ( try let machine_type = List.nth list i in - Configuration.make ?docker_image ~machine_type () - with _ -> default_vm_configuration)) - | `Producer | `Observer | `Observer_pkh | `Etherlink_dal_node -> ( + Configuration.make ?docker_image ~machine_type ~name () + with _ -> default_vm_configuration ~name)) + | Producer _ | Observer _ | Etherlink_dal_operator + | Etherlink_dal_observer _ -> ( match configuration.producer_machine_type with - | None -> Configuration.make ?docker_image () + | None -> Configuration.make ?docker_image ~name () | Some machine_type -> - Configuration.make ?docker_image ~machine_type ()) - | `Etherlink_operator -> default_vm_configuration - | `Etherlink_producer _ -> default_vm_configuration - | `Reverse_proxy -> default_vm_configuration) + Configuration.make ?docker_image ~machine_type ~name ()) + | Etherlink_operator -> default_vm_configuration ~name + | Etherlink_producer _ -> default_vm_configuration ~name + | Reverse_proxy -> default_vm_configuration ~name) in Cloud.register (* docker images are pushed before executing the test in case binaries are modified locally. This way we always use the latest ones. *) @@ -2660,22 +2692,13 @@ let benchmark () = DAL deactivated for bakers. DAL network can't work properly. This \ is probably a configuration issue." ; let agents = Cloud.agents cloud in - (* We give to the [init] function a sequence of agents (and cycle if - they were all consumed). We set their name only if the number of - agents is the computed one. Otherwise, the user has mentioned - explicitely a reduced number of agents and it is not clear how to give - them proper names. *) - let set_name agent name = - if List.length agents = List.length vms then - Cloud.set_agent_name cloud agent name - else Lwt.return_unit - in - let next_agent = - let f = List.to_seq agents |> Seq.cycle |> Seq.to_dispenser in - fun ~name -> - let agent = f () |> Option.get in - let* () = set_name agent name in - Lwt.return agent + let next_agent ~name = + let agent = + match List.find_opt (fun agent -> Agent.name agent = name) agents with + | None -> Test.fail ~__LOC__ "Agent not found: %s" name + | Some agent -> agent + in + Lwt.return agent in let* t = init ~configuration etherlink_configuration cloud next_agent in toplog "Starting main loop" ; diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index cc8174f6d79d381cf2db5aaabd7121b2d49bf086..e4b4712b00c232adabe2e2f6310e9a9b9e827441 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -871,7 +871,7 @@ let benchmark () = :: (match configuration.stake with | [n] -> List.init n (fun i -> `Baker i) - | stake -> List.map (fun i -> `Baker i) stake) + | stake -> List.mapi (fun i _ -> `Baker i) stake) @ match configuration.stresstest with | None -> [] @@ -881,18 +881,18 @@ let benchmark () = | Some network -> nb_stresstester network tps | None -> tps / stresstest_max_tps_pre_node in - List.init n (fun _ -> `Stresstest) + List.init n (fun i -> `Stresstest i) in let default_docker_image = Option.map (fun tag -> Configuration.Octez_release {tag}) Scenarios_cli.octez_release in - let default_vm_configuration = - Configuration.make ?docker_image:default_docker_image () + let default_vm_configuration ~name = + Configuration.make ?docker_image:default_docker_image ~name () in - let make_vm_conf = function - | None -> default_vm_configuration + let make_vm_conf ~name = function + | None -> default_vm_configuration ~name | Some {machine_type; docker_image; max_run_duration; binaries_path; os} -> let docker_image = match docker_image with @@ -906,19 +906,21 @@ let benchmark () = ?max_run_duration ?binaries_path ?os + ~name () in let vms = vms - |> List.map (function + |> List.map (fun kind -> + match kind with | `Bootstrap -> - make_vm_conf + make_vm_conf ~name:"bootstrap" @@ Option.bind vms_conf (fun {bootstrap; _} -> bootstrap) - | `Stresstest -> - make_vm_conf + | `Stresstest j -> + make_vm_conf ~name:(Format.sprintf "stresstest-%d" j) @@ Option.bind vms_conf (fun {bootstrap; _} -> bootstrap) | `Baker i -> - make_vm_conf + make_vm_conf ~name:(Format.sprintf "baker-%d" i) @@ Option.bind vms_conf (function | {bakers = Some bakers; _} -> List.nth_opt bakers i | {bakers = None; _} -> None)) @@ -947,19 +949,10 @@ let benchmark () = toplog "Created %d agents" (List.length agents) ; (* We give to the [init] function a sequence of agents. We set their name only if the number of agents is the computed one. Otherwise, the user - has mentioned explicitely a reduced number of agents and it is not + has mentioned explicitly a reduced number of agents and it is not clear how to give them proper names. *) - let set_name agent name = - if List.length agents = List.length vms then - Cloud.set_agent_name cloud agent name - else Lwt.return_unit - in - let next_agent = - let next = List.to_seq agents |> Seq.to_dispenser in - fun ~name -> - let agent = next () |> Option.get in - let* () = set_name agent name in - Lwt.return agent + let next_agent ~name = + List.find (fun agent -> Agent.name agent = name) agents |> Lwt.return in let* t = init ~configuration cloud next_agent in toplog "Starting main loop" ; diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 5ecb503d01b78934bfe4e4d3752eab39fc2da123..eae0be78f259560db0620466fe865e1e48a0a280 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -5362,7 +5362,7 @@ module Amplification = struct (* Create and configure all nodes: a slot producer, an observer, and one attester per bootstrap baker. *) let make_attester index (account : Account.key) : attester Lwt.t = - let name = Printf.sprintf "attester%d" (index + 1) in + let name = Printf.sprintf "attester-%d" (index + 1) in let pkh = account.public_key_hash in let dal_node = Dal_node.create ~name ~node () in let* () = Dal_node.init_config ~attester_profiles:[pkh] ~peers dal_node in