]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Add a unit test for Pool_db_backup.prepare_database_for_restore.
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/OMakefile
ocaml/xapi/pool_db_backup_test.ml [new file with mode: 0644]
ocaml/xapi/xapi_db_upgrade_test.ml
ocaml/xapi/xapi_test_common.ml [new file with mode: 0644]
ocaml/xapi/xapi_unit_test.ml [new file with mode: 0644]

index 2d463996860d4aaa820ecdd4906e22dae0973ac3..763128b2fbeb0a21dc9a30a65b1f0b631cc9465d 100644 (file)
@@ -243,7 +243,7 @@ XAPI_MODULES = $(COMMON) \
 OCamlProgram(xapi, xapi $(XAPI_MODULES))
 OCamlDocProgram(xapi, xapi $(XAPI_MODULES))
 
-OCamlProgram(xapi_unit_test, xapi_db_upgrade_test $(XAPI_MODULES))
+OCamlProgram(xapi_unit_test, xapi_unit_test xapi_db_upgrade_test pool_db_backup_test xapi_test_common $(XAPI_MODULES))
 
 OCamlProgram(bootloader, bootloader bootloader_test)
 
diff --git a/ocaml/xapi/pool_db_backup_test.ml b/ocaml/xapi/pool_db_backup_test.ml
new file mode 100644 (file)
index 0000000..d07f6ac
--- /dev/null
@@ -0,0 +1,59 @@
+(*
+ * Copyright (C) 2011 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+open Xapi_test_common
+
+let test_prepare_restore () = 
+       let make_context mac1 mac2 host_uuid dom0_uuid = 
+               let __context = make_test_database () in
+               let master = List.hd (Db.Host.get_all ~__context) in
+               Db.Host.set_uuid ~__context ~self:master ~value:host_uuid;
+               List.iter
+                       (fun self -> Db.VM.set_uuid ~__context ~self ~value:dom0_uuid)
+                       (Db.Host.get_resident_VMs ~__context ~self:master);
+               let slave = make_host ~__context ~name_label:"slave" () in
+               let management_net = make_network ~__context ~name_label:"management network" () in
+               let (_: API.ref_PIF) = make_pif ~__context ~network:management_net ~device:"eth0" ~host:master ~management:true ~mAC:mac1 () in
+               let (_: API.ref_PIF) = make_pif ~__context ~network:management_net ~device:"eth0" ~host:slave ~management:true ~mAC:mac2 () in
+               __context in
+       let my_installation_uuid = Xapi_inventory.lookup Xapi_inventory._installation_uuid in
+       let my_control_uuid = Xapi_inventory.lookup Xapi_inventory._control_domain_uuid in
+       let old_context = make_context "1" "2" my_installation_uuid my_control_uuid in
+       let new_context = make_context "a" "b" "host-uuid" "dom0-uuid" in
+       Pool_db_backup.prepare_database_for_restore ~old_context ~new_context;
+       let all_hosts = Db.Host.get_all ~__context:new_context in
+       (* new_context should have exactly 1 host: the master *)
+       if List.length all_hosts <> 1
+       then failwith "test_prepare_restore: should only be 1 host";
+       let master = List.hd all_hosts in       
+       (* new_context master host should have PIF with MAC "1" *)
+       let pif = List.hd (Db.Host.get_PIFs ~__context:new_context ~self:master) in
+       let mac = Db.PIF.get_MAC ~__context:new_context ~self:pif in
+       if mac <> "1"
+       then failwith "test_prepare_restore: PIF should have MAC 1";
+       (* new_context should have correct master host uuid *)
+       let host_uuid = Db.Host.get_uuid ~__context:new_context ~self:master in
+       if host_uuid <> my_installation_uuid
+       then failwith "test_prepare_restore: master uuid wrong";
+       (* new_context should have correct master dom0 uuid *)
+       let dom0 = List.hd (Db.Host.get_resident_VMs ~__context:new_context ~self:master) in
+       let dom0_uuid = Db.VM.get_uuid ~__context:new_context ~self:dom0 in
+       if dom0_uuid <> my_control_uuid
+       then failwith "test_prepare_restore: master dom0 uuid wrong";
+       Printf.printf "test_prepare_restore OK \n"
+
+let all () = 
+       test_prepare_restore ()
+
+       
index e5a55e969ac417f4859fb46d3521741ca7e2492c..b6af0dd0af684a6085e5ad851b22b54dd915312e 100644 (file)
  * GNU Lesser General Public License for more details.
  *)
 
+open Xapi_test_common
 open Xapi_db_upgrade
 
-(** 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
-
-       (* Db_xml.To.file "/tmp/new3.db" (Db_ref.get_database (Context.database_of __context)); *)
-
-       let host_info = {
-               Create_misc.name_label = "test host";
-               xen_verstring = "unknown";
-               linux_verstring = "something";
-               hostname = "localhost";
-               uuid = Xapi_inventory.lookup Xapi_inventory._installation_uuid;
-               dom0_uuid = "dom0-uuid";
-               oem_manufacturer = None;
-               oem_model = None;
-               oem_build_number = None;
-               machine_serial_number = None;
-               machine_serial_name = None;
-               total_memory_mib = 1024L;
-               dom0_static_max = Memory.bytes_of_mib 512L;
-       } 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
 
@@ -95,28 +69,6 @@ let upgrade_bios () =
        Unixext.unlink_safe "/var/tmp/.previousInventory";
        Printf.printf "upgrade_bios: OK\n"
 
-
-let make_vm ~__context ?(name_label="name_label") ?(name_description="description")
-               ?(user_version=1L) ?(is_a_template=false) ?(affinity=Ref.null)
-               ?(memory_target=500L) ?(memory_static_max=1000L) ?(memory_dynamic_max=500L)
-               ?(memory_dynamic_min=500L) ?(memory_static_min=0L) ?(vCPUs_params=[])
-               ?(vCPUs_max=1L) ?(vCPUs_at_startup=1L) ?(actions_after_shutdown=`destroy)
-               ?(actions_after_reboot=`restart) ?(actions_after_crash=`destroy)
-               ?(pV_bootloader="") ?(pV_kernel="") ?(pV_ramdisk="") ?(pV_args="") 
-               ?(pV_bootloader_args="") ?(pV_legacy_args="") ?(hVM_boot_policy="BIOS order")
-               ?(hVM_boot_params=[]) ?(hVM_shadow_multiplier=1.) ?(platform=[]) ?(pCI_bus="")
-               ?(other_config=[]) ?(xenstore_data=[]) ?(recommendations="") ?(ha_always_run=false)
-               ?(ha_restart_priority="1") ?(tags=[]) ?(blocked_operations=[]) ?(protection_policy=Ref.null)
-               ?(is_snapshot_from_vmpp=false) () = 
-       Xapi_vm.create ~__context ~name_label ~name_description ~user_version ~is_a_template 
-               ~affinity ~memory_target ~memory_static_max ~memory_dynamic_max ~memory_dynamic_min
-        ~memory_static_min ~vCPUs_params ~vCPUs_max ~vCPUs_at_startup ~actions_after_shutdown 
-               ~actions_after_reboot ~actions_after_crash ~pV_bootloader ~pV_kernel ~pV_ramdisk 
-               ~pV_args ~pV_bootloader_args ~pV_legacy_args ~hVM_boot_policy ~hVM_boot_params 
-               ~hVM_shadow_multiplier ~platform ~pCI_bus ~other_config ~xenstore_data ~recommendations
-               ~ha_always_run ~ha_restart_priority ~tags ~blocked_operations ~protection_policy
-               ~is_snapshot_from_vmpp
-
 let update_snapshots () = 
        let __context = make_test_database () in
        let a = make_vm ~__context ~name_label:"a" () in
@@ -148,9 +100,7 @@ let update_snapshots () =
 
        Printf.printf "update_snapshots: OK\n"
 
-let _ = 
+let all () = 
        upgrade_vm_memory_for_dmc ();
        upgrade_bios ();
        update_snapshots ()
-       
-
diff --git a/ocaml/xapi/xapi_test_common.ml b/ocaml/xapi/xapi_test_common.ml
new file mode 100644 (file)
index 0000000..fb87a2c
--- /dev/null
@@ -0,0 +1,83 @@
+(*
+ * Copyright (C) 2011 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(** 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
+
+       (* Db_xml.To.file "/tmp/new3.db" (Db_ref.get_database (Context.database_of __context)); *)
+
+       let host_info = {
+               Create_misc.name_label = "test host";
+               xen_verstring = "unknown";
+               linux_verstring = "something";
+               hostname = "localhost";
+               uuid = Xapi_inventory.lookup Xapi_inventory._installation_uuid;
+               dom0_uuid = "dom0-uuid";
+               oem_manufacturer = None;
+               oem_model = None;
+               oem_build_number = None;
+               machine_serial_number = None;
+               machine_serial_name = None;
+               total_memory_mib = 1024L;
+               dom0_static_max = Memory.bytes_of_mib 512L;
+       } in
+       Dbsync_slave.create_localhost ~__context host_info;
+       Create_misc.ensure_domain_zero_records ~__context host_info;
+       Dbsync_master.create_pool_record ~__context;
+       __context
+
+let make_vm ~__context ?(name_label="name_label") ?(name_description="description")
+               ?(user_version=1L) ?(is_a_template=false) ?(affinity=Ref.null)
+               ?(memory_target=500L) ?(memory_static_max=1000L) ?(memory_dynamic_max=500L)
+               ?(memory_dynamic_min=500L) ?(memory_static_min=0L) ?(vCPUs_params=[])
+               ?(vCPUs_max=1L) ?(vCPUs_at_startup=1L) ?(actions_after_shutdown=`destroy)
+               ?(actions_after_reboot=`restart) ?(actions_after_crash=`destroy)
+               ?(pV_bootloader="") ?(pV_kernel="") ?(pV_ramdisk="") ?(pV_args="") 
+               ?(pV_bootloader_args="") ?(pV_legacy_args="") ?(hVM_boot_policy="BIOS order")
+               ?(hVM_boot_params=[]) ?(hVM_shadow_multiplier=1.) ?(platform=[]) ?(pCI_bus="")
+               ?(other_config=[]) ?(xenstore_data=[]) ?(recommendations="") ?(ha_always_run=false)
+               ?(ha_restart_priority="1") ?(tags=[]) ?(blocked_operations=[]) ?(protection_policy=Ref.null)
+               ?(is_snapshot_from_vmpp=false) () = 
+       Xapi_vm.create ~__context ~name_label ~name_description ~user_version ~is_a_template 
+               ~affinity ~memory_target ~memory_static_max ~memory_dynamic_max ~memory_dynamic_min
+        ~memory_static_min ~vCPUs_params ~vCPUs_max ~vCPUs_at_startup ~actions_after_shutdown 
+               ~actions_after_reboot ~actions_after_crash ~pV_bootloader ~pV_kernel ~pV_ramdisk 
+               ~pV_args ~pV_bootloader_args ~pV_legacy_args ~hVM_boot_policy ~hVM_boot_params 
+               ~hVM_shadow_multiplier ~platform ~pCI_bus ~other_config ~xenstore_data ~recommendations
+               ~ha_always_run ~ha_restart_priority ~tags ~blocked_operations ~protection_policy
+               ~is_snapshot_from_vmpp
+
+let make_host ~__context ?(uuid=Uuid.string_of_uuid (Uuid.make_uuid ())) ?(name_label="host")
+               ?(name_description="description") ?(hostname="localhost") ?(address="127.0.0.1")
+               ?(external_auth_type="") ?(external_auth_service_name="") ?(external_auth_configuration=[])
+               ?(license_params=[]) ?(edition="free") ?(license_server=[]) () = 
+
+       Xapi_host.create ~__context ~uuid ~name_label ~name_description ~hostname ~address ~external_auth_type ~external_auth_service_name ~external_auth_configuration ~license_params ~edition ~license_server
+
+let make_pif ~__context ~network ~host ?(device="eth0") ?(mAC="C0:FF:EE:C0:FF:EE") ?(mTU=1500L)
+               ?(vLAN=(-1L)) ?(physical=true) ?(ip_configuration_mode=`None) ?(iP="") ?(netmask="")
+               ?(gateway="") ?(dNS="") ?(bond_slave_of=Ref.null) ?(vLAN_master_of=Ref.null) 
+               ?(management=false) ?(other_config=[]) ?(disallow_unplug=false) () =
+       Xapi_pif.pool_introduce ~__context
+               ~device ~network ~host ~mAC ~mTU ~vLAN ~physical ~ip_configuration_mode
+               ~iP ~netmask ~gateway ~dNS ~bond_slave_of ~vLAN_master_of ~management ~other_config ~disallow_unplug
+
+let make_network ~__context ?(name_label="net") ?(name_description="description") ?(mTU=1500L)
+               ?(other_config=[]) ?(bridge="xenbr0") () = 
+       Xapi_network.pool_introduce ~__context ~name_label ~name_description ~mTU ~other_config ~bridge
+
+
diff --git a/ocaml/xapi/xapi_unit_test.ml b/ocaml/xapi/xapi_unit_test.ml
new file mode 100644 (file)
index 0000000..304ead9
--- /dev/null
@@ -0,0 +1,20 @@
+(*
+ * Copyright (C) 2011 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+let _ = 
+       Xapi_db_upgrade_test.all ();
+       Pool_db_backup_test.all ()
+
+       
+