From dece92ffc417c951c6351c63c797eeff52aef8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Tue, 7 Jan 2025 16:25:25 +0100 Subject: [PATCH 1/5] Tezt/Cloud: Add a configuration file for tezt-cloud --- tezt/lib_cloud/cli.ml | 11 +++++++ tezt/lib_cloud/cli.mli | 3 ++ tezt/lib_cloud/configuration.ml | 56 ++++++++++++++++++++++++++++++++ tezt/lib_cloud/configuration.mli | 16 +++++++++ 4 files changed, 86 insertions(+) create mode 100644 tezt/lib_cloud/configuration.ml create mode 100644 tezt/lib_cloud/configuration.mli diff --git a/tezt/lib_cloud/cli.ml b/tezt/lib_cloud/cli.ml index 52e8d1ee53e9..d939f76c2e97 100644 --- a/tezt/lib_cloud/cli.ml +++ b/tezt/lib_cloud/cli.ml @@ -308,3 +308,14 @@ let binaries_path = "Where to find binaries in the docker image by default (default is: \ '/tmp/tezt-runners')" Types.Agent_configuration.default_gcp_binaries_path + +let config_dir = + Clap.default_string + ~section + ~long:"config-dir" + ~description: + "Specify the configuration directory for tezt-cloud. By default, the \ + directory is determined by the XDG Base Directory Specification. If \ + XDG_CONFIG_HOME is not set, the default is: \ + '$HOME/.config/tezt-cloud/'." + (Sys.getenv "HOME" // ".config" // "tezt-cloud") diff --git a/tezt/lib_cloud/cli.mli b/tezt/lib_cloud/cli.mli index 9d6f9e39238f..007d48107ff2 100644 --- a/tezt/lib_cloud/cli.mli +++ b/tezt/lib_cloud/cli.mli @@ -125,3 +125,6 @@ val faketime : string option (** Where to find binaries path by default in the docker image. *) val binaries_path : string + +(** Configuration directory. *) +val config_dir : string option diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml new file mode 100644 index 000000000000..3834a5c3b26b --- /dev/null +++ b/tezt/lib_cloud/configuration.ml @@ -0,0 +1,56 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +(** This configuration contains local information. It includes data + that falls into one of the following categories: + + - Common data shared across all scenarios run with tezt-cloud. + - Sensitive data that should not be shared publicly, such as secrets. +*) + +type t = unit + +let encoding = Data_encoding.unit + +let config_dir = + match Sys.getenv_opt "XDG_CONFIG_HOME" with + | None -> Option.value Cli.config_dir ~default:Path.config_dir + | Some home -> home + +let config_filename = config_dir // "tezt-cloud.yaml" + +let filename = config_filename + +let make () = () + +let load () = + Log.info "Reading the configuration file..." ; + if Sys.file_exists config_filename then + let content = read_file config_filename in + match Yaml.of_string content with + | Error (`Msg message) -> + Test.fail + "Content of configuration file '%s' is invalid:@. %s" + message + config_filename + | Ok json -> ( + try Data_encoding.Json.destruct encoding json + with _ -> + Test.fail + "Decoding failed while reading content of configuration file '%s'. \ + Please fix it." + config_filename) + else + Test.fail + "Unknown configuration file '%s'. Please check the configuration \ + directory or run the 'config init' job to create a configuration file" + config_filename + +let save configuration = + (* We can assume a configuration produces always a valid YAML. *) + let content = Data_encoding.Json.construct encoding configuration in + write_file config_filename ~contents:(Yaml.to_string_exn content) diff --git a/tezt/lib_cloud/configuration.mli b/tezt/lib_cloud/configuration.mli new file mode 100644 index 000000000000..0731ebbf72a9 --- /dev/null +++ b/tezt/lib_cloud/configuration.mli @@ -0,0 +1,16 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +type t = private {tezt_cloud : string} + +val filename : string + +val make : tezt_cloud:string -> unit -> t + +val load : unit -> t + +val save : t -> unit -- GitLab From 0190dce7530128831ee3248dd4c43c4cc84e123e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Tue, 7 Jan 2025 17:10:36 +0100 Subject: [PATCH 2/5] Tezt/Cloud: Add a configuration for tezt-cloud --- manifest/product_octez.ml | 1 + opam/tezt-cloud.opam | 1 + tezt/lib_cloud/cli.mli | 2 +- tezt/lib_cloud/configuration.ml | 2 +- tezt/lib_cloud/configuration.mli | 4 ++-- tezt/lib_cloud/dune | 1 + 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index f6b6d4c1fdfe..fb09ef0f791e 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -2388,6 +2388,7 @@ let tezt_cloud = tezt_lib |> open_ |> open_ ~m:"Base"; tezt_performance_regression |> open_; jingoo; + yaml; dream; data_encoding; ] diff --git a/opam/tezt-cloud.opam b/opam/tezt-cloud.opam index 215f36e56e1e..b34367970ce2 100644 --- a/opam/tezt-cloud.opam +++ b/opam/tezt-cloud.opam @@ -13,6 +13,7 @@ depends: [ "tezt" { >= "4.1.0" & < "5.0.0" } "tezt-tezos" { = version } "jingoo" + "yaml" { >= "3.1.0" } "dream" { >= "1.0.0~alpha7" } "octez-libs" { = version } ] diff --git a/tezt/lib_cloud/cli.mli b/tezt/lib_cloud/cli.mli index 007d48107ff2..8872149b4441 100644 --- a/tezt/lib_cloud/cli.mli +++ b/tezt/lib_cloud/cli.mli @@ -127,4 +127,4 @@ val faketime : string option val binaries_path : string (** Configuration directory. *) -val config_dir : string option +val config_dir : string diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml index 3834a5c3b26b..be0f97f11fc2 100644 --- a/tezt/lib_cloud/configuration.ml +++ b/tezt/lib_cloud/configuration.ml @@ -18,7 +18,7 @@ let encoding = Data_encoding.unit let config_dir = match Sys.getenv_opt "XDG_CONFIG_HOME" with - | None -> Option.value Cli.config_dir ~default:Path.config_dir + | None -> Cli.config_dir | Some home -> home let config_filename = config_dir // "tezt-cloud.yaml" diff --git a/tezt/lib_cloud/configuration.mli b/tezt/lib_cloud/configuration.mli index 0731ebbf72a9..5f584d22888e 100644 --- a/tezt/lib_cloud/configuration.mli +++ b/tezt/lib_cloud/configuration.mli @@ -5,11 +5,11 @@ (* *) (*****************************************************************************) -type t = private {tezt_cloud : string} +type t = unit val filename : string -val make : tezt_cloud:string -> unit -> t +val make : unit -> t val load : unit -> t diff --git a/tezt/lib_cloud/dune b/tezt/lib_cloud/dune index 6735173a7d35..992d2f49e330 100644 --- a/tezt/lib_cloud/dune +++ b/tezt/lib_cloud/dune @@ -8,6 +8,7 @@ tezt tezt-tezos.tezt-performance-regression jingoo + yaml dream octez-libs.data-encoding) (flags -- GitLab From a96a6ca1da45c609c475237c2a187c8b72841468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Tue, 7 Jan 2025 17:15:47 +0100 Subject: [PATCH 3/5] Tezt/Cloud: Push the configuration using the proxy mode --- tezt/lib_cloud/proxy.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tezt/lib_cloud/proxy.ml b/tezt/lib_cloud/proxy.ml index ecfe8ccd8844..3746d0f1a5d9 100644 --- a/tezt/lib_cloud/proxy.ml +++ b/tezt/lib_cloud/proxy.ml @@ -25,6 +25,12 @@ let copy_files proxy_agent ~scenario_files ~proxy_deployement = other VMs. *) let ssh_public_key_filename = Env.ssh_public_key_filename () in let ssh_private_key_filename = Env.ssh_private_key_filename () in + let* _ = + Agent.copy + proxy_agent + ~source:Configuration.filename + ~destination:("/root" // "tezt-cloud.yml") + in let* _ = Agent.copy proxy_agent -- GitLab From b96f70a7f000d76cfb812bf6745d94482c5f4c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Tue, 7 Jan 2025 17:20:25 +0100 Subject: [PATCH 4/5] Tezt/Cloud: Add a config init job --- tezt/lib_cloud/tezt_cloud.ml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tezt/lib_cloud/tezt_cloud.ml b/tezt/lib_cloud/tezt_cloud.ml index d6cb0d79d63c..a710c33491cd 100644 --- a/tezt/lib_cloud/tezt_cloud.ml +++ b/tezt/lib_cloud/tezt_cloud.ml @@ -205,6 +205,20 @@ let register_dns_remove ~tags = unit) domains +let register_config_init ~tags = + (* We use [Test.register] because we can't assume there is already a configuration. *) + Test.register + ~__FILE__ + ~title:"Create tezt-cloud configuration file" + ~tags:("config" :: "configuration" :: "init" :: tags) + @@ fun () -> + let configuration = Configuration.make () in + Configuration.save configuration ; + Log.report + "Configuration saved successfully under '%s'." + Configuration.filename ; + Lwt.return_unit + let register ~tags = register_docker_push ~tags ; register_docker_build ~tags ; @@ -217,4 +231,5 @@ let register ~tags = register_describe_dns_zone ~tags ; register_list_dns_domains ~tags ; register_dns_add ~tags ; - register_dns_remove ~tags + register_dns_remove ~tags ; + register_config_init ~tags -- GitLab From 3474d0d0d4eece455fdee9c029297f3a167eaa43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Tue, 7 Jan 2025 17:20:57 +0100 Subject: [PATCH 5/5] Tezt/Cloud: Force the use of a configuration file --- tezt/lib_cloud/cloud.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index 6b43f89228e4..dc5b6fc36f5e 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -481,6 +481,7 @@ let set_faketime faketime agent = let register ?proxy_files ?proxy_args ?vms ~__FILE__ ~title ~tags ?seed ?alerts f = Test.register ~__FILE__ ~title ~tags ?seed @@ fun () -> + let _configuration = Configuration.load () in let* () = Env.init () in let vms = match (vms, Env.vms) with -- GitLab