summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-04-13 20:53:48 -0500
committerJohn Estabrook <jestabro@vyos.io>2025-05-12 11:26:41 -0500
commit3c4d8803fc84da305aaa72cf97ca96fb19d186c9 (patch)
treefaddd3e3644af6991c64460d43d17c89ce530c50
parent4f8cd87849ae16f5efb127b63767176a243bcd8d (diff)
downloadvyconf-3c4d8803fc84da305aaa72cf97ca96fb19d186c9.tar.gz
vyconf-3c4d8803fc84da305aaa72cf97ca96fb19d186c9.zip
T7272: refactor commit function for clarity
-rw-r--r--src/session.ml22
-rw-r--r--src/session.mli2
-rw-r--r--src/vyconfd.ml11
3 files changed, 27 insertions, 8 deletions
diff --git a/src/session.ml b/src/session.ml
index 24a8153..1ff7c45 100644
--- a/src/session.ml
+++ b/src/session.ml
@@ -1,8 +1,11 @@
module CT = Vyos1x.Config_tree
+module IC = Vyos1x.Internal.Make(CT)
+module CC = Commitd_client.Commit
module CD = Vyos1x.Config_diff
module VT = Vyos1x.Vytree
module RT = Vyos1x.Reference_tree
module D = Directories
+module FP = FilePath
exception Session_error of string
@@ -136,6 +139,25 @@ let save w s file =
| Error e -> raise (Session_error (Printf.sprintf "Error saving config: %s" e))
| Ok () -> s
+let prepare_commit ?(dry_run=false) w s id =
+ let at = w.running_config in
+ let wt = s.proposed_config in
+ let rt = w.reference_tree in
+ let vc = w.vyconf_config in
+ let () =
+ try
+ IC.write_internal at (FP.concat vc.session_dir vc.running_cache)
+ with
+ Vyos1x.Internal.Write_error msg -> raise (Session_error msg)
+ in
+ let () =
+ try
+ IC.write_internal wt (FP.concat vc.session_dir vc.session_cache)
+ with
+ Vyos1x.Internal.Write_error msg -> raise (Session_error msg)
+ in
+ CC.make_commit_data ~dry_run:dry_run rt at wt id
+
let get_value w s path =
if not (VT.exists s.proposed_config path) then
raise (Session_error ("Config path does not exist"))
diff --git a/src/session.mli b/src/session.mli
index 9b8c5a0..4bae311 100644
--- a/src/session.mli
+++ b/src/session.mli
@@ -50,4 +50,6 @@ val list_children : world -> session_data -> string list -> string list
val string_of_op : cfg_op -> string
+val prepare_commit : ?dry_run:bool -> world -> session_data -> string -> Commitd_client.Commit.commit_data
+
val show_config : world -> session_data -> string list -> Vyconf_connect.Vyconf_pbt.request_config_format -> string
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index 885fd20..bc607a3 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -192,15 +192,10 @@ let save world token (req: request_save) =
let commit world token (req: request_commit) =
let s = find_session token in
- let at = world.Session.running_config in
- let wt = s.proposed_config in
- let rt = world.reference_tree in
- let vc = world.vyconf_config in
- let () = IC.write_internal at (FP.concat vc.session_dir vc.running_cache) in
- let () = IC.write_internal wt (FP.concat vc.session_dir vc.session_cache) in
-
let req_dry_run = Option.value req.dry_run ~default:false in
- let commit_data = CC.make_commit_data ~dry_run:req_dry_run rt at wt token in
+
+ let commit_data = Session.prepare_commit ~dry_run:req_dry_run world s token
+ in
let%lwt received_commit_data = VC.do_commit commit_data in
let%lwt result_commit_data =
Lwt.return (CC.commit_update received_commit_data)