Skip to content

Commit 84e7574

Browse files
committed
CA-233915 turn post-op assertions that VM is "Running" into warnings
Most VM operations that change the power state of a VM include assertions that the power state is indeed as expected after that operation. Such a check can issue a false alarm in some cases and this commit removes it from operations that change the power state to "running" but still logs any unexpected power state: start unpause reboot resume The problem was that the assertion was too naive when changing the state into running: when a VM quickly changes its state once it is running (e.g., by rebooting) the assertion can fail because it can be too late and would find the VM not running as expected. Assertions after operations that change the state not to running are kept by this commit. Signed-off-by: Christian Lindig <[email protected]>
1 parent 0e5281b commit 84e7574

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

ocaml/xapi/xapi_xenops.ml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ module Rrdd = Rrd_client.Client
2828
open Xenops_interface
2929
open Xapi_xenops_queue
3030

31+
let check_power_state_is ~__context ~self ~expected =
32+
if expected <> `Running then
33+
Xapi_vm_lifecycle.assert_power_state_is ~__context ~self ~expected
34+
else
35+
(* CA-233915: only warn about unexpected power state - the check
36+
* is too naive to make it an assertion
37+
*)
38+
let actual = Db.VM.get_power_state ~__context ~self in
39+
if actual <> expected then
40+
warn "Potential problem: VM %s in power state '%s' when expecting '%s'"
41+
(Db.VM.get_uuid ~__context ~self)
42+
(Record_util.power_to_string expected)
43+
(Record_util.power_to_string actual)
44+
3145
let event_wait queue_name dbg ?from p =
3246
let finished = ref false in
3347
let event_id = ref from in
@@ -2292,7 +2306,7 @@ let unpause ~__context ~self =
22922306
let module Client = (val make_client queue_name : XENOPS) in
22932307
Client.VM.unpause dbg id |> sync_with_task __context queue_name;
22942308
Events_from_xenopsd.wait queue_name dbg id ();
2295-
Xapi_vm_lifecycle.assert_power_state_is ~__context ~self ~expected:`Running
2309+
check_power_state_is ~__context ~self ~expected:`Running
22962310
)
22972311

22982312
let request_rdp ~__context ~self enabled =
@@ -2452,7 +2466,7 @@ let start ~__context ~self paused force =
24522466

24532467
set_resident_on ~__context ~self;
24542468
(* set_resident_on syncs both xenopsd and with the xapi event mechanism *)
2455-
Xapi_vm_lifecycle.assert_power_state_is ~__context ~self ~expected:(if paused then `Paused else `Running)
2469+
check_power_state_is ~__context ~self ~expected:(if paused then `Paused else `Running)
24562470
with e ->
24572471
error "Caught exception starting VM: %s" (string_of_exn e);
24582472
set_resident_on ~__context ~self;
@@ -2498,7 +2512,7 @@ let reboot ~__context ~self timeout =
24982512
(fun () ->
24992513
Events_from_xenopsd.wait queue_name dbg id ())
25002514
in
2501-
Xapi_vm_lifecycle.assert_power_state_is ~__context ~self ~expected:`Running
2515+
check_power_state_is ~__context ~self ~expected:`Running
25022516
)
25032517

25042518
let shutdown ~__context ~self timeout =
@@ -2626,7 +2640,7 @@ let resume ~__context ~self ~start_paused ~force =
26262640
(fun rpc session_id ->
26272641
XenAPI.VDI.destroy rpc session_id vdi
26282642
);
2629-
Xapi_vm_lifecycle.assert_power_state_is ~__context ~self ~expected:(if start_paused then `Paused else `Running)
2643+
check_power_state_is ~__context ~self ~expected:(if start_paused then `Paused else `Running)
26302644
)
26312645

26322646
let s3suspend ~__context ~self =

0 commit comments

Comments
 (0)