Skip to content

Commit b014ce1

Browse files
lindigChristian Lindig
authored andcommitted
CP-308455 VM.sysprep CA-414158 wait for "action" key to disappear (xapi-project#6604)
Change when a CD is ejected because ideally the VM is still running at this point: * wait for sysprep no longer being reported as running * eject Make sure we still eject the CD if we hit a timeout before reaching that point. Signed-off-by: Christian Lindig <[email protected]>
1 parent 2d2f5fb commit b014ce1

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

ocaml/xapi/vm_sysprep.ml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type error =
2828
| API_not_enabled
2929
| Other of string
3030
| VM_CDR_not_found
31+
| VM_CDR_eject
3132
| VM_misses_feature
3233
| VM_not_running
3334
| VM_sysprep_timeout
@@ -205,9 +206,18 @@ let find_vdi ~__context ~label =
205206
warn "%s: more than one VDI with label %s" __FUNCTION__ label ;
206207
vdi
207208

209+
(* Ejecting the CD/VDI/ISO may fail with a timeout *)
210+
let eject ~rpc ~session_id ~vbd ~iso =
211+
try
212+
Client.VBD.eject ~rpc ~session_id ~vbd ;
213+
Sys.remove iso
214+
with exn ->
215+
warn "%s: ejecting CD failed: %s" __FUNCTION__ (Printexc.to_string exn) ;
216+
fail VM_CDR_eject
217+
208218
(** notify the VM with [domid] to run sysprep and where to find the
209219
file. *)
210-
let trigger ~domid ~uuid ~timeout =
220+
let trigger ~rpc ~session_id ~domid ~uuid ~timeout ~vbd ~iso =
211221
let open Ezxenstore_core.Xenstore in
212222
let control = Printf.sprintf "/local/domain/%Ld/control/sysprep" domid in
213223
let domain = Printf.sprintf "/local/domain/%Ld" domid in
@@ -217,17 +227,21 @@ let trigger ~domid ~uuid ~timeout =
217227
xs.Xs.write (control // "action") "sysprep" ;
218228
debug "%s: notified domain %Ld" __FUNCTION__ domid ;
219229
try
220-
(* wait for sysprep to start, then domain to dissapear *)
221-
Ezxenstore_core.Watch.(
222-
wait_for ~xs ~timeout:5.0
223-
(value_to_become (control // "action") "running")
224-
) ;
225-
debug "%s: sysprep is runnung; waiting for sysprep to finish"
226-
__FUNCTION__ ;
227-
Ezxenstore_core.Watch.(
228-
wait_for ~xs ~timeout (key_to_disappear (control // "action"))
229-
) ;
230-
debug "%s sysprep is finished" __FUNCTION__ ;
230+
finally
231+
(fun () ->
232+
(* wait for sysprep to start, then domain to dissapear *)
233+
Ezxenstore_core.Watch.(
234+
wait_for ~xs ~timeout:5.0
235+
(value_to_become (control // "action") "running")
236+
) ;
237+
debug "%s: sysprep is running; waiting for sysprep to finish"
238+
__FUNCTION__ ;
239+
Ezxenstore_core.Watch.(
240+
wait_for ~xs ~timeout (key_to_disappear (control // "action"))
241+
)
242+
)
243+
(fun () -> eject ~rpc ~session_id ~vbd ~iso) ;
244+
debug "%s waiting for domain to dissapear" __FUNCTION__ ;
231245
Ezxenstore_core.Watch.(wait_for ~xs ~timeout (key_to_disappear domain)) ;
232246
true
233247
with Ezxenstore_core.Watch.Timeout _ ->
@@ -269,13 +283,8 @@ let sysprep ~__context ~vm ~unattend ~timeout =
269283
call ~__context @@ fun rpc session_id ->
270284
Client.VBD.insert ~rpc ~session_id ~vdi ~vbd ;
271285
Thread.delay !Xapi_globs.vm_sysprep_wait ;
272-
match trigger ~domid ~uuid ~timeout with
286+
match trigger ~rpc ~session_id ~domid ~uuid ~timeout ~vbd ~iso with
273287
| true ->
274-
debug "%s: sysprep running, ejecting CD" __FUNCTION__ ;
275-
Client.VBD.eject ~rpc ~session_id ~vbd ;
276-
Sys.remove iso
288+
()
277289
| false ->
278-
debug "%s: sysprep timeout, ejecting CD" __FUNCTION__ ;
279-
Client.VBD.eject ~rpc ~session_id ~vbd ;
280-
Sys.remove iso ;
281290
fail VM_sysprep_timeout

ocaml/xapi/vm_sysprep.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type error =
1717
| API_not_enabled
1818
| Other of string
1919
| VM_CDR_not_found
20+
| VM_CDR_eject
2021
| VM_misses_feature
2122
| VM_not_running
2223
| VM_sysprep_timeout

ocaml/xapi/xapi_vm.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,8 @@ let sysprep ~__context ~self ~unattend ~timeout =
17251725
)
17261726
| exception Vm_sysprep.Sysprep VM_not_running ->
17271727
raise Api_errors.(Server_error (sysprep, [uuid; "VM is not running"]))
1728+
| exception Vm_sysprep.Sysprep VM_CDR_eject ->
1729+
raise Api_errors.(Server_error (sysprep, [uuid; "VM failed to eject CD"]))
17281730
| exception Vm_sysprep.Sysprep VM_sysprep_timeout ->
17291731
raise
17301732
Api_errors.(

0 commit comments

Comments
 (0)