Skip to content

Commit d4ce578

Browse files
committed
Handle bridge-does-not-exist errors from OVS
Avoid log spam, and raise the new Bridge_does_not_exist error. Signed-off-by: Rob Hoes <[email protected]>
1 parent a9d1b90 commit d4ce578

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/network_utils.ml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,28 @@ module Proc = struct
905905
end
906906

907907
module Ovs = struct
908+
let match_multiple patterns s =
909+
let rec loop = function
910+
| [] -> None
911+
| pattern :: rest ->
912+
match Re.exec_opt pattern s with
913+
| Some groups -> Some groups
914+
| None -> loop rest
915+
in
916+
loop patterns
917+
918+
let patterns = List.map Re.Perl.compile_pat [
919+
"no bridge named (.*)\n";
920+
"no row \"(.*)\" in table Bridge"
921+
]
922+
923+
let error_handler script args stdout stderr exn =
924+
match match_multiple patterns stderr with
925+
| Some groups ->
926+
let bridge = Re.Group.get groups 1 in
927+
raise (Network_error (Bridge_does_not_exist bridge))
928+
| None ->
929+
default_error_handler script args stdout stderr exn
908930

909931
module Cli : sig
910932
val vsctl : string list -> string
@@ -915,12 +937,12 @@ module Ovs = struct
915937
let s = Semaphore.create 5
916938
let vsctl args =
917939
Semaphore.execute s (fun () ->
918-
call_script ovs_vsctl ("--timeout=20" :: args)
940+
call_script ~on_error:error_handler ovs_vsctl ("--timeout=20" :: args)
919941
)
920942
let ofctl args =
921-
call_script ovs_ofctl args
943+
call_script ~on_error:error_handler ovs_ofctl args
922944
let appctl args =
923-
call_script ovs_appctl args
945+
call_script ~on_error:error_handler ovs_appctl args
924946
end
925947

926948
module type Cli_S = module type of Cli

0 commit comments

Comments
 (0)