From: David Scott Date: Wed, 26 Jan 2011 17:39:06 +0000 (+0000) Subject: Add a unit test for the database upgrade_bios_strings logic. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d15615f9fd7cb0270533858134062d91d877b519;p=xcp%2Fxen-api.git Add a unit test for the database upgrade_bios_strings logic. Signed-off-by: David Scott --- diff --git a/ocaml/xapi/helpers.ml b/ocaml/xapi/helpers.ml index adf1bf27..6e8c0255 100644 --- a/ocaml/xapi/helpers.ml +++ b/ocaml/xapi/helpers.ml @@ -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 diff --git a/ocaml/xapi/xapi_db_upgrade_test.ml b/ocaml/xapi/xapi_db_upgrade_test.ml index 5c748af4..ef93737e 100644 --- a/ocaml/xapi/xapi_db_upgrade_test.ml +++ b/ocaml/xapi/xapi_db_upgrade_test.ml @@ -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 () +