diff --git a/tezt/lib_cloud/agent.ml b/tezt/lib_cloud/agent.ml index c7e73af1042f2724dac796970b00ef524d4d1c93..e58a8323d81dc4225a02690b2ed007975485e7d4 100644 --- a/tezt/lib_cloud/agent.ml +++ b/tezt/lib_cloud/agent.ml @@ -128,7 +128,7 @@ let encoding = I don't have a good proposition that keeps a nice UX and is secure at the moment. *) Runner.create - ~options:["-o"; "StrictHostKeyChecking=no"] + ~options:Ssh.ssh_options ~ssh_user:"root" ~ssh_id ~ssh_port @@ -184,7 +184,7 @@ let make ?zone ?ssh_id ?point ~configuration ~next_available_port ~vm_name Test.fail "Agent.make was not initialized correctly" | Some (address, ssh_port), Some ssh_id -> Runner.create - ~options:["-o"; "StrictHostKeyChecking=no"] + ~options:Ssh.ssh_options ~ssh_user ~ssh_id ~ssh_port @@ -337,13 +337,10 @@ let copy agent ~consistency_check ~is_directory ~source ~destination = runner.Runner.ssh_port in let* () = - (* FIXME: I forgot why we enforce [-0]. *) Process.run "scp" ((if is_directory then ["-r"] else []) - @ ["-O"] - @ ["-o"; "StrictHostKeyChecking=no"] - @ identity @ port @ [source] @ [destination]) + @ Ssh.scp_options @ identity @ port @ [source] @ [destination]) in Lwt.return_unit diff --git a/tezt/lib_cloud/cloud.ml b/tezt/lib_cloud/cloud.ml index c177d59679ff1c33c3f54efc2ba0a06df895b878..676a5fdebdb1a076b3e4adfb90ae2e7d116105fd 100644 --- a/tezt/lib_cloud/cloud.ml +++ b/tezt/lib_cloud/cloud.ml @@ -160,7 +160,7 @@ let wait_ssh_server_running agent = runner (Runner.Shell.cmd [] "echo" ["-n"; "check"]) in - Process.spawn cmd (["-o"; "StrictHostKeyChecking=no"] @ args) + Process.spawn cmd (runner.options @ args) in let* _ = Env.wait_process ~is_ready ~run () in Lwt.return_unit @@ -330,8 +330,7 @@ let attach agent = (Runner.Shell.cmd [] "screen" ["-S"; "tezt-cloud"; "-X"; "stuff"; "^C"]) in let* () = - Process.spawn ~hooks cmd (["-o"; "StrictHostKeyChecking=no"] @ args) - |> Process.check + Process.spawn ~hooks cmd (runner.options @ args) |> Process.check in let cmd, args = Runner.wrap_with_ssh @@ -339,8 +338,7 @@ let attach agent = (Runner.Shell.cmd [] "stdbuf" ["-oL"; "tail"; "-F"; "screenlog.0"]) in let _p = - Process.spawn ~hooks cmd (["-o"; "StrictHostKeyChecking=no"] @ args) - |> Process.check + Process.spawn ~hooks cmd (runner.options @ args) |> Process.check in let* _ = Input.eof in let* () = @@ -390,8 +388,7 @@ let attach agent = Lwt.catch (fun () -> let* () = - Process.spawn ~hooks cmd (["-o"; "StrictHostKeyChecking=no"] @ args) - |> Process.check + Process.spawn ~hooks cmd (runner.options @ args) |> Process.check in Lwt.return_unit) (fun exn -> diff --git a/tezt/lib_cloud/service_manager.ml b/tezt/lib_cloud/service_manager.ml index 7730e5175f27aa3b2742f5568e2d0f495c3aceb0..991d9bbbed69548a34e738a969996e35ec58ace5 100644 --- a/tezt/lib_cloud/service_manager.ml +++ b/tezt/lib_cloud/service_manager.ml @@ -99,19 +99,15 @@ let register_service ~name ~executable let () = if Hashtbl.length t.services = 0 then start t else () in (* Get the real executable name *) (* Note: this only works on remote vm *) - if Sys.file_exists executable then - let executable = Unix.realpath executable in - let service = - {executable = Some executable; on_alive_callback; pid = None; on_shutdown} + let service = + let executable = + if Sys.file_exists executable then Some (Unix.realpath executable) + else None in - let () = Hashtbl.add t.services name service in - Log.info "%s: Registering service: %s (%s)" section name executable - else - let service = - {executable = None; on_alive_callback; pid = None; on_shutdown} - in - let () = Hashtbl.add t.services name service in - Log.info "%s: Registering service: %s (%s)" section name executable + {executable; on_alive_callback; pid = None; on_shutdown} + in + let () = Hashtbl.add t.services name service in + Log.info "%s: Registering service: %s (%s)" section name executable let notify_start_service ~name ~pid t = match Hashtbl.find_opt t.services name with diff --git a/tezt/lib_cloud/ssh.ml b/tezt/lib_cloud/ssh.ml index bee0fabcc7832b7e5ea735df40f0575d821b9cdd..79b0e4030f22a559e7192c78276843e4bf6969a2 100644 --- a/tezt/lib_cloud/ssh.ml +++ b/tezt/lib_cloud/ssh.ml @@ -24,3 +24,18 @@ let public_key () = Process.run_and_read_stdout ~name:"cat" "cat" [ssh_public_key_filename] in Lwt.return content + +let common_options = ["-o"; "StrictHostKeyChecking=no"] + +let ssh_options = common_options + +(* Default options required to properly run scp command. As scp command's syntax + is close to the ssh one, we reuse the [ssh_options]. This might be breaking + if incompatible ssh options are used. + + The [-O] option forces the use of the SCP protocol, instead of the SFTP + protocol. This may be necessary for servers that do not implement SFTP, for + backwards-compatibility for particular filename wildcard patterns and for + expanding paths with a ‘~’ prefix for older SFTP servers. +*) +let scp_options = ["-O"] @ common_options diff --git a/tezt/lib_cloud/ssh.mli b/tezt/lib_cloud/ssh.mli index 594ceedc1146444567b188d0eb1e247ff0173d97..9cee09a88cfc72744e96d7497ded42b90cc4d59f 100644 --- a/tezt/lib_cloud/ssh.mli +++ b/tezt/lib_cloud/ssh.mli @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) -(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* SPDX-FileCopyrightText: 2025 Nomadic Labs *) (* *) (*****************************************************************************) @@ -12,3 +12,11 @@ val generate_key : unit -> unit Lwt.t (** [ssh_public_key()] returns the ssh public key associated to the generate_key It calls [generate_key] if it does not exist *) val public_key : unit -> string Lwt.t + +(* Default options required to properly run through ssh. *) +val ssh_options : string list + +(* Default options required to properly run scp command. As scp command's syntax + is close to the ssh one, we reuse the [ssh_options]. This might be breaking + if incompatible ssh options are used. *) +val scp_options : string list diff --git a/tezt/lib_cloud/tezt_cloud.ml b/tezt/lib_cloud/tezt_cloud.ml index 9e693ad953f8d55d059e8730d41847b3a2574385..b53d44aca4568edae7b1b3876ab9b6552c8c39cb 100644 --- a/tezt/lib_cloud/tezt_cloud.ml +++ b/tezt/lib_cloud/tezt_cloud.ml @@ -9,6 +9,7 @@ module Path = Path module Agent = Agent module Types = Types module Chronos = Chronos +module Ssh = Ssh module Alert = struct include Alert_manager diff --git a/tezt/lib_cloud/tezt_cloud.mli b/tezt/lib_cloud/tezt_cloud.mli index 4c463fd37f2e808f56957af65f740443d268f607..0a24c8e52b675cd06c3b3055361f82a3480eb586 100644 --- a/tezt/lib_cloud/tezt_cloud.mli +++ b/tezt/lib_cloud/tezt_cloud.mli @@ -8,6 +8,7 @@ module Path = Path module Agent = Agent module Types = Types +module Ssh = Ssh module Chronos : sig (** A scheduler task. *) diff --git a/tezt/lib_cloud/web.ml b/tezt/lib_cloud/web.ml index 8591c0e203aeed849ae79962e61943ae9bcbb79d..600263e8279f1e398c42e0bb164084b05f19ccc2 100644 --- a/tezt/lib_cloud/web.ml +++ b/tezt/lib_cloud/web.ml @@ -39,16 +39,15 @@ let string_docker_command agent = let ssh_id = runner.Runner.ssh_id in String.concat " " - [ - "ssh"; - Format.asprintf "root@%s" (fst point); - "-p"; - string_of_int (snd point); - "-o"; - "StrictHostKeyChecking=no"; - "-i"; - ssh_id |> Option.get; - ] + ([ + "ssh"; + Format.asprintf "root@%s" (fst point); + "-p"; + string_of_int (snd point); + "-i"; + ssh_id |> Option.get; + ] + @ runner.options) let string_vm_command agent = match Agent.cmd_wrapper agent with diff --git a/tezt/tests/cloud/agent_kind.ml b/tezt/tests/cloud/agent_kind.ml index 9cc6ab224c6da374168ceedc3894f377b0d8a29a..775712990410028f0796ded63a44189570a265d8 100644 --- a/tezt/tests/cloud/agent_kind.ml +++ b/tezt/tests/cloud/agent_kind.ml @@ -107,9 +107,7 @@ module Logs = struct (fun () -> Process.run "scp" - (["-r"] @ ["-O"] - @ ["-o"; "StrictHostKeyChecking=no"] - @ identity @ port + (Ssh.scp_options @ ["-r"] @ identity @ port @ [source // daemon_name // "daily_logs"] @ [local_path // "daily_logs"])) (fun exn ->