diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index f6b6d4c1fdfe49c622046c43268a128a5a272219..fb09ef0f791ecc972b975bedb5f2dac8f73a542e 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 215f36e56e1e62e9fb2f0271d77078a462894043..b34367970ce2a1eb3c98c40d70f733588f083fab 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.ml b/tezt/lib_cloud/cli.ml index 52e8d1ee53e943e1036d670845b649d686f4cb76..d939f76c2e9769120b5dcdab569c4d3daf30ea65 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 9d6f9e39238fbc65760289e893604d6a6f276e89..8872149b44415d80b6cb6ed5c5d7fd2970b85b85 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 diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index 6b43f89228e4d805bacbe6968051856f1d5570e5..dc5b6fc36f5e944ad0016347db714913d80f2409 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 diff --git a/tezt/lib_cloud/configuration.ml b/tezt/lib_cloud/configuration.ml new file mode 100644 index 0000000000000000000000000000000000000000..be0f97f11fc2e6e03faa8627b152684245afa6b6 --- /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 -> Cli.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 0000000000000000000000000000000000000000..5f584d22888e51e56777d62f98a42b73af070367 --- /dev/null +++ b/tezt/lib_cloud/configuration.mli @@ -0,0 +1,16 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +type t = unit + +val filename : string + +val make : unit -> t + +val load : unit -> t + +val save : t -> unit diff --git a/tezt/lib_cloud/dune b/tezt/lib_cloud/dune index 6735173a7d35c26f82dc16dcbb105e17963f04e1..992d2f49e330d47002313394284ebd1e3a097ad5 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 diff --git a/tezt/lib_cloud/proxy.ml b/tezt/lib_cloud/proxy.ml index ecfe8ccd8844295317eb478351128e9e21b150ab..3746d0f1a5d9a733e58da4428837474fd7f75847 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 diff --git a/tezt/lib_cloud/tezt_cloud.ml b/tezt/lib_cloud/tezt_cloud.ml index d6cb0d79d63cf6bede50ded146f8a78430d41b1c..a710c33491cda83dec7a4c786e71cd08d3168564 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