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
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
} 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
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 ()
+