From d7fd925bceb0349322860f99c736237c6bc0e3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Thu, 2 Jan 2025 11:47:55 +0100 Subject: [PATCH 01/17] Tezt/Cloud/DAL: Ensure consistency between Agent names --- tezt/tests/cloud/dal.ml | 84 ++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 97e30fbd9253..8d4d4e5c370d 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 @@ -2115,7 +2113,7 @@ let init ~(configuration : configuration) etherlink_configuration cloud let* producers_agents = configuration.dal_node_producers |> List.mapi (fun i slot_index -> - let name = Format.asprintf "producer-%d" i in + let name = Format.asprintf "dal-producer-%d" i in let* name = next_agent ~name in return (name, slot_index)) |> Lwt.all @@ -2123,7 +2121,7 @@ let init ~(configuration : configuration) etherlink_configuration cloud let* observers_slot_index_agents = List.map (fun i -> - let name = Format.asprintf "observer-%d" i in + let name = Format.asprintf "dal-observer-%d" i in let* agent = next_agent ~name in return (`Slot_index i, agent)) configuration.observer_slot_indices @@ -2132,7 +2130,7 @@ let init ~(configuration : configuration) etherlink_configuration cloud let* observers_bakers_agents = List.map (fun pkh -> - let name = Format.asprintf "observer-%s" pkh in + let name = Format.asprintf "observer-%s" (String.sub pkh 0 8) in let* agent = next_agent ~name in return (`Pkh pkh, agent)) configuration.observer_pkhs @@ -2560,26 +2558,41 @@ 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 @@ -2587,11 +2600,27 @@ let benchmark () = Option.map (fun tag -> Configuration.Octez_release {tag}) Cli.octez_release in let default_vm_configuration = Configuration.make ?docker_image () in + (* To be used in the next commit. *) + let _names_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 -> ( + | Bootstrap -> default_vm_configuration + | Baker i -> ( match configuration.stake_machine_type with | None -> default_vm_configuration | Some list -> ( @@ -2599,14 +2628,15 @@ let benchmark () = 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 -> ( + | Producer _ | Observer _ | Etherlink_dal_operator + | Etherlink_dal_observer _ -> ( match configuration.producer_machine_type with | None -> Configuration.make ?docker_image () | Some machine_type -> Configuration.make ?docker_image ~machine_type ()) - | `Etherlink_operator -> default_vm_configuration - | `Etherlink_producer _ -> default_vm_configuration - | `Reverse_proxy -> default_vm_configuration) + | Etherlink_operator -> default_vm_configuration + | Etherlink_producer _ -> default_vm_configuration + | Reverse_proxy -> default_vm_configuration) 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. *) -- GitLab From fc8e516a7149fa88f61e1de7b206449894558126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Thu, 2 Jan 2025 12:02:19 +0100 Subject: [PATCH 02/17] Tezt/Cloud: Add a name to an agent configuration --- tezt/lib_cloud/agent.ml | 17 ++++++++++++----- tezt/lib_cloud/configuration.ml | 12 ++++++++++-- tezt/lib_cloud/configuration.mli | 2 ++ tezt/lib_cloud/tezt_cloud.mli | 8 +++++++- tezt/lib_cloud/web.ml | 5 ++++- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index cbd88ccf79db..31e10875f192 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -44,11 +44,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) diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml index 962482edf70a..fffc4e80cab4 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-%3d" !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 2c1699c1be28..8c1ee15aaa0a 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/tezt_cloud.mli b/tezt/lib_cloud/tezt_cloud.mli index 5975aabef9ec..61057610f2e9 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 not 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 diff --git a/tezt/lib_cloud/web.ml b/tezt/lib_cloud/web.ml index 8ddfbcc89766..90d2c7be7ff3 100644 --- a/tezt/lib_cloud/web.ml +++ b/tezt/lib_cloud/web.ml @@ -55,11 +55,14 @@ 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 [ + (* This will simplified in a future commit. *) + ("configuration_vm_name", Tstr name); ("name", Tstr (Agent.name agent)); ("machine_type", Tstr machine_type); ("docker_image", Tstr (Format.asprintf "%a" pp_docker_image docker_image)); -- GitLab From f6dbb078d345df41f33d2e2640da098b257ad52b Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Thu, 9 Jan 2025 15:25:44 +0100 Subject: [PATCH 03/17] Tezt/cloud: fix typo --- tezt/lib_cloud/tezt_cloud.mli | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/lib_cloud/tezt_cloud.mli b/tezt/lib_cloud/tezt_cloud.mli index 61057610f2e9..981cbee28e41 100644 --- a/tezt/lib_cloud/tezt_cloud.mli +++ b/tezt/lib_cloud/tezt_cloud.mli @@ -34,7 +34,7 @@ module Configuration : sig 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 not check so if you override the ?name + 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 -> @@ -93,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, ...). -- GitLab From 4a59c5fb72ba2e86751a953d73b108c35539a56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Thu, 2 Jan 2025 12:51:56 +0100 Subject: [PATCH 04/17] Tezt/Cloud/DAL: Provide agent name before deployment --- tezt/tests/cloud/dal.ml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 8d4d4e5c370d..e8360b8b3ceb 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -2599,9 +2599,10 @@ let benchmark () = let docker_image = Option.map (fun tag -> Configuration.Octez_release {tag}) Cli.octez_release in - let default_vm_configuration = Configuration.make ?docker_image () in - (* To be used in the next commit. *) - let _names_of = function + 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 @@ -2618,25 +2619,27 @@ let benchmark () = in let vms = vms - |> List.map (function - | Bootstrap -> default_vm_configuration + |> 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)) + 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 () | Some machine_type -> Configuration.make ?docker_image ~machine_type ()) - | Etherlink_operator -> default_vm_configuration - | Etherlink_producer _ -> default_vm_configuration - | Reverse_proxy -> default_vm_configuration) + | 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. *) -- GitLab From aec9c765e9c19a437b7180db17252716e4ec226d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Thu, 2 Jan 2025 12:57:25 +0100 Subject: [PATCH 05/17] Tezt/Cloud: Remove the `Agent.set_agent` function --- tezt/lib_cloud/agent.ml | 6 +----- tezt/lib_cloud/agent.mli | 3 --- tezt/lib_cloud/cloud.ml | 7 ------- tezt/lib_cloud/cloud.mli | 2 -- tezt/lib_cloud/tezt_cloud.mli | 4 ---- tezt/tests/cloud/dal.ml | 18 ++---------------- 6 files changed, 3 insertions(+), 37 deletions(-) diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index 31e10875f192..6ea3de6b0d37 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -9,7 +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; + name : string; vm_name : string; zone : string option; point : (string * int) option; @@ -112,10 +112,6 @@ let runner {runner; _} = runner let configuration {configuration; _} = configuration -(* Setters *) - -let set_name agent name = agent.name <- name - let make ?zone ?ssh_id ?point ~configuration ~next_available_port ~name () = let ssh_user = "root" in let runner = diff --git a/tezt/lib_cloud/agent.mli b/tezt/lib_cloud/agent.mli index a5debf3a986c..05364b96442e 100644 --- a/tezt/lib_cloud/agent.mli +++ b/tezt/lib_cloud/agent.mli @@ -47,9 +47,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 2d877580497c..43154691da9e 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -617,13 +617,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 c71cdcba94cb..a1ec1c9942f3 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/tezt_cloud.mli b/tezt/lib_cloud/tezt_cloud.mli index 981cbee28e41..54df7634d7a9 100644 --- a/tezt/lib_cloud/tezt_cloud.mli +++ b/tezt/lib_cloud/tezt_cloud.mli @@ -156,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/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index e8360b8b3ceb..be85ea506c1a 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -2693,22 +2693,8 @@ 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 = + List.find (fun agent -> Agent.name agent = name) agents |> Lwt.return in let* t = init ~configuration etherlink_configuration cloud next_agent in toplog "Starting main loop" ; -- GitLab From 42d5adaac0d8491c0d9bd19f3f2f5ae369c1127c Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Wed, 8 Jan 2025 18:27:01 +0100 Subject: [PATCH 06/17] Tezt/Cloud: fix inconsistent naming of agents --- tezt/tests/cloud/dal.ml | 40 ++++++++++++++++++++++------------------ tezt/tests/dal.ml | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index be85ea506c1a..0885128bd4d9 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -2105,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 "dal-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 "dal-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" (String.sub pkh 0 8) 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 = @@ -2694,7 +2693,12 @@ let benchmark () = is probably a configuration issue." ; let agents = Cloud.agents cloud in let next_agent ~name = - List.find (fun agent -> Agent.name agent = name) agents |> Lwt.return + 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/dal.ml b/tezt/tests/dal.ml index 5ecb503d01b7..eae0be78f259 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 -- GitLab From 16961f5ab7735aa3d986c0f8bc0b057e80534fae Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Wed, 8 Jan 2025 18:38:54 +0100 Subject: [PATCH 07/17] Tezt/Cloud: fix agent name for localhost containers --- tezt/lib_cloud/deployement.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index 292bb30fb996..c221dea7247f 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -357,14 +357,13 @@ module Localhost = struct 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.name ()) in Lwt.return -- GitLab From 2203cb2c2e4050a728dcd14b39ebae0f07ca3c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Thu, 2 Jan 2025 14:07:46 +0100 Subject: [PATCH 08/17] Tezt/Cloud: Remove unecessary duplication --- tezt/lib_cloud/agent.ml | 36 ++++++++---------------------------- tezt/lib_cloud/agent.mli | 6 ++---- tezt/lib_cloud/cloud.ml | 5 ++--- tezt/lib_cloud/web.ml | 4 +--- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index 6ea3de6b0d37..a856792e1bd7 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -10,7 +10,6 @@ open Types type t = { (* The name initially is the same as [vm_name] and can be changed dynamically by the scenario. *) name : string; - vm_name : string; zone : string option; point : (string * int) option; runner : Runner.t option; @@ -64,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 () -> @@ -89,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) @@ -102,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 () @@ -122,17 +110,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 -> @@ -141,7 +121,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 05364b96442e..48a917c3d419 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 diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index 43154691da9e..c426b6f98925 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -589,10 +589,9 @@ 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 default_agent = diff --git a/tezt/lib_cloud/web.ml b/tezt/lib_cloud/web.ml index 90d2c7be7ff3..fd84d56c9dc2 100644 --- a/tezt/lib_cloud/web.ml +++ b/tezt/lib_cloud/web.ml @@ -61,9 +61,7 @@ let agent_jingo_template agent = in Tobj [ - (* This will simplified in a future commit. *) - ("configuration_vm_name", Tstr name); - ("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", -- GitLab From cdc49e8b4e3eb31c60fd5116da63f4ced86c323e Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Wed, 8 Jan 2025 17:33:54 +0100 Subject: [PATCH 09/17] Tezt/Cloud: use Proxy.get_agent to avoid duplication --- tezt/lib_cloud/cloud.ml | 16 ++-------------- tezt/lib_cloud/proxy.ml | 11 +++++------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index c426b6f98925..759d5f1a9aa6 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 diff --git a/tezt/lib_cloud/proxy.ml b/tezt/lib_cloud/proxy.ml index d274675e034c..3208e2a9ecc1 100644 --- a/tezt/lib_cloud/proxy.ml +++ b/tezt/lib_cloud/proxy.ml @@ -5,13 +5,12 @@ (* *) (*****************************************************************************) -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 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. *) -- GitLab From 1c803fd3d8445a6b2c8d9c7f2bd8611f45cbf555 Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Wed, 8 Jan 2025 17:47:50 +0100 Subject: [PATCH 10/17] Tezt/cloud: fixes proxy agent name --- tezt/lib_cloud/deployement.ml | 2 +- tezt/lib_cloud/proxy.ml | 2 ++ tezt/lib_cloud/proxy.mli | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index c221dea7247f..3c900a1c8ac9 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -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 = diff --git a/tezt/lib_cloud/proxy.ml b/tezt/lib_cloud/proxy.ml index 3208e2a9ecc1..6cbbce56c09d 100644 --- a/tezt/lib_cloud/proxy.ml +++ b/tezt/lib_cloud/proxy.ml @@ -7,6 +7,8 @@ let agent_name = Format.asprintf "%s-proxy" Env.tezt_cloud +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 diff --git a/tezt/lib_cloud/proxy.mli b/tezt/lib_cloud/proxy.mli index ce6a3ba220e0..0aa0c9b8e7ce 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]. *) -- GitLab From bba6b3c16a0e1283c90eb36e9100f237bd17967d Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Wed, 8 Jan 2025 17:48:30 +0100 Subject: [PATCH 11/17] Tezt/Cloud: avoid creating names with spaces --- tezt/lib_cloud/configuration.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml index fffc4e80cab4..103a28bcf303 100644 --- a/tezt/lib_cloud/configuration.ml +++ b/tezt/lib_cloud/configuration.ml @@ -20,7 +20,7 @@ let gen_name = let cpt = ref (-1) in fun () -> incr cpt ; - Format.asprintf "agent-%3d" !cpt + Format.asprintf "agent-%03d" !cpt let make ?os ?binaries_path ?max_run_duration ?machine_type ?docker_image ?(name = gen_name ()) () = -- GitLab From fbfbf782b964e5c790f7ece4be817a9b15ab4d39 Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Thu, 9 Jan 2025 11:00:42 +0100 Subject: [PATCH 12/17] Tezt/Cloud: fix missing agent names --- tezt/tests/cloud/dal.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 0885128bd4d9..6a9a38aa18e3 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -2633,9 +2633,9 @@ let benchmark () = | 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 ()) + 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) -- GitLab From 449203a142090ddedc91194c940f33d9c5a1d887 Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Thu, 9 Jan 2025 11:02:24 +0100 Subject: [PATCH 13/17] Tezt/Cloud: also change local docker container names --- tezt/lib_cloud/deployement.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index 3c900a1c8ac9..f3c6db8322f7 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -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 @@ -389,8 +392,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 -- GitLab From e97e7a1e52d8ad51240751d49339cba1697365ac Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Thu, 9 Jan 2025 13:57:21 +0100 Subject: [PATCH 14/17] Tezt/Cloud: fixes naming of remaining agents in vm 0 mode --- tezt/lib_cloud/cloud.ml | 10 ++++++---- tezt/lib_cloud/deployement.ml | 2 +- tezt/tests/cloud/layer1.ml | 15 +++------------ 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index 759d5f1a9aa6..b7b891f4e6e1 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -502,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 @@ -582,15 +583,16 @@ let agents t = 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] diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index f3c6db8322f7..adefc8788150 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 diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index cc8174f6d79d..90bb92c4150d 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -947,19 +947,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" ; -- GitLab From 94990950940f618579295adf574263d719c2daff Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Mon, 13 Jan 2025 14:41:19 +0100 Subject: [PATCH 15/17] Tezt/Cloud: fix port/address allocation --- tezt/lib_cloud/deployement.ml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index adefc8788150..c3328290271a 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -315,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" @@ -323,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) @@ -331,24 +331,25 @@ 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* () = - 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 + 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 + let addr = Hashtbl.find addresses_table 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 = -- GitLab From c832c941bad80386447d1b552b33e11da7d363db Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Mon, 13 Jan 2025 15:38:32 +0100 Subject: [PATCH 16/17] Tezt/Cloud: adds sanity check function for container name --- tezt/lib_cloud/agent.ml | 7 +++++++ tezt/lib_cloud/deployement.ml | 15 ++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index a856792e1bd7..40c3fad1d38d 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -100,8 +100,15 @@ let runner {runner; _} = runner let configuration {configuration; _} = configuration +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 diff --git a/tezt/lib_cloud/deployement.ml b/tezt/lib_cloud/deployement.ml index c3328290271a..5a95ef8fa534 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -332,20 +332,17 @@ module Localhost = struct could be more robust to handle that. *) let* () = Lwt_unix.sleep 5. in let addresses_table = Hashtbl.create number_of_vms in + let ports_table = Hashtbl.create number_of_vms in let* () = 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_table 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 @@ -353,8 +350,8 @@ module Localhost = struct (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 @@ -367,7 +364,7 @@ module Localhost = struct ~point ~configuration ~next_available_port:(fun () -> next_port point) - ~name:configuration.name + ~name:configuration.Configuration.name ()) in Lwt.return -- GitLab From cd42283c05445cfefd16b356b1f53cef690d698c Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Mon, 13 Jan 2025 16:24:38 +0100 Subject: [PATCH 17/17] Tezt/Cloud: avoid duplicate names in tezt layer1 --- tezt/tests/cloud/layer1.ml | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index 90bb92c4150d..e4b4712b00c2 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)) -- GitLab