diff --git a/src/bin_flextesa/command_voting.ml b/src/bin_flextesa/command_voting.ml index 850c3e8edfd1ec4c01df2252a3cabf5c24c8fe3c..150df6575a5abb4759bac8c19b7c42d69eaf3dae 100644 --- a/src/bin_flextesa/command_voting.ml +++ b/src/bin_flextesa/command_voting.ml @@ -254,7 +254,7 @@ let run state ~winner_path ~demo_path ~current_hash ~node_exec ~client_exec let tmpdir = Paths.root state // sprintf "protocol-%s" name in Console.say state EF.(wf "Injecting protocol from %s" tmpdir) >>= fun () -> - Running_processes.run_successful_cmdf state "cp -L -r %s %s" + Running_processes.run_successful_cmdf state "cp -L -R %s %s" (Filename.quote path) (Filename.quote tmpdir) >>= fun _ -> ( if make_different then diff --git a/src/lib_network_sandbox/running_processes.ml b/src/lib_network_sandbox/running_processes.ml index 5d8355bfc5a99fa02ccb3cbb9181774bed27a85f..1e34f13e7687dc324fde30270176db5aace49adb 100644 --- a/src/lib_network_sandbox/running_processes.ml +++ b/src/lib_network_sandbox/running_processes.ml @@ -1,18 +1,21 @@ open Internal_pervasives module Process = struct - type t = - { id: string - ; binary: string option - ; command: string list - ; kind: [`Process_group | `Docker of string] } + type kind = + [`Process_group | `Docker of string | `Process_group_script of string] - let make_in_session ?binary id command = - {id; binary; command= "setsid" :: command; kind= `Process_group} + type t = {id: string; binary: string option; command: string list; kind: kind} + + let make_in_session ?binary id kind command = + {id; binary; command= "setsid" :: command; kind} let genspio id script = - let command = ["sh"; "-c"; Genspio.Compile.to_one_liner script] in - make_in_session id command + let script_content = + Format.asprintf "%a" Genspio.Compile.To_slow_flow.Script.pp_posix + (Genspio.Compile.To_slow_flow.compile script) + in + let command = ["sh"] in + make_in_session id (`Process_group_script script_content) command let docker_run id ~image ~options ~args = let name = id in @@ -59,7 +62,8 @@ let output_path t process which = match which with | `Stdout -> "stdout.log" | `Stderr -> "stderr.log" - | `Meta -> "meta.log" ) + | `Meta -> "meta.log" + | `Script -> "script.sh" ) let ef_procesess state processes = EF.( @@ -96,7 +100,8 @@ let ef ?(all = false) state = ; desc (af "kind:") ( match process.kind with | `Docker n -> af "docker:%s" n - | `Process_group -> af "process-group" ) ] ) + | `Process_group -> af "process-group" + | `Process_group_script _ -> af "shell-script" ) ] ) :: prev | _, _ -> prev ) (State.processes state) [] @@ -106,8 +111,9 @@ let ef ?(all = false) state = label (af "Processes:") (list all_procs)) let start t process = - let date = Tezos_stdlib_unix.Systime_os.now () - |> Tezos_base.Time.System.to_notation in + let date = + Tezos_stdlib_unix.Systime_os.now () |> Tezos_base.Time.System.to_notation + in let open_file f = Lwt_exception.catch ~attach:[("open_file", `String_value f)] @@ -129,6 +135,13 @@ let start t process = >>= fun stdout -> open_file (output_path t process `Stderr) >>= fun stderr -> + ( match process.kind with + | `Process_group | `Docker _ -> return process.command + | `Process_group_script s -> + let path = output_path t process `Script in + System.write_file t path ~content:s + >>= fun () -> return (process.command @ [path]) ) + >>= fun actual_command -> Lwt_exception.catch (fun () -> Lwt_io.with_file ~mode:Lwt_io.output @@ -139,7 +152,7 @@ let start t process = let sep = String.make 80 '=' in sprintf "\n%s\nDate: %s\nStarting: %s\nCmd: [%s]\n%s\n" sep date process.Process.id - ( List.map process.command ~f:(sprintf "%S") + ( List.map actual_command ~f:(sprintf "%S") |> String.concat ~sep:"; " ) sep in @@ -149,7 +162,7 @@ let start t process = let proc = Lwt_process.open_process_none ~stdout:(`FD_move stdout) ~stderr:(`FD_move stderr) - (Option.value ~default:"" process.binary, Array.of_list process.command) + (Option.value ~default:"" process.binary, Array.of_list actual_command) in State.add_process t process proc >>= fun () -> return {process; lwt= proc} @@ -170,7 +183,7 @@ let wait _t {lwt; _} = let kill _t {lwt; process} = match process.kind with - | `Process_group -> + | `Process_group | `Process_group_script _ -> Lwt_exception.catch (fun () -> let signal = Sys.sigterm in @@ -238,7 +251,7 @@ let run_cmdf state fmt = ksprintf (fun s -> let id = fresh_id state "cmd" ~seed:s in - let proc = Process.make_in_session id ["sh"; "-c"; s] in + let proc = Process.make_in_session id `Process_group ["sh"; "-c"; s] in start state proc >>= fun proc -> wait state proc @@ -261,7 +274,7 @@ let run_async_cmdf state f fmt = ksprintf (fun s -> let id = fresh_id state "cmd" ~seed:s in - let proc = Process.make_in_session id ["sh"; "-c"; s] in + let proc = Process.make_in_session id `Process_group ["sh"; "-c"; s] in start_full state proc >>= fun (proc_state, proc) -> f proc diff --git a/src/lib_network_sandbox/running_processes.mli b/src/lib_network_sandbox/running_processes.mli index 0adb39772a35f11e70e588ed690b9fa48d7d5b4c..911d14839c0675dbdf55c49b6ecd0c3e071f0dca 100644 --- a/src/lib_network_sandbox/running_processes.mli +++ b/src/lib_network_sandbox/running_processes.mli @@ -5,13 +5,13 @@ open Internal_pervasives (** The definition of a process, for now, a process within a process-group or a Docker container. *) module Process : sig + type kind = + [`Process_group | `Docker of string | `Process_group_script of string] + type t = private - { id: string - ; binary: string option - ; command: string list - ; kind: [`Process_group | `Docker of string] } + {id: string; binary: string option; command: string list; kind: kind} - val make_in_session : ?binary:string -> string -> string list -> t + val make_in_session : ?binary:string -> string -> kind -> string list -> t val genspio : string -> 'a Genspio.EDSL.t -> t val docker_run : @@ -40,7 +40,7 @@ val ef_procesess : val ef : ?all:bool -> < runner: State.t ; .. > -> Easy_format.t val start : - < paths: Paths.t ; runner: State.t ; .. > + < application_name: string ; paths: Paths.t ; runner: State.t ; .. > -> Process.t -> (State.process_state, [> `Lwt_exn of exn]) Asynchronous_result.t @@ -67,7 +67,7 @@ val find_process_by_id : -> (State.process_state list, [> ]) Asynchronous_result.t val run_cmdf : - < paths: Paths.t ; runner: State.t ; .. > + < paths: Paths.t ; runner: State.t ; .. > Base_state.t -> ( 'a , unit , string @@ -89,7 +89,7 @@ val run_async_cmdf : (** Run a shell command and run a function over the process data before waiting for its end. *) val run_successful_cmdf : - < paths: Paths.t ; runner: State.t ; .. > + < paths: Paths.t ; runner: State.t ; .. > Base_state.t -> ( 'a , unit , string @@ -100,7 +100,7 @@ val run_successful_cmdf : -> 'a val run_genspio : - < paths: Paths.t ; runner: State.t ; .. > + < paths: Paths.t ; runner: State.t ; .. > Base_state.t -> string -> 'a Genspio.Language.t -> (Lwt_unix.process_status, [> `Lwt_exn of exn]) Asynchronous_result.t diff --git a/src/lib_network_sandbox/test_scenario.mli b/src/lib_network_sandbox/test_scenario.mli index cd7931d30c3a82d953de078735c3ba31c8e78f1d..9a6e5da0dcc7e6aab271f93d3947f0d7328de195 100644 --- a/src/lib_network_sandbox/test_scenario.mli +++ b/src/lib_network_sandbox/test_scenario.mli @@ -64,7 +64,7 @@ module Network : sig val make : Tezos_node.t list -> t val netstat_listening_ports : - < paths: Paths.t ; runner: Running_processes.State.t ; .. > + < paths: Paths.t ; runner: Running_processes.State.t ; .. > Base_state.t -> ( (int * [> `Tcp of int * string list]) list , [> `Lwt_exn of exn | Process_result.Error.t] ) Asynchronous_result.t @@ -72,7 +72,10 @@ module Network : sig val start_up : ?check_ports:bool - -> < paths: Paths.t ; runner: Running_processes.State.t ; .. > + -> < Base_state.base + ; paths: Paths.t + ; runner: Running_processes.State.t + ; .. > -> client_exec:Tezos_executable.t -> t -> ( unit @@ -89,7 +92,7 @@ val network_with_protocol : -> ?base_port:int -> ?size:int -> ?protocol:Tezos_protocol.t - -> < paths: Paths.t ; runner: Running_processes.State.t ; .. > + -> < paths: Paths.t ; runner: Running_processes.State.t ; .. > Base_state.t -> node_exec:Tezos_executable.t -> client_exec:Tezos_executable.t -> ( Tezos_node.t list * Tezos_protocol.t diff --git a/src/lib_network_sandbox/tezos_client.mli b/src/lib_network_sandbox/tezos_client.mli index d05569910fee4c567eb5bfdb30217f1d62fc6e68..4355373a319719a79dab5e0fd3b1c9c5c13471f4 100644 --- a/src/lib_network_sandbox/tezos_client.mli +++ b/src/lib_network_sandbox/tezos_client.mli @@ -32,12 +32,14 @@ val activate_protocol_script : val bootstrapped : t -> state:< paths: Paths.t ; runner: Running_processes.State.t ; .. > + Base_state.t -> (unit, [> `Lwt_exn of exn]) Asynchronous_result.t (** Wait for the node to be bootstrapped. *) val import_secret_key : t -> state:< paths: Paths.t ; runner: Running_processes.State.t ; .. > + Base_state.t -> string -> string -> (unit, [> `Lwt_exn of exn]) Asynchronous_result.t @@ -45,12 +47,14 @@ val import_secret_key : val register_as_delegate : t -> state:< paths: Paths.t ; runner: Running_processes.State.t ; .. > + Base_state.t -> string -> (unit, [> `Lwt_exn of exn]) Asynchronous_result.t val activate_protocol : t -> state:< paths: Paths.t ; runner: Running_processes.State.t ; .. > + Base_state.t -> Tezos_protocol.t -> (unit, [> `Lwt_exn of exn]) Asynchronous_result.t @@ -81,6 +85,7 @@ val successful_client_cmd : ; paths: Paths.t ; runner: Running_processes.State.t ; .. > + Base_state.t -> client:t -> string list -> ( < err: string list ; out: string list ; status: Unix.process_status > @@ -93,6 +98,7 @@ val rpc : ; paths: Paths.t ; runner: Running_processes.State.t ; .. > + Base_state.t -> client:t -> [< `Get | `Post of string] -> path:string