def _test_finish_migration(self, power_on=True, resize_instance=True, throw_exception=None): self._stub_out_common() self.mox.StubOutWithMock(vm_utils, "import_all_migrated_disks") self.mox.StubOutWithMock(self.vmops, "_attach_mapped_block_devices") context = "context" migration = {} name_label = "dummy" instance = {"name": name_label, "uuid": "fake_uuid"} disk_info = "disk_info" network_info = "net_info" image_meta = {"id": "image_id"} block_device_info = "bdi" session = self.vmops._session self.vmops._ensure_instance_name_unique(name_label) self.vmops._ensure_enough_free_mem(instance) di_type = "di_type" vm_utils.determine_disk_image_type(image_meta).AndReturn(di_type) root_vdi = {"ref": "fake_ref"} ephemeral_vdi = {"ref": "fake_ref_e"} vdis = {"root": root_vdi, "ephemerals": {4: ephemeral_vdi}} vm_utils.import_all_migrated_disks(self.vmops._session, instance).AndReturn(vdis) kernel_file = "kernel" ramdisk_file = "ramdisk" vm_utils.create_kernel_and_ramdisk(context, session, instance, name_label).AndReturn( (kernel_file, ramdisk_file)) vm_ref = "fake_vm_ref" self.vmops._create_vm_record(context, instance, name_label, di_type, kernel_file, ramdisk_file).AndReturn(vm_ref) if resize_instance: self.vmops._resize_up_root_vdi(instance, root_vdi) self.vmops._attach_disks(instance, vm_ref, name_label, vdis, di_type, network_info, None, None) self.vmops._attach_mapped_block_devices(instance, block_device_info) self.vmops._inject_instance_metadata(instance, vm_ref) self.vmops._inject_auto_disk_config(instance, vm_ref) self.vmops._file_inject_vm_settings(instance, vm_ref, vdis, network_info) self.vmops.inject_network_info(instance, network_info, vm_ref) self.vmops._create_vifs(instance, vm_ref, network_info) self.vmops.firewall_driver.setup_basic_filtering( instance, network_info).AndRaise(NotImplementedError) self.vmops.firewall_driver.prepare_instance_filter( instance, network_info) if power_on: self.vmops._start(instance, vm_ref) self.vmops._wait_for_instance_to_start(instance, vm_ref) self.vmops.firewall_driver.apply_instance_filter( instance, network_info) last_call = self.vmops._update_instance_progress(context, instance, step=5, total_steps=5) if throw_exception: last_call.AndRaise(throw_exception) self.vmops._destroy(instance, vm_ref, network_info=network_info) vm_utils.destroy_kernel_ramdisk(self.vmops._session, instance, kernel_file, ramdisk_file) vm_utils.safe_destroy_vdis(self.vmops._session, ["fake_ref_e", "fake_ref"]) self.mox.ReplayAll() self.vmops.finish_migration(context, migration, instance, disk_info, network_info, image_meta, resize_instance, block_device_info, power_on)
def _test_finish_migration(self, power_on=True, resize_instance=True, throw_exception=None): self._stub_out_common() self.mox.StubOutWithMock(vm_utils, "import_all_migrated_disks") self.mox.StubOutWithMock(self.vmops, "_attach_mapped_block_devices") context = "context" migration = {} name_label = "dummy" instance = {"name": name_label, "uuid": "fake_uuid"} disk_info = "disk_info" network_info = "net_info" image_meta = {"id": "image_id"} block_device_info = "bdi" session = self.vmops._session self.vmops._ensure_instance_name_unique(name_label) self.vmops._ensure_enough_free_mem(instance) di_type = "di_type" vm_utils.determine_disk_image_type(image_meta).AndReturn(di_type) root_vdi = {"ref": "fake_ref"} ephemeral_vdi = {"ref": "fake_ref_e"} vdis = {"root": root_vdi, "ephemerals": {4: ephemeral_vdi}} vm_utils.import_all_migrated_disks(self.vmops._session, instance).AndReturn(vdis) kernel_file = "kernel" ramdisk_file = "ramdisk" vm_utils.create_kernel_and_ramdisk(context, session, instance, name_label).AndReturn((kernel_file, ramdisk_file)) vm_ref = "fake_vm_ref" self.vmops._create_vm_record(context, instance, name_label, di_type, kernel_file, ramdisk_file, image_meta).AndReturn(vm_ref) if resize_instance: self.vmops._resize_up_vdis(instance, vdis) self.vmops._attach_disks(instance, vm_ref, name_label, vdis, di_type, network_info, None, None) self.vmops._attach_mapped_block_devices(instance, block_device_info) pci_manager.get_instance_pci_devs(instance).AndReturn([]) self.vmops._inject_instance_metadata(instance, vm_ref) self.vmops._inject_auto_disk_config(instance, vm_ref) self.vmops._file_inject_vm_settings(instance, vm_ref, vdis, network_info) self.vmops.inject_network_info(instance, network_info, vm_ref) self.vmops._create_vifs(instance, vm_ref, network_info) self.vmops.firewall_driver.setup_basic_filtering(instance, network_info).AndRaise(NotImplementedError) self.vmops.firewall_driver.prepare_instance_filter(instance, network_info) if power_on: self.vmops._start(instance, vm_ref) self.vmops._wait_for_instance_to_start(instance, vm_ref) self.vmops.firewall_driver.apply_instance_filter(instance, network_info) last_call = self.vmops._update_instance_progress(context, instance, step=5, total_steps=5) if throw_exception: last_call.AndRaise(throw_exception) self.vmops._destroy(instance, vm_ref, network_info=network_info) vm_utils.destroy_kernel_ramdisk(self.vmops._session, instance, kernel_file, ramdisk_file) vm_utils.safe_destroy_vdis(self.vmops._session, ["fake_ref_e", "fake_ref"]) self.mox.ReplayAll() self.vmops.finish_migration(context, migration, instance, disk_info, network_info, image_meta, resize_instance, block_device_info, power_on)