Skip to content

Commit 84d4a78

Browse files
authored
Merge pull request xapi-project#238 from jonludlam/CA-229331-ely-bugfix
CA-229331: Fixes to compute_evacuation_plan
2 parents d052406 + 30f97ff commit 84d4a78

File tree

5 files changed

+6
-43
lines changed

5 files changed

+6
-43
lines changed

ocaml/idl/datamodel.ml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,25 +2884,11 @@ let host_get_vms_which_prevent_evacuation = call
28842884
~in_product_since:rel_orlando
28852885
~name:"get_vms_which_prevent_evacuation"
28862886
~doc:"Return a set of VMs which prevent the host being evacuated, with per-VM error codes"
2887-
~lifecycle:[
2888-
Published, rel_orlando, "The call returns for each VM all the reasons why a host cannot be evacuated";
2889-
Changed, rel_ely, "The call now retuns only one reason per VM."
2890-
]
28912887
~params:[Ref _host, "self", "The host to query"]
28922888
~result:(Map(Ref _vm, Set(String)), "VMs which block evacuation together with reasons")
28932889
~allowed_roles:_R_READ_ONLY
28942890
()
28952891

2896-
let host_get_vms_which_prevent_evacuation_all = call
2897-
~in_product_since:rel_ely
2898-
~name:"get_vms_which_prevent_evacuation_all"
2899-
~doc:"Return a set of VMs which prevent the host being evacuated, with per-VM error codes. This call returns for each VM all the reasons why a host cannot be evacuated."
2900-
~params:[Ref _host, "self", "The host to query"]
2901-
~hide_from_docs:true
2902-
~result:(Map(Ref _vm, Set(String)), "VMs which block evacuation together with reasons")
2903-
~allowed_roles:_R_READ_ONLY
2904-
()
2905-
29062892
let host_evacuate = call
29072893
~in_product_since:rel_miami
29082894
~name:"evacuate"
@@ -4857,7 +4843,6 @@ let host =
48574843
host_forget_data_source_archives;
48584844
host_assert_can_evacuate;
48594845
host_get_vms_which_prevent_evacuation;
4860-
host_get_vms_which_prevent_evacuation_all;
48614846
host_get_uncooperative_resident_VMs;
48624847
host_get_uncooperative_domains;
48634848
host_evacuate;

ocaml/xapi/cli_operations.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,10 +3170,7 @@ let host_evacuate printer rpc session_id params =
31703170
let host_get_vms_which_prevent_evacuation printer rpc session_id params =
31713171
let uuid = List.assoc "uuid" params in
31723172
let host = Client.Host.get_by_uuid rpc session_id uuid in
3173-
(* Although the API call get_vms_which_prevent_evacuation was changed within CA-220610
3174-
to return per VM only one reason why the host cannot be evacuated, it was decided
3175-
the CLI call should still return all the reasons *)
3176-
let vms = Client.Host.get_vms_which_prevent_evacuation_all rpc session_id host in
3173+
let vms = Client.Host.get_vms_which_prevent_evacuation rpc session_id host in
31773174

31783175
let op (vm, error) =
31793176
let error = String.concat "," error in

ocaml/xapi/message_forwarding.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,10 +2278,6 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
22782278
info "Host.get_vms_which_prevent_evacuation: host = '%s'" (host_uuid ~__context self);
22792279
Local.Host.get_vms_which_prevent_evacuation ~__context ~self
22802280

2281-
let get_vms_which_prevent_evacuation_all ~__context ~self =
2282-
info "Host.get_vms_which_prevent_evacuation_all: host = '%s'" (host_uuid ~__context self);
2283-
Local.Host.get_vms_which_prevent_evacuation_all ~__context ~self
2284-
22852281
let evacuate ~__context ~host =
22862282
info "Host.evacuate: host = '%s'" (host_uuid ~__context host);
22872283
(* Block call if this would break our VM restart plan (because the body of this sets enabled to false) *)

ocaml/xapi/xapi_host.ml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ let compute_evacuation_plan_no_wlb ~__context ~host =
225225
then
226226
begin
227227
List.iter (fun (vm, _) ->
228-
Hashtbl.add plans vm (Error (Api_errors.no_hosts_available, [ Ref.string_of vm ])))
228+
Hashtbl.replace plans vm (Error (Api_errors.no_hosts_available, [ Ref.string_of vm ])))
229229
all_user_vms ;
230230
plans
231231
end
@@ -269,8 +269,8 @@ let compute_evacuation_plan_no_wlb ~__context ~host =
269269
let plan = Xapi_ha_vm_failover.compute_evacuation_plan ~__context (List.length all_hosts) target_hosts migratable_vms in
270270
(* Check if the plan was actually complete: if some VMs are missing it means there wasn't enough memory *)
271271
let vms_handled = List.map fst plan in
272-
let vms_missing = List.filter (fun x -> not(List.mem x vms_handled)) (List.map fst protected_vms) in
273-
List.iter (fun vm -> Hashtbl.add plans vm (Error (Api_errors.host_not_enough_free_memory, [ Ref.string_of vm ]))) vms_missing;
272+
let vms_missing = List.filter (fun x -> not(List.mem x vms_handled)) (List.map fst migratable_vms) in
273+
List.iter (fun vm -> Hashtbl.replace plans vm (Error (Api_errors.host_not_enough_free_memory, [ Ref.string_of vm ]))) vms_missing;
274274

275275
(* Now for each VM we did place, verify storage and network visibility. *)
276276
List.iter (fun (vm, host) ->
@@ -279,7 +279,7 @@ let compute_evacuation_plan_no_wlb ~__context ~host =
279279
try Xapi_vm_helpers.assert_can_boot_here ~__context ~self:vm ~host ~snapshot ~do_memory_check:false ()
280280
with (Api_errors.Server_error (code, params)) -> Hashtbl.replace plans vm (Error (code, params))
281281
end;
282-
if not(Hashtbl.mem plans vm) then Hashtbl.add plans vm (Migrate host)
282+
if not(Hashtbl.mem plans vm) then Hashtbl.replace plans vm (Migrate host)
283283
) plan;
284284
plans
285285
end
@@ -292,22 +292,10 @@ let assert_can_evacuate ~__context ~host =
292292
if errors <> []
293293
then raise (Api_errors.Server_error (Api_errors.cannot_evacuate_host, [ String.concat "|" errors ]))
294294

295-
(* New Orlando style function which returns a Map *)
296-
let get_vms_which_prevent_evacuation_all ~__context ~self =
297-
let plans = compute_evacuation_plan_no_wlb ~__context ~host:self in
298-
Hashtbl.fold (fun vm plan acc -> match plan with Error(code, params) -> (vm, (code :: params)) :: acc | _ -> acc) plans []
299-
300295
(* New Orlando style function which returns a Map *)
301296
let get_vms_which_prevent_evacuation ~__context ~self =
302297
let plans = compute_evacuation_plan_no_wlb ~__context ~host:self in
303-
let get_error_per_vm vm plan acc =
304-
match plan with
305-
| Error(code, params) ->
306-
if List.exists (fun (x,_) -> x = vm) acc then acc
307-
else (vm, (code :: params)) :: acc
308-
| _ -> acc
309-
in
310-
Hashtbl.fold get_error_per_vm plans []
298+
Hashtbl.fold (fun vm plan acc -> match plan with Error(code, params) -> (vm, (code :: params)) :: acc | _ -> acc) plans []
311299

312300
let compute_evacuation_plan_wlb ~__context ~self =
313301
(* We treat xapi as primary when it comes to "hard" errors, i.e. those that aren't down to memory constraints. These are things like

ocaml/xapi/xapi_host.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ val notify : __context:Context.t -> ty:string -> params:string -> unit
4242
val assert_can_evacuate : __context:Context.t -> host:API.ref_host -> unit
4343
val get_vms_which_prevent_evacuation :
4444
__context:Context.t -> self:API.ref_host -> (API.ref_VM * string list) list
45-
val get_vms_which_prevent_evacuation_all :
46-
__context:Context.t -> self:API.ref_host -> (API.ref_VM * string list) list
47-
4845
val evacuate : __context:Context.t -> host:API.ref_host -> unit
4946
val retrieve_wlb_evacuate_recommendations :
5047
__context:Context.t -> self:API.ref_host -> (API.ref_VM * string list) list

0 commit comments

Comments
 (0)