From d45d9c22e33a73d5c65a5141daea186fa42f0085 Mon Sep 17 00:00:00 2001 From: Guillaume Bau Date: Wed, 15 Jan 2025 19:18:04 +0100 Subject: [PATCH] Tezt/Cloud: Move the configuration into its own datatype --- tezt/lib_cloud/agent.ml | 88 ++++++++++++++++---------------- tezt/lib_cloud/agent.mli | 38 ++++++++++++++ tezt/lib_cloud/cli.ml | 4 +- tezt/lib_cloud/cloud.ml | 8 ++- tezt/lib_cloud/cloud.mli | 4 +- tezt/lib_cloud/configuration.ml | 46 ----------------- tezt/lib_cloud/configuration.mli | 26 ---------- tezt/lib_cloud/deployement.ml | 20 ++++---- tezt/lib_cloud/deployement.mli | 2 +- tezt/lib_cloud/env.ml | 18 ------- tezt/lib_cloud/env.mli | 9 ---- tezt/lib_cloud/jobs.ml | 4 +- tezt/lib_cloud/jobs.mli | 5 +- tezt/lib_cloud/proxy.ml | 4 +- tezt/lib_cloud/proxy.mli | 2 +- tezt/lib_cloud/tezt_cloud.ml | 5 -- tezt/lib_cloud/tezt_cloud.mli | 42 +-------------- tezt/lib_cloud/types.ml | 88 ++++++++++++++++++++++++++++++++ tezt/lib_cloud/types.mli | 36 +++++++++++++ tezt/lib_cloud/web.ml | 4 +- tezt/tests/cloud/basic.ml | 6 +-- tezt/tests/cloud/dal.ml | 19 ++++--- tezt/tests/cloud/layer1.ml | 10 ++-- 23 files changed, 256 insertions(+), 232 deletions(-) delete mode 100644 tezt/lib_cloud/configuration.ml delete mode 100644 tezt/lib_cloud/configuration.mli diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index c0d6c8937814..03f4c6a7cefb 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -5,7 +5,49 @@ (* *) (*****************************************************************************) -open Types +module Configuration = struct + include Types.Agent_configuration + + let uri_of_docker_image docker_image = + match (docker_image, Env.mode) with + | Types.Agent_configuration.Gcp {alias}, (`Cloud | `Host | `Orchestrator) -> + let* registry_uri = Env.registry_uri () in + Lwt.return (Format.asprintf "%s/%s" registry_uri alias) + | Gcp {alias}, `Localhost -> Lwt.return alias + | Octez_release _, (`Cloud | `Host | `Orchestrator) -> + let* registry_uri = Env.registry_uri () in + Lwt.return (Format.asprintf "%s/octez" registry_uri) + | Octez_release _, `Localhost -> Lwt.return "octez" + + 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:Cli.os os in + let binaries_path = Option.value ~default:Cli.binaries_path binaries_path in + let max_run_duration = + let default = + if Cli.no_max_run_duration then None else Some Cli.max_run_duration + in + Option.value ~default max_run_duration + in + let machine_type = Option.value ~default:Cli.machine_type machine_type in + let docker_image = + Option.value ~default:(Gcp {alias = Env.dockerfile_alias}) docker_image + in + make + ~os + ~binaries_path + ?max_run_duration + ~machine_type + ~docker_image + ~name + () +end type t = { (* The name initially is the same as [vm_name] and can be changed dynamically by the scenario. *) @@ -21,48 +63,6 @@ let ssh_id () = Env.ssh_private_key_filename () (* Encodings *) -let docker_image_encoding = - let open Data_encoding in - union - [ - case - ~title:"gcp" - Json_only - Data_encoding.(obj1 (req "gcp" string)) - (function Env.Gcp {alias} -> Some alias | _ -> None) - (fun alias -> Gcp {alias}); - case - ~title:"octez_release" - Json_only - Data_encoding.(obj1 (req "octez" string)) - (function Env.Octez_release {tag} -> Some tag | _ -> None) - (fun tag -> Octez_release {tag}); - ] - -let configuration_encoding = - let open Data_encoding in - let open Configuration in - conv - (fun { - name; - vm = - { - 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) - (req "os" Os.encoding)) - let encoding = let open Data_encoding in conv @@ -89,7 +89,7 @@ let encoding = (req "zone" (option string)) (req "point" (option (tup2 string int31))) (req "next_available_port" int31) - (req "configuration" configuration_encoding)) + (req "configuration" Configuration.encoding)) (* Getters *) diff --git a/tezt/lib_cloud/agent.mli b/tezt/lib_cloud/agent.mli index e4ab61ddd335..a75c370f9e35 100644 --- a/tezt/lib_cloud/agent.mli +++ b/tezt/lib_cloud/agent.mli @@ -10,6 +10,44 @@ (** Datatype for an agent *) type t +module Configuration : sig + type docker_image = + | Gcp of {alias : string} + | Octez_release of {tag : string} + + type vm = private { + machine_type : string; + docker_image : docker_image; + max_run_duration : int option; + binaries_path : string; + os : Types.Os.t; + } + + type t = {name : string; vm : vm} + + val uri_of_docker_image : docker_image -> string Lwt.t + + (** [make ?machine_type ()] is a smart-constructor to make a VM + configuration. + + Default value for [max_run_duration] is [7200]. + + Default value for [machine_type] is [n1-standard-2]. + + Default value for [docker_image] is [Custom {tezt_cloud}] where [tezt_cloud] + is the value provided by the environement variable [$TEZT_CLOUD]. + *) + val make : + ?os:Types.Os.t -> + ?binaries_path:string -> + ?max_run_duration:int option -> + ?machine_type:string -> + ?docker_image:docker_image -> + ?name:string -> + unit -> + t +end + (** [make ?zone ?ssh_id ?point ~configuration ~next_available_port ~name ()] creates an [agent] from the given parameters. [~next_available_port] should always provide an available port or raise [Not_found] otherwise. diff --git a/tezt/lib_cloud/cli.ml b/tezt/lib_cloud/cli.ml index 36e996f326c3..c5a4937c4059 100644 --- a/tezt/lib_cloud/cli.ml +++ b/tezt/lib_cloud/cli.ml @@ -168,7 +168,7 @@ let machine_type = ~description: "Can specify a GCP machine type (see \ https://cloud.google.com/compute/docs/general-purpose-machines#c3d_series)" - "n1-standard-2" + Types.Agent_configuration.default_gcp_machine_type let dockerfile_alias = Clap.optional_string @@ -318,4 +318,4 @@ let binaries_path = ~description: "Where to find binaries in the docker image by default (default is: \ '/tmp/tezt-runners')" - (Filename.get_temp_dir_name () // "tezt-runners") + Types.Agent_configuration.default_gcp_binaries_path diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index 61ca7c54faa1..34bc117f6360 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -502,7 +502,7 @@ let register ?proxy_files ?proxy_args ?vms ~__FILE__ ~title ~tags ?seed ?alerts match vms with | None -> let default_agent = - let configuration = Configuration.make () in + let configuration = Agent.Configuration.make ~name:"default" () in Agent.make ~configuration ~next_available_port: @@ -527,7 +527,7 @@ let register ?proxy_files ?proxy_args ?vms ~__FILE__ ~title ~tags ?seed ?alerts | Some configurations -> ( let sorted_names = configurations - |> List.map (fun Configuration.{name; _} -> name) + |> List.map (fun Agent.Configuration.{name; _} -> name) |> List.sort_uniq compare in if List.length sorted_names < List.length configurations then @@ -599,7 +599,7 @@ let agents t = t.agents |> List.filter (fun agent -> Agent.name agent <> proxy_name) with | [] -> - let configuration = Configuration.make () in + let configuration = Agent.Configuration.make () in let default_agent = Agent.make ~configuration @@ -615,8 +615,6 @@ let agents t = | agents -> agents) | `Host | `Cloud | `Localhost -> t.agents -let get_configuration = Agent.configuration - let write_website t = match t.website with | None -> Lwt.return_unit diff --git a/tezt/lib_cloud/cloud.mli b/tezt/lib_cloud/cloud.mli index a1ec1c9942f3..eac7eff9231c 100644 --- a/tezt/lib_cloud/cloud.mli +++ b/tezt/lib_cloud/cloud.mli @@ -13,7 +13,7 @@ type t val register : ?proxy_files:string list -> ?proxy_args:string list -> - ?vms:Configuration.t list -> + ?vms:Agent.Configuration.t list -> __FILE__:string -> title:string -> tags:string list -> @@ -24,8 +24,6 @@ val register : val agents : t -> Agent.t list -val get_configuration : Agent.t -> Configuration.t - val push_metric : t -> ?help:string -> diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml deleted file mode 100644 index 00deb067d683..000000000000 --- a/tezt/lib_cloud/configuration.ml +++ /dev/null @@ -1,46 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) -(* *) -(*****************************************************************************) - -include Types - -type vm = { - machine_type : string; - docker_image : Env.docker_image; - max_run_duration : int option; - binaries_path : string; - os : Os.t; -} - -type t = {name : string; vm : vm} - -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 - let default_binaries_path = - match docker_image with - | Env.Gcp _ -> Env.binaries_path - | Octez_release _ -> "/usr/local/bin" - in - let binaries_path = - Option.value ~default:default_binaries_path binaries_path - in - let max_run_duration = - match max_run_duration with - | None -> - if Env.no_max_run_duration then None else Some Env.max_run_duration - | Some max_run_duration -> Some max_run_duration - in - let vm = {machine_type; docker_image; max_run_duration; binaries_path; os} in - {name; vm} diff --git a/tezt/lib_cloud/configuration.mli b/tezt/lib_cloud/configuration.mli deleted file mode 100644 index 84dc624a053a..000000000000 --- a/tezt/lib_cloud/configuration.mli +++ /dev/null @@ -1,26 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) -(* *) -(*****************************************************************************) - -type vm = private { - machine_type : string; - docker_image : Env.docker_image; - max_run_duration : int option; - binaries_path : string; - os : Types.Os.t; -} - -type t = private {name : string; vm : vm} - -val make : - ?os:Types.Os.t -> - ?binaries_path:string -> - ?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 663a2cb347bf..2474bf2042a8 100644 --- a/tezt/lib_cloud/deployement.ml +++ b/tezt/lib_cloud/deployement.ml @@ -50,7 +50,8 @@ module Remote = struct ~configurations = let* () = Terraform.VM.Workspace.select workspace_name in let* docker_image = - Env.uri_of_docker_image vm_configuration.Configuration.docker_image + Agent.Configuration.uri_of_docker_image + vm_configuration.Agent.Configuration.docker_image in let machine_type = vm_configuration.machine_type in let max_run_duration = vm_configuration.max_run_duration in @@ -139,7 +140,7 @@ module Remote = struct let* agents = workspace_deploy ~workspace_name - ~vm_configuration:configuration.Configuration.vm + ~vm_configuration:configuration.Agent.Configuration.vm ~configurations:[configuration] ~number_of_vms:1 in @@ -184,10 +185,10 @@ module Remote = struct let workspaces_info = (* VMs are grouped per group of configuration. Each group leads to one workspace. *) List.to_seq configurations - |> Seq.group (fun Configuration.{vm; name = _} configuration -> + |> Seq.group (fun Agent.Configuration.{vm; name = _} configuration -> vm = configuration.vm) |> Seq.mapi (fun i seq -> - let Configuration.{vm = vm_configuration; _} = + let Agent.Configuration.{vm = vm_configuration; _} = Seq.uncons seq |> Option.get |> fst in let workspace_name = Format.asprintf "%s-%d" Env.tezt_cloud i in @@ -206,7 +207,7 @@ module Remote = struct -> let* () = Jobs.docker_build - ~docker_image:vm_configuration.Configuration.docker_image + ~docker_image:vm_configuration.Agent.Configuration.docker_image ~push:Env.push_docker () in @@ -287,7 +288,7 @@ module Localhost = struct Format.asprintf "teztcloud-%s-%s" Env.tezt_cloud - configuration.Configuration.name + configuration.Agent.Configuration.name let deploy ~configurations () = let number_of_vms = List.length configurations in @@ -313,12 +314,13 @@ module Localhost = struct let publish_ports = (start, stop, start, stop) in let* () = Jobs.docker_build - ~docker_image:configuration.Configuration.vm.docker_image + ~docker_image:configuration.Agent.Configuration.vm.docker_image ~push:false () in let* docker_image = - Env.uri_of_docker_image configuration.vm.docker_image + Agent.Configuration.uri_of_docker_image + configuration.vm.docker_image in let process = Docker.run @@ -383,7 +385,7 @@ module Localhost = struct ~point ~configuration ~next_available_port:(fun () -> next_port point) - ~name:configuration.Configuration.name + ~name:configuration.Agent.Configuration.name ()) in Lwt.return {number_of_vms; processes; base_port; ports_per_vm; agents} diff --git a/tezt/lib_cloud/deployement.mli b/tezt/lib_cloud/deployement.mli index cdafe7532832..1222eff796aa 100644 --- a/tezt/lib_cloud/deployement.mli +++ b/tezt/lib_cloud/deployement.mli @@ -13,7 +13,7 @@ type t be opened and [ports_per_vm] specifies the number of opened ports from the [base_port]. The promise returned by this function is fulfilled when all the vms are deployed. Consequently, it can take some time. *) -val deploy : configurations:Configuration.t list -> t Lwt.t +val deploy : configurations:Agent.Configuration.t list -> t Lwt.t (** [get_agents t] returns the list of agents deployed. *) val agents : t -> Agent.t list diff --git a/tezt/lib_cloud/env.ml b/tezt/lib_cloud/env.ml index 1a0db579f0da..1a471c541c0e 100644 --- a/tezt/lib_cloud/env.ml +++ b/tezt/lib_cloud/env.ml @@ -5,8 +5,6 @@ (* *) (*****************************************************************************) -type docker_image = Gcp of {alias : string} | Octez_release of {tag : string} - let tezt_cloud = match Cli.tezt_cloud with | Some tezt_cloud -> tezt_cloud @@ -68,11 +66,6 @@ let alert_handlers = Cli.alert_handlers let dockerfile_alias = Option.value ~default:tezt_cloud Cli.dockerfile_alias -let docker_image = - (* In localhost mode, we don't want to interact with GCP. The image is taken - locally. *) - Gcp {alias = dockerfile_alias} - let dockerfile = Path.dockerfile ~alias:dockerfile_alias let docker_registry = Format.asprintf "%s-docker-registry" tezt_cloud @@ -137,17 +130,6 @@ let registry_uri () = let uri = Format.asprintf "%s/%s/%s" hostname project_id docker_registry in Lwt.return uri -let uri_of_docker_image docker_image = - match (docker_image, mode) with - | Gcp {alias}, (`Cloud | `Host | `Orchestrator) -> - let* registry_uri = registry_uri () in - Lwt.return (Format.asprintf "%s/%s" registry_uri alias) - | Gcp {alias}, `Localhost -> Lwt.return alias - | Octez_release _, (`Cloud | `Host | `Orchestrator) -> - let* registry_uri = registry_uri () in - Lwt.return (Format.asprintf "%s/octez" registry_uri) - | Octez_release _, `Localhost -> Lwt.return "octez" - let rec wait_process ?(sleep = 4) ~is_ready ~run () = let process = run () in let* status = Process.wait process in diff --git a/tezt/lib_cloud/env.mli b/tezt/lib_cloud/env.mli index 123f96a790b8..a2ab4be20679 100644 --- a/tezt/lib_cloud/env.mli +++ b/tezt/lib_cloud/env.mli @@ -8,8 +8,6 @@ (* This module aims to encapsulate static values from the CLI and several functions that are used by the library. *) -type docker_image = Gcp of {alias : string} | Octez_release of {tag : string} - (** Equivalent to [Cli.tezt_cloud], but if not present, checks if `TEZT_CLOUD` is provided. *) val tezt_cloud : string @@ -96,9 +94,6 @@ val alert_handlers : string list (** If [Cli.dockerfile_alias] is provided, use it, otherwise default to [tezt_cloud]. *) val dockerfile_alias : string -(** Use [tezt_cloud] image if [Cli.dockerfile_alias] is not provided, otherwise use it. *) -val docker_image : docker_image - (** Docker path associated to [dockerfile_alias]. *) val dockerfile : string @@ -140,10 +135,6 @@ val zone : unit -> string Lwt.t (** [registry_uri ()] constructs the URI for the Docker registry. *) val registry_uri : unit -> string Lwt.t -(** [uri_of_docker_image docker_image] generates the URI for the Docker image based on - [docker_image]'s type. *) -val uri_of_docker_image : docker_image -> string Lwt.t - (** [wait_process ?sleep ~is_ready ~run ()] recursively waits for [~run] process to be ready. When the process is successful, but no [~is_ready], it loops after [?sleep] seconds. If it is ready, it returns the read output. If it fails, this gets logged. *) diff --git a/tezt/lib_cloud/jobs.ml b/tezt/lib_cloud/jobs.ml index dcdd38181adf..12ce5194655d 100644 --- a/tezt/lib_cloud/jobs.ml +++ b/tezt/lib_cloud/jobs.ml @@ -12,7 +12,9 @@ module Cli = C let docker_build = let cache = Hashtbl.create 11 in - fun ?(docker_image = Env.Gcp {alias = Env.dockerfile_alias}) ~push () -> + fun ?(docker_image = Agent.Configuration.Gcp {alias = Env.dockerfile_alias}) + ~push + () -> if Hashtbl.mem cache docker_image then ( Log.info "Docker image is already built. Nothing to do" ; Lwt.return_unit) diff --git a/tezt/lib_cloud/jobs.mli b/tezt/lib_cloud/jobs.mli index 8592b4ef52d3..58934d7008b9 100644 --- a/tezt/lib_cloud/jobs.mli +++ b/tezt/lib_cloud/jobs.mli @@ -10,7 +10,10 @@ val deploy_docker_registry : unit -> unit Lwt.t (* A job for building and pushing docker images on the registry. *) val docker_build : - ?docker_image:Env.docker_image -> push:bool -> unit -> unit Lwt.t + ?docker_image:Agent.Configuration.docker_image -> + push:bool -> + unit -> + unit Lwt.t (* The docker containers are killed and restarted from scratch. *) val clean_up_vms : unit -> unit Lwt.t diff --git a/tezt/lib_cloud/proxy.ml b/tezt/lib_cloud/proxy.ml index d6a70cf4b7e1..dc0f1c9e848b 100644 --- a/tezt/lib_cloud/proxy.ml +++ b/tezt/lib_cloud/proxy.ml @@ -7,7 +7,7 @@ let agent_name = Format.asprintf "%s-proxy" Env.tezt_cloud -let make_config () = Configuration.make ~name:agent_name () +let make_config () = Agent.Configuration.make ~name:agent_name () let get_agent agents = match List.find_opt (fun agent -> Agent.name agent = agent_name) agents with @@ -100,7 +100,7 @@ let copy_files proxy_agent ~scenario_files ~proxy_deployement = This requires the docker image to contain all the binaries used by the proxy agent. *) - let Configuration.{vm = {binaries_path; _}; name = _} = + let Agent.Configuration.{vm = {binaries_path; _}; name = _} = Agent.configuration proxy_agent in let* output = diff --git a/tezt/lib_cloud/proxy.mli b/tezt/lib_cloud/proxy.mli index 0aa0c9b8e7ce..3218daf5c3f4 100644 --- a/tezt/lib_cloud/proxy.mli +++ b/tezt/lib_cloud/proxy.mli @@ -6,7 +6,7 @@ (*****************************************************************************) (** Create a configuration for the proxy *) -val make_config : unit -> Configuration.t +val make_config : unit -> Agent.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 diff --git a/tezt/lib_cloud/tezt_cloud.ml b/tezt/lib_cloud/tezt_cloud.ml index fb19265ab789..d6cb0d79d63c 100644 --- a/tezt/lib_cloud/tezt_cloud.ml +++ b/tezt/lib_cloud/tezt_cloud.ml @@ -33,11 +33,6 @@ module Alert = struct Alert_manager.alert ?route alert end -module Configuration = struct - include Env - include Configuration -end - module Cloud = Cloud let register_docker_push ~tags = diff --git a/tezt/lib_cloud/tezt_cloud.mli b/tezt/lib_cloud/tezt_cloud.mli index 932653006022..fea12f7c995a 100644 --- a/tezt/lib_cloud/tezt_cloud.mli +++ b/tezt/lib_cloud/tezt_cloud.mli @@ -8,46 +8,6 @@ module Agent = Agent module Types = Types -module Configuration : sig - type docker_image = - | Gcp of {alias : string} - | Octez_release of {tag : string} - - type vm = private { - machine_type : string; - docker_image : docker_image; - max_run_duration : int option; - binaries_path : string; - os : Types.Os.t; - } - - type t = private {name : string; vm : vm} - - (** [make ?machine_type ()] is a smart-constructor to make a VM - configuration. - - Default value for [max_run_duration] is [7200]. - - Default value for [machine_type] is [n1-standard-2]. - - 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 - module Alert : sig (* A receiver of an alert. *) type receiver @@ -131,7 +91,7 @@ module Cloud : sig val register : ?proxy_files:string list -> ?proxy_args:string list -> - ?vms:Configuration.t list -> + ?vms:Agent.Configuration.t list -> __FILE__:string -> title:string -> tags:string list -> diff --git a/tezt/lib_cloud/types.ml b/tezt/lib_cloud/types.ml index f1f5a75fc0b4..411000f709a3 100644 --- a/tezt/lib_cloud/types.ml +++ b/tezt/lib_cloud/types.ml @@ -26,3 +26,91 @@ module Os = struct let open Data_encoding in conv to_string of_string_exn string end + +module Agent_configuration = struct + type docker_image = + | Gcp of {alias : string} + | Octez_release of {tag : string} + + type vm = { + machine_type : string; + docker_image : docker_image; + max_run_duration : int option; + binaries_path : string; + os : Os.t; + } + + type t = {name : string; vm : vm} + + let docker_image_encoding = + let open Data_encoding in + union + [ + case + ~title:"gcp" + Json_only + Data_encoding.(obj1 (req "gcp" string)) + (function Gcp {alias} -> Some alias | _ -> None) + (fun alias -> Gcp {alias}); + case + ~title:"octez_release" + Json_only + Data_encoding.(obj1 (req "octez" string)) + (function Octez_release {tag} -> Some tag | _ -> None) + (fun tag -> Octez_release {tag}); + ] + + let encoding = + let open Data_encoding in + conv + (fun { + name; + vm = + { + 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) -> + { + name; + vm = + { + machine_type; + binaries_path; + max_run_duration = None; + docker_image; + os; + }; + }) + (obj5 + (req "name" string) + (req "machine_type" string) + (req "binaries_path" string) + (req "docker_image" docker_image_encoding) + (req "os" Os.encoding)) + + let default_gcp_machine_type = "n1-standard-2" + + let default_docker_image ~tezt_cloud = Gcp {alias = tezt_cloud} + + let default_max_run_duration = Some 7200 + + let default_gcp_binaries_path = + Filename.get_temp_dir_name () // "tezt-runners" + + let make ~os ~binaries_path ?max_run_duration ~machine_type ~docker_image + ~name () = + let binaries_path = + match docker_image with + | Gcp _ -> binaries_path + | Octez_release _ -> "/usr/local/bin" + in + { + name; + vm = {os; machine_type; docker_image; max_run_duration; binaries_path}; + } +end diff --git a/tezt/lib_cloud/types.mli b/tezt/lib_cloud/types.mli index c38e10e5549f..d7726eb7b254 100644 --- a/tezt/lib_cloud/types.mli +++ b/tezt/lib_cloud/types.mli @@ -21,3 +21,39 @@ module Os : sig val encoding : t Data_encoding.encoding end + +module Agent_configuration : sig + type docker_image = + | Gcp of {alias : string} + | Octez_release of {tag : string} + + val default_docker_image : tezt_cloud:string -> docker_image + + type vm = private { + machine_type : string; + docker_image : docker_image; + max_run_duration : int option; + binaries_path : string; + os : Os.t; + } + + type t = {name : string; vm : vm} + + val encoding : t Data_encoding.encoding + + val default_gcp_machine_type : string + + val default_gcp_binaries_path : string + + val default_max_run_duration : int option + + val make : + os: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 3b0c3db97bb3..94f33bcdb7aa 100644 --- a/tezt/lib_cloud/web.ml +++ b/tezt/lib_cloud/web.ml @@ -19,7 +19,7 @@ type t = { } let pp_docker_image fmt = function - | Env.Gcp {alias} -> Format.fprintf fmt "%s" alias + | Agent.Configuration.Gcp {alias} -> Format.fprintf fmt "%s" alias | Octez_release {tag} -> Format.fprintf fmt "Octez %s release" tag let domain agents = @@ -54,7 +54,7 @@ let string_vm_command agent = let agent_jingo_template agent = let open Jingoo.Jg_types in - let Configuration. + let Agent.Configuration. { vm = {machine_type; docker_image; max_run_duration; binaries_path; os}; name; diff --git a/tezt/tests/cloud/basic.ml b/tezt/tests/cloud/basic.ml index e9ef1d7c96f0..a29f85afb81f 100644 --- a/tezt/tests/cloud/basic.ml +++ b/tezt/tests/cloud/basic.ml @@ -7,7 +7,7 @@ let simple () = Cloud.register - ~vms:[Configuration.make (); Configuration.make ()] + ~vms:[Agent.Configuration.make (); Agent.Configuration.make ()] ~__FILE__ ~tags:["simple"; "health"; Tag.cloud] ~title:"Simple health check to check local configuration" @@ -37,7 +37,7 @@ let simple () = let run_vm () = Cloud.register - ~vms:[Configuration.make ()] + ~vms:[Agent.Configuration.make ()] ~__FILE__ ~tags:["run"; "vm"; Tag.cloud] ~title:"Run a new VM" @@ -61,7 +61,7 @@ let run_vm () = let run_detached () = Cloud.register - ~vms:[Configuration.make ()] + ~vms:[Agent.Configuration.make ()] ~__FILE__ ~tags:["run"; "detach"; Tag.cloud] ~title:"Run a command and detach in a vm" diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 57adf8a5938c..28f027bcd718 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -2654,10 +2654,12 @@ let benchmark () = |> List.concat in let docker_image = - Option.map (fun tag -> Configuration.Octez_release {tag}) Cli.octez_release + Option.map + (fun tag -> Agent.Configuration.Octez_release {tag}) + Cli.octez_release in let default_vm_configuration ~name = - Configuration.make ?docker_image ~name () + Agent.Configuration.make ?docker_image ~name () in let name_of = function | Bootstrap -> "bootstrap" @@ -2686,14 +2688,15 @@ let benchmark () = | Some list -> ( try let machine_type = List.nth list i in - Configuration.make ?docker_image ~machine_type ~name () + Agent.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 ~name () - | Some machine_type -> - Configuration.make ?docker_image ~machine_type ~name ()) + | Etherlink_dal_observer _ -> + Agent.Configuration.make ?docker_image ~name () | Etherlink_operator -> default_vm_configuration ~name | Etherlink_producer _ -> default_vm_configuration ~name | Reverse_proxy -> default_vm_configuration ~name) diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index 4e6c3db11393..032481c219c7 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -741,7 +741,7 @@ let on_new_level = toplog "Done processing metrics for level %d" level ; Lwt.return_unit -type docker_image = Configuration.docker_image = +type docker_image = Agent.Configuration.docker_image = | Gcp of {alias : string} | Octez_release of {tag : string} @@ -887,11 +887,11 @@ let benchmark () = in let default_docker_image = Option.map - (fun tag -> Configuration.Octez_release {tag}) + (fun tag -> Agent.Configuration.Octez_release {tag}) Scenarios_cli.octez_release in let default_vm_configuration ~name = - Configuration.make ?docker_image:default_docker_image ~name () + Agent.Configuration.make ?docker_image:default_docker_image ~name () in let make_vm_conf ~name = function | None -> default_vm_configuration ~name @@ -902,10 +902,10 @@ let benchmark () = | _ -> docker_image in let os = Option.map Types.Os.of_string_exn os in - Configuration.make + Agent.Configuration.make ?machine_type ?docker_image - ?max_run_duration + ~max_run_duration ?binaries_path ?os ~name -- GitLab