Skip to content

Commit 6cc4afa

Browse files
committed
idl/datamodel_errors: add reason to ha_operation_would_break_failover_plan
This allows users to better see the cause of this error without having to go to the logs of the host running the operation. Also remove the additional logline now that the reason is going to be logged as part of the error. Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent e3d4f34 commit 6cc4afa

File tree

6 files changed

+59
-50
lines changed

6 files changed

+59
-50
lines changed

ocaml/idl/datamodel_errors.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ let _ =
16041604
must be physically present via a currently_attached PIF on every host."
16051605
() ;
16061606

1607-
error Api_errors.ha_operation_would_break_failover_plan []
1607+
error Api_errors.ha_operation_would_break_failover_plan ["reason"]
16081608
~doc:
16091609
"This operation cannot be performed because it would invalidate VM \
16101610
failover planning such that the system would be unable to guarantee to \

ocaml/xapi/xapi_ha_vm_failover.ml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,12 +1223,13 @@ let assert_configuration_change_preserves_ha_plan ~__context c =
12231223
"assert_configuration_change_preserves_ha_plan: plan exists after \
12241224
change"
12251225
| Plan_exists_excluding_non_agile_VMs | No_plan_exists ->
1226-
debug
1226+
let reason =
12271227
"assert_configuration_change_preserves_ha_plan: proposed change \
1228-
breaks plan" ;
1228+
breaks plan"
1229+
in
12291230
raise
1230-
(Api_errors.Server_error
1231-
(Api_errors.ha_operation_would_break_failover_plan, [])
1231+
Api_errors.(
1232+
Server_error (ha_operation_would_break_failover_plan, [reason])
12321233
)
12331234
)
12341235

@@ -1413,16 +1414,19 @@ let restart_auto_run_vms ~__context ~last_live_set ~live_set n =
14131414
let open TaskChains.Infix in
14141415
(* execute the plan *)
14151416
Helpers.call_api_functions ~__context (fun rpc session_id ->
1416-
(* Helper function to start a VM somewhere. If the HA overcommit protection stops us then disable it and try once more.
1417-
Returns true if the VM was restarted and false otherwise. *)
1417+
(* Helper function to start a VM somewhere. If the HA overcommit
1418+
protection stops us then disable it and try once more. Returns true if
1419+
the VM was restarted and false otherwise. *)
14181420
let restart_vm vm ?host () =
14191421
let go () =
14201422
( if Xapi_fist.simulate_restart_failure () then
14211423
match Random.int 3 with
14221424
| 0 ->
1425+
let reason = "Simulated restart failure" in
14231426
raise
1424-
(Api_errors.Server_error
1425-
(Api_errors.ha_operation_would_break_failover_plan, [])
1427+
Api_errors.(
1428+
Server_error
1429+
(ha_operation_would_break_failover_plan, [reason])
14261430
)
14271431
| 1 ->
14281432
raise
@@ -1579,10 +1583,11 @@ let restart_auto_run_vms ~__context ~last_live_set ~live_set n =
15791583
in
15801584
gc_table last_start_attempt ;
15811585
gc_table restart_failed ;
1582-
(* Consider restarting the best-effort VMs we *think* have failed (but we might get this wrong --
1583-
ok since this is 'best-effort'). NOTE we do not use the restart_vm function above as this will mark the
1584-
pool as overcommitted if an HA_OPERATION_WOULD_BREAK_FAILOVER_PLAN is received (although this should never
1585-
happen it's better safe than sorry) *)
1586+
(* Consider restarting the best-effort VMs we *think* have failed (but we
1587+
might get this wrong -- ok since this is 'best-effort'). NOTE we do
1588+
not use the restart_vm function above as this will mark the pool as
1589+
overcommitted if an HA_OPERATION_WOULD_BREAK_FAILOVER_PLAN is received
1590+
(although this should never happen it's better safe than sorry) *)
15861591
let is_best_effort r =
15871592
r.API.vM_ha_restart_priority = Constants.ha_restart_best_effort
15881593
&& r.API.vM_power_state = `Halted

ocaml/xapi/xapi_pbd.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ let abort_if_storage_attached_to_protected_vms ~__context ~self =
113113
List.iter
114114
(fun vbd ->
115115
let vdi = Db.VBD.get_VDI ~__context ~self:vbd in
116-
if List.mem vdi vdis then (
117-
warn
118-
"PBD.unplug will make protected VM %s not agile since it has a \
119-
VBD attached to VDI %s"
120-
(Ref.string_of vm_ref) (Ref.string_of vdi) ;
116+
if List.mem vdi vdis then
117+
let reason =
118+
Printf.sprintf
119+
"PBD.unplug will make protected VM %s not agile since it has \
120+
a VBD attached to VDI %s"
121+
(Ref.string_of vm_ref) (Ref.string_of vdi)
122+
in
121123
raise
122-
(Api_errors.Server_error
123-
(Api_errors.ha_operation_would_break_failover_plan, [])
124+
Api_errors.(
125+
Server_error (ha_operation_would_break_failover_plan, [reason])
124126
)
125-
)
126127
)
127128
vbds
128129
)

ocaml/xapi/xapi_pif.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,17 @@ let abort_if_network_attached_to_protected_vms ~__context ~self =
270270
let vms = List.map (fun vif -> Db.VIF.get_VM ~__context ~self:vif) vifs in
271271
List.iter
272272
(fun vm ->
273-
if Helpers.is_xha_protected ~__context ~self:vm then (
274-
warn
275-
"PIF.unplug will make protected VM %s not agile since it has a VIF \
276-
attached to network %s"
277-
(Ref.string_of vm) (Ref.string_of net) ;
273+
if Helpers.is_xha_protected ~__context ~self:vm then
274+
let reason =
275+
Printf.sprintf
276+
"PIF.unplug will make protected VM %s not agile since it has a \
277+
VIF attached to network %s"
278+
(Ref.string_of vm) (Ref.string_of net)
279+
in
278280
raise
279-
(Api_errors.Server_error
280-
(Api_errors.ha_operation_would_break_failover_plan, [])
281+
Api_errors.(
282+
Server_error (ha_operation_would_break_failover_plan, [reason])
281283
)
282-
)
283284
)
284285
vms
285286

ocaml/xapi/xapi_vbd_helpers.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,15 @@ let assert_doesnt_make_vm_non_agile ~__context ~vm ~vdi =
368368
&& (not (Db.Pool.get_ha_allow_overcommit ~__context ~self:pool))
369369
&& Helpers.is_xha_protected ~__context ~self:vm
370370
&& not properly_shared
371-
then (
372-
warn "Attaching VDI %s makes VM %s not agile" (Ref.string_of vdi)
373-
(Ref.string_of vm) ;
371+
then
372+
let reason =
373+
Printf.sprintf "Attaching VDI %s makes VM %s not agile"
374+
(Ref.string_of vdi) (Ref.string_of vm)
375+
in
374376
raise
375-
(Api_errors.Server_error
376-
(Api_errors.ha_operation_would_break_failover_plan, [])
377+
Api_errors.(
378+
Server_error (ha_operation_would_break_failover_plan, [reason])
377379
)
378-
)
379380

380381
let update_allowed_operations ~__context ~self : unit =
381382
let all = Db.VBD.get_record_internal ~__context ~self in

ocaml/xapi/xapi_vif_helpers.ml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,21 @@ let create ~__context ~device ~network ~vM ~mAC ~mTU ~other_config
267267
raise (Api_errors.Server_error (Api_errors.mac_invalid, [mAC])) ;
268268
(* Make people aware that non-shared networks being added to VMs makes them not agile *)
269269
let pool = Helpers.get_pool ~__context in
270-
if
271-
true
272-
&& Db.Pool.get_ha_enabled ~__context ~self:pool
273-
&& (not (Db.Pool.get_ha_allow_overcommit ~__context ~self:pool))
274-
&& Helpers.is_xha_protected ~__context ~self:vM
275-
&& not (Agility.is_network_properly_shared ~__context ~self:network)
276-
then (
277-
warn "Creating VIF %s makes VM %s not agile" (Ref.string_of ref)
278-
(Ref.string_of vM) ;
279-
raise
280-
(Api_errors.Server_error
281-
(Api_errors.ha_operation_would_break_failover_plan, [])
282-
)
270+
( if
271+
true
272+
&& Db.Pool.get_ha_enabled ~__context ~self:pool
273+
&& (not (Db.Pool.get_ha_allow_overcommit ~__context ~self:pool))
274+
&& Helpers.is_xha_protected ~__context ~self:vM
275+
&& not (Agility.is_network_properly_shared ~__context ~self:network)
276+
then
277+
let reason =
278+
Printf.sprintf "Creating VIF %s makes VM %s not agile"
279+
(Ref.string_of ref) (Ref.string_of vM)
280+
in
281+
raise
282+
Api_errors.(
283+
Server_error (ha_operation_would_break_failover_plan, [reason])
284+
)
283285
) ;
284286
(* Check to make sure the device is unique *)
285287
Xapi_stdext_threads.Threadext.Mutex.execute m (fun () ->
@@ -291,8 +293,7 @@ let create ~__context ~device ~network ~vM ~mAC ~mTU ~other_config
291293
in
292294
let new_device = int_of_string device in
293295
if List.exists (fun (_, d) -> d = new_device) all_vifs_with_devices then
294-
raise
295-
(Api_errors.Server_error (Api_errors.device_already_exists, [device])) ;
296+
raise Api_errors.(Server_error (device_already_exists, [device])) ;
296297

297298
(* If the VM uses a PVS_proxy, then the proxy _must_ be associated with
298299
the VIF that has the lowest device number. Check that the new VIF

0 commit comments

Comments
 (0)