summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-04-08 15:09:45 +0100
committerGitHub <noreply@github.com>2025-04-08 15:09:45 +0100
commit61566db58d2b5f8eacbd1564ba1ae0690ac4b1f6 (patch)
tree47ccceb8e72c4a02ceb282a0c5db7e06c93baaf8
parent0fb5e2f781725196ae010cf64e4d185a8f5ce721 (diff)
parenteeb758f406f0cc27ab7863dc17eec00c24f2c0b6 (diff)
downloadvyconf-master.tar.gz
vyconf-master.zip
Merge pull request #19 from jestabro/commit-dry-runHEADmaster
T7302: add backend support for commit dry-run
-rw-r--r--data/vyconf.proto1
-rw-r--r--src/commit.ml15
-rw-r--r--src/commit.mli4
-rw-r--r--src/vyconf_client.ml4
-rw-r--r--src/vyconf_pbt.ml18
-rw-r--r--src/vyconf_pbt.mli2
-rw-r--r--src/vyconfd.ml9
7 files changed, 33 insertions, 20 deletions
diff --git a/data/vyconf.proto b/data/vyconf.proto
index 09ee685..56875a3 100644
--- a/data/vyconf.proto
+++ b/data/vyconf.proto
@@ -55,6 +55,7 @@ message Request {
optional bool Confirm = 1;
optional int32 ConfirmTimeout = 2;
optional string Comment = 3;
+ optional bool DryRun = 4;
}
message Rollback {
diff --git a/src/commit.ml b/src/commit.ml
index ba740b5..19c9844 100644
--- a/src/commit.ml
+++ b/src/commit.ml
@@ -169,18 +169,6 @@ let calculate_priority_lists rt diff =
let cs_del, cs_add = legacy_order del_tree cs_del' cs_add' in
List.rev (CS.elements cs_del), CS.elements cs_add
-let commit_store c_data =
- let out =
- let func acc nd =
- match nd.reply with
- | None -> acc ^ "\n"
- | Some r ->
- match r.success with
- | true -> acc ^ "\n"
- | false -> acc ^ "\n" ^ r.out
- in List.fold_left func "" c_data.node_list
- in print_endline out
-
(* The base config_result is the intersection of running and proposed
configs:
on success, added paths are added; deleted paths are ignored
@@ -239,11 +227,12 @@ let commit_update c_data =
| Some _ -> config_result_update acc_data nd
in List.fold_left func c_data c_data.node_list
-let make_commit_data rt at wt id =
+let make_commit_data ?(dry_run=false) rt at wt id =
let diff = CD.diff_tree [] at wt in
let del_list, add_list = calculate_priority_lists rt diff in
{ default_commit_data with
session_id = id;
+ dry_run = dry_run;
config_diff = diff;
config_result = CT.get_subtree diff ["inter"];
node_list = del_list @ add_list; }
diff --git a/src/commit.mli b/src/commit.mli
index 12ad084..01022ec 100644
--- a/src/commit.mli
+++ b/src/commit.mli
@@ -35,10 +35,8 @@ val default_node_data : node_data
val default_commit_data : commit_data
-val make_commit_data : Vyos1x.Reference_tree.t -> Vyos1x.Config_tree.t -> Vyos1x.Config_tree.t -> string -> commit_data
+val make_commit_data : ?dry_run:bool -> Vyos1x.Reference_tree.t -> Vyos1x.Config_tree.t -> Vyos1x.Config_tree.t -> string -> commit_data
val calculate_priority_lists : Vyos1x.Reference_tree.t -> Vyos1x.Config_tree.t -> node_data list * node_data list
val commit_update : commit_data -> commit_data
-
-val commit_store : commit_data -> unit
diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml
index 1f00f29..7380760 100644
--- a/src/vyconf_client.ml
+++ b/src/vyconf_client.ml
@@ -135,7 +135,9 @@ let delete client path =
| _ -> Error (Option.value resp.error ~default:"") |> Lwt.return
let commit client =
- let req = Commit {confirm=None; confirm_timeout=None; comment=None;} in
+ let req =
+ Commit {confirm=None; confirm_timeout=None; comment=None; dry_run=None}
+ in
let%lwt resp = do_request client req in
match resp.status with
| Success -> Ok (Option.value resp.output ~default:"") |> Lwt.return
diff --git a/src/vyconf_pbt.ml b/src/vyconf_pbt.ml
index 5692f77..48a8e87 100644
--- a/src/vyconf_pbt.ml
+++ b/src/vyconf_pbt.ml
@@ -53,6 +53,7 @@ type request_commit = {
confirm : bool option;
confirm_timeout : int32 option;
comment : string option;
+ dry_run : bool option;
}
type request_rollback = {
@@ -236,10 +237,12 @@ let rec default_request_commit
?confirm:((confirm:bool option) = None)
?confirm_timeout:((confirm_timeout:int32 option) = None)
?comment:((comment:string option) = None)
+ ?dry_run:((dry_run:bool option) = None)
() : request_commit = {
confirm;
confirm_timeout;
comment;
+ dry_run;
}
let rec default_request_rollback
@@ -442,12 +445,14 @@ type request_commit_mutable = {
mutable confirm : bool option;
mutable confirm_timeout : int32 option;
mutable comment : string option;
+ mutable dry_run : bool option;
}
let default_request_commit_mutable () : request_commit_mutable = {
confirm = None;
confirm_timeout = None;
comment = None;
+ dry_run = None;
}
type request_rollback_mutable = {
@@ -668,6 +673,7 @@ let rec pp_request_commit fmt (v:request_commit) =
Pbrt.Pp.pp_record_field ~first:true "confirm" (Pbrt.Pp.pp_option Pbrt.Pp.pp_bool) fmt v.confirm;
Pbrt.Pp.pp_record_field ~first:false "confirm_timeout" (Pbrt.Pp.pp_option Pbrt.Pp.pp_int32) fmt v.confirm_timeout;
Pbrt.Pp.pp_record_field ~first:false "comment" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.comment;
+ Pbrt.Pp.pp_record_field ~first:false "dry_run" (Pbrt.Pp.pp_option Pbrt.Pp.pp_bool) fmt v.dry_run;
in
Pbrt.Pp.pp_brk pp_i fmt ()
@@ -936,6 +942,12 @@ let rec encode_pb_request_commit (v:request_commit) encoder =
Pbrt.Encoder.key 3 Pbrt.Bytes encoder;
| None -> ();
end;
+ begin match v.dry_run with
+ | Some x ->
+ Pbrt.Encoder.bool x encoder;
+ Pbrt.Encoder.key 4 Pbrt.Varint encoder;
+ | None -> ();
+ end;
()
let rec encode_pb_request_rollback (v:request_rollback) encoder =
@@ -1435,12 +1447,18 @@ let rec decode_pb_request_commit d =
end
| Some (3, pk) ->
Pbrt.Decoder.unexpected_payload "Message(request_commit), field(3)" pk
+ | Some (4, Pbrt.Varint) -> begin
+ v.dry_run <- Some (Pbrt.Decoder.bool d);
+ end
+ | Some (4, pk) ->
+ Pbrt.Decoder.unexpected_payload "Message(request_commit), field(4)" pk
| Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
done;
({
confirm = v.confirm;
confirm_timeout = v.confirm_timeout;
comment = v.comment;
+ dry_run = v.dry_run;
} : request_commit)
let rec decode_pb_request_rollback d =
diff --git a/src/vyconf_pbt.mli b/src/vyconf_pbt.mli
index 7371d18..7189a7a 100644
--- a/src/vyconf_pbt.mli
+++ b/src/vyconf_pbt.mli
@@ -60,6 +60,7 @@ type request_commit = {
confirm : bool option;
confirm_timeout : int32 option;
comment : string option;
+ dry_run : bool option;
}
type request_rollback = {
@@ -242,6 +243,7 @@ val default_request_commit :
?confirm:bool option ->
?confirm_timeout:int32 option ->
?comment:string option ->
+ ?dry_run:bool option ->
unit ->
request_commit
(** [default_request_commit ()] is the default value for type [request_commit] *)
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index d3e4216..fc47bf6 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -163,7 +163,7 @@ let delete world token (req: request_delete) =
response_tmpl
with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)}
-let commit world token (_req: request_commit) =
+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
@@ -172,7 +172,8 @@ let commit world token (_req: request_commit) =
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 commit_data = CC.make_commit_data rt at wt token 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%lwt received_commit_data = VC.do_commit commit_data in
let%lwt result_commit_data =
Lwt.return (CC.commit_update received_commit_data)
@@ -189,7 +190,9 @@ let commit world token (_req: request_commit) =
| false ->
Lwt.return {response_tmpl with status=Internal_error; error=(Some out)}
| true ->
- world.Session.running_config <- result_commit_data.config_result;
+ (* partial commit *)
+ if not req_dry_run then
+ world.Session.running_config <- result_commit_data.config_result;
let success, msg_str =
result_commit_data.result.success, result_commit_data.result.out
in