]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Add a unit test for the database upgrade_bios_strings logic.
authorDavid Scott <dave.scott@eu.citrix.com>
Wed, 26 Jan 2011 17:39:06 +0000 (17:39 +0000)
committerDavid Scott <dave.scott@eu.citrix.com>
Wed, 26 Jan 2011 17:39:06 +0000 (17:39 +0000)
Signed-off-by: David Scott <dave.scott@eu.citrix.com>
ocaml/xapi/helpers.ml
ocaml/xapi/xapi_db_upgrade_test.ml

index adf1bf278bd746d4f2f229b6f4e535a7875d1c62..6e8c0255de93c1421d80d05dd7d0eab25d5fe837 100644 (file)
@@ -67,21 +67,9 @@ let get_management_ip_addr () =
 let get_localhost_uuid () =
   Xapi_inventory.lookup Xapi_inventory._installation_uuid
 
-let localhost_ref_m = Mutex.create ()
-let localhost_ref = ref Ref.null
-  
 let get_localhost ~__context : API.ref_host  =
-  Mutex.execute localhost_ref_m (fun () -> 
-    if !localhost_ref <> Ref.null then
-      !localhost_ref
-    else
-      let me = get_localhost_uuid () in
-      let my_ref = Db.Host.get_internal_records_where ~__context ~expr:(Eq (Field "uuid", Literal me)) in
-      if List.length my_ref <> 1 then
-       failwith (sprintf "Found %d hosts which claim to be localhost" (List.length my_ref));
-      let my_ref = fst (List.hd my_ref) in
-      localhost_ref := my_ref;
-      my_ref)
+    let uuid = get_localhost_uuid () in
+       Db.Host.get_by_uuid ~__context ~uuid
 
 let make_rpc ~__context xml = 
     let subtask_of = Ref.string_of (Context.get_task_id __context) in
index 5c748af4eb8b1ff2b81762690da9214c1bdc3462..ef93737e796eca8b28b3d4a4e51b874927816ea7 100644 (file)
@@ -14,7 +14,8 @@
 
 open Xapi_db_upgrade
 
-let upgrade_vm_memory_for_dmc () = 
+(** Make a simple in-memory database containing a single host and dom0 VM record. *)
+let make_test_database () = 
        let db = Db_upgrade.generic_database_upgrade (Db_cache_types.Database.make (Schema.of_datamodel ())) in
        let db_ref = Db_ref.in_memory (ref (ref db)) in
        let __context = Context.make ~database:db_ref "upgrade_vm_memory_for_dmc" in
@@ -38,6 +39,10 @@ let upgrade_vm_memory_for_dmc () =
        } in
        Dbsync_slave.create_localhost ~__context host_info;
        Create_misc.ensure_domain_zero_records ~__context host_info;
+       __context
+
+let upgrade_vm_memory_for_dmc () = 
+       let __context = make_test_database () in
 
        let self = List.hd (Db.VM.get_all ~__context) in
 
@@ -73,6 +78,25 @@ let upgrade_vm_memory_for_dmc () =
        then failwith "upgrade_vm_memory_for_dmc: memory_static_min > memory_static_max";
        Printf.printf "upgrade_vm_memory_for_dmc: OK\n"
 
+let upgrade_bios () = 
+
+       let check inventory bios_strings = 
+               Unixext.mkdir_safe "/var/tmp" 0o755;
+               Unixext.write_string_to_file "/var/tmp/.previousInventory" inventory;
+               let __context = make_test_database () in
+               upgrade_bios_strings.fn ~__context; 
+               let _, vm_r = List.hd (Db.VM.get_all_records ~__context) in
+               if vm_r.API.vM_bios_strings <> bios_strings
+               then failwith "bios strings upgrade" in
+       
+       check "OEM_MANUFACTURER=Dell" Xapi_globs.old_dell_bios_strings;
+       check "OEM_MANUFACTURER=HP" Xapi_globs.old_hp_bios_strings;
+       check "" Xapi_globs.generic_bios_strings;
+       Unixext.unlink_safe "/var/tmp/.previousInventory";
+       Printf.printf "upgrade_bios: OK\n"
+
 let _ = 
-       upgrade_vm_memory_for_dmc ()
+       upgrade_vm_memory_for_dmc ();
+       upgrade_bios ()
        
+