Permalink
Browse files

Merge pull request #911 from mcclurmc/ca91480-import-cleanup-vm-destroy

  • Loading branch information...
2 parents 4474f90 + fc9a4bf commit ffa3d3742fc2cb54b361ff19bf73c20e881fdc26 xen-git committed Nov 9, 2012
Showing with 39 additions and 1 deletion.
  1. +1 −0 ocaml/test/OMakefile
  2. +1 −0 ocaml/test/suite.ml
  3. +32 −0 ocaml/test/test_ca91480.ml
  4. +5 −1 ocaml/xapi/xapi_vm_helpers.ml
View
@@ -27,5 +27,6 @@ OCAML_OBJS = \
test_basic \
test_pool_db_backup \
test_xapi_db_upgrade \
+ test_ca91480 \
OCamlProgram(suite, suite $(OCAML_OBJS) )
View
@@ -45,6 +45,7 @@ let base_suite =
test_basic;
test_db_backup;
test_db_upgrade;
+ Test_ca91480.test;
]
let _ = run_test_tt_main base_suite
View
@@ -0,0 +1,32 @@
+(* Fixture: Create DB with VM. VM has records for Blobs, Appliances,
+ VBDs, VIFs, VGPUs, PCIs, VM_metrics, and VM_guest_metrics, but none
+ of these objects should actually exist in the DB. *)
+
+open OUnit
+open Test_common
+
+let setup_fixture () =
+ let __context = make_test_database () in
+ let self = make_vm ~__context () in
+
+ let fake_v f = f ~__context ~self ~value:(Ref.make ())
+ and fake_m f = f ~__context ~self ~key:"fake" ~value:(Ref.make ())
+ and fake_l f = f ~__context ~self ~value:[(Ref.make ())] in
+
+ fake_m Db.VM.add_to_blobs ;
+ fake_v Db.VM.set_appliance ;
+ fake_l Db.VM.set_attached_PCIs ;
+ fake_v Db.VM.set_metrics ;
+ fake_v Db.VM.set_guest_metrics ;
+
+ __context, self
+
+let test_vm_destroy () =
+ let __context, self = setup_fixture () in
+ Xapi_vm_helpers.destroy ~__context ~self
+
+let test =
+ "test_ca91480" >:::
+ [
+ "test_vm_destroy" >:: test_vm_destroy;
+ ]
@@ -151,8 +151,12 @@ let destroy ~__context ~self =
(* given the call to 'assert_operation_valid' *)
debug "VM.destroy: deleting DB records";
+ (* Should we be destroying blobs? It's possible to create a blob and then
+ add its reference to multiple objects. Perhaps we want to just leave the
+ blob? Or only delete it if there is no other reference to it? Is that
+ even possible to know? *)
let blobs = Db.VM.get_blobs ~__context ~self in
- List.iter (fun (name,_ref) -> Xapi_blob.destroy ~__context ~self:_ref) blobs;
+ List.iter (fun (_,self) -> try Xapi_blob.destroy ~__context ~self with _ -> ()) blobs;
let other_config = Db.VM.get_other_config ~__context ~self in
if ((List.mem_assoc Xapi_globs.default_template_key other_config) &&

0 comments on commit ffa3d37

Please sign in to comment.