Skip to content

Commit bcb1845

Browse files
committed
fixup! CP-44103: Ordering network devices - ordering logic
Signed-off-by: Ming Lu <[email protected]>
1 parent 79254e5 commit bcb1845

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

ocaml/networkd/lib/network_device_order.ml

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -487,40 +487,33 @@ let generate_order ~(currents : Dev.t list) ~(rules : Rule.t list)
487487
OrderedDev.assert_no_duplicate_mac new_order ;
488488
new_order
489489

490-
let generate ?(force = false) interface_order =
491-
match interface_order with
492-
| None ->
493-
None
494-
| Some last_order ->
495-
let rules, last_order =
496-
match (last_order, force) with
497-
| [], _ | _ :: _, true ->
498-
(Rule.rules_of_file ~path:initial_rules_file_path, [])
499-
| (_ :: _ as last_order), false ->
500-
([], last_order)
501-
in
502-
let currents = Dev.get_all () in
503-
currents
504-
|> List.iter (fun x ->
505-
debug "%s current: %s" __FUNCTION__ (Dev.to_string x)
506-
) ;
507-
let new_order = generate_order ~currents ~rules ~last_order in
508-
new_order
509-
|> List.iter (fun x ->
510-
debug "%s new order: %s" __FUNCTION__ (OrderedDev.to_string x)
511-
) ;
512-
513-
(* Find the NICs whose name changes *)
514-
let changes =
515-
let m = OrderedDev.map_by_position last_order in
516-
List.fold_left
517-
(fun acc {position; name= curr; _} ->
518-
match IntMap.find_opt position m with
519-
| Some {name= last; _} when last <> curr ->
520-
(last, curr) :: acc
521-
| _ ->
522-
acc
523-
)
524-
[] new_order
525-
in
526-
Some (new_order, changes)
490+
let generate last_order =
491+
let rules, last_order =
492+
if last_order = [] then
493+
(Rule.rules_of_file ~path:initial_rules_file_path, [])
494+
else
495+
([], last_order)
496+
in
497+
let currents = Dev.get_all () in
498+
currents
499+
|> List.iter (fun x -> debug "%s current: %s" __FUNCTION__ (Dev.to_string x)) ;
500+
let new_order = generate_order ~currents ~rules ~last_order in
501+
new_order
502+
|> List.iter (fun x ->
503+
debug "%s new order: %s" __FUNCTION__ (OrderedDev.to_string x)
504+
) ;
505+
506+
(* Find the NICs whose name changes *)
507+
let changes =
508+
let m = OrderedDev.map_by_position last_order in
509+
List.fold_left
510+
(fun acc {position; name= curr; _} ->
511+
match IntMap.find_opt position m with
512+
| Some {name= last; _} when last <> curr ->
513+
(last, curr) :: acc
514+
| _ ->
515+
acc
516+
)
517+
[] new_order
518+
in
519+
(new_order, changes)

ocaml/networkd/lib/network_device_order.mli

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ module OrderedDev : sig
7676
exception Duplicate_mac_address
7777
end
7878

79-
val generate :
80-
?force:bool
81-
-> OrderedDev.t list option
82-
-> (OrderedDev.t list * (string * string) list) option
83-
(** [generate force ()] is to generate order, return the order and a list for device name changes (old_name, new_name).
84-
When the [force] is [true], use the initial rules only. By default it is [false]. *)
79+
val generate : OrderedDev.t list -> OrderedDev.t list * (string * string) list
80+
(** [generate last_order] is to generate an order based on [last_order], return the new order and a list for device name changes (old_name, new_name). *)
8581

8682
(* Below is exposed only for unit tests *)
8783

0 commit comments

Comments
 (0)