Browse files

Add test for CA-91480: VM destroy skips missing blobs

Xapi_vm_helpers.destroy would fail if a VM had a reference to a non-existant
blob, which would happen when the VM had been imported. This would prevent the
rest of the function from running, leaving ghost objects in the database after
an import was cancelled.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
  • Loading branch information...
1 parent dbd1565 commit 1fa3fb2d43371660fcb5eac9179ffcd7946ed9ba Mike McClurg committed Oct 26, 2012
Showing with 34 additions and 0 deletions.
  1. +1 −0 ocaml/test/OMakefile
  2. +1 −0 ocaml/test/suite.ml
  3. +32 −0 ocaml/test/test_ca91480.ml
View
1 ocaml/test/OMakefile
@@ -27,5 +27,6 @@ OCAML_OBJS = \
test_basic \
test_pool_db_backup \
test_xapi_db_upgrade \
+ test_ca91480 \
OCamlProgram(suite, suite $(OCAML_OBJS) )
View
1 ocaml/test/suite.ml
@@ -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
32 ocaml/test/test_ca91480.ml
@@ -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;
+ ]

0 comments on commit 1fa3fb2

Please sign in to comment.