#NEWLINE# def _test_finish_migration( self , power_on = True , resize_instance = True , throw_exception = None , booted_from_volume = False ) : #NEWLINE# #INDENT# self . _stub_out_common ( ) #NEWLINE# self . mox . StubOutWithMock ( volumeops . VolumeOps , 'connect_volume' ) #NEWLINE# self . mox . StubOutWithMock ( vm_utils , 'import_all_migrated_disks' ) #NEWLINE# self . mox . StubOutWithMock ( self . vmops , '_attach_mapped_block_devices' ) #NEWLINE# context = 'context' #NEWLINE# migration = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# name_label = 'dummy' #NEWLINE# instance = { #NEWLINE# #INDENT# 'name' : name_label , #NEWLINE# 'uuid' : 'fake_uuid' , #NEWLINE# 'root_device_name' : '/dev/xvda' , #NEWLINE# #UNINDENT# } #NEWLINE# disk_info = 'disk_info' #NEWLINE# network_info = 'net_info' #NEWLINE# image_meta = objects . ImageMeta . from_dict ( { #NEWLINE# #INDENT# 'id' : 'image_id' , #NEWLINE# #UNINDENT# } ) #NEWLINE# block_device_info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# import_root = True #NEWLINE# if booted_from_volume : #NEWLINE# #INDENT# block_device_info = { #NEWLINE# #INDENT# 'block_device_mapping' : [ { #NEWLINE# #INDENT# 'mount_device' : '/dev/xvda' , #NEWLINE# 'connection_info' : { #NEWLINE# #INDENT# 'data' : 'fake-data' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# import_root = False #NEWLINE# volumeops . VolumeOps . connect_volume ( { #NEWLINE# #INDENT# 'data' : 'fake-data' , #NEWLINE# #UNINDENT# } ) . AndReturn ( ( 'sr' , 'vol-vdi-uuid' ) ) #NEWLINE# self . vmops . _session . call_xenapi ( 'VDI.get_by_uuid' , 'vol-vdi-uuid' ) . AndReturn ( 'vol-vdi-ref' ) #NEWLINE# #UNINDENT# session = self . vmops . _session #NEWLINE# self . vmops . _ensure_instance_name_unique ( name_label ) #NEWLINE# self . vmops . _ensure_enough_free_mem ( instance ) #NEWLINE# di_type = 'di_type' #NEWLINE# vm_utils . determine_disk_image_type ( image_meta ) . AndReturn ( di_type ) #NEWLINE# root_vdi = { #NEWLINE# #INDENT# 'ref' : 'fake_ref' , #NEWLINE# #UNINDENT# } #NEWLINE# ephemeral_vdi = { #NEWLINE# #INDENT# 'ref' : 'fake_ref_e' , #NEWLINE# #UNINDENT# } #NEWLINE# vdis = { #NEWLINE# #INDENT# 'root' : root_vdi , #NEWLINE# 'ephemerals' : { #NEWLINE# #INDENT# 4 : ephemeral_vdi , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# vm_utils . import_all_migrated_disks ( self . vmops . _session , instance , import_root = import_root ) . AndReturn ( vdis ) #NEWLINE# kernel_file = 'kernel' #NEWLINE# ramdisk_file = 'ramdisk' #NEWLINE# vm_utils . create_kernel_and_ramdisk ( context , session , instance , name_label ) . AndReturn ( ( kernel_file , ramdisk_file ) ) #NEWLINE# vm_ref = 'fake_vm_ref' #NEWLINE# rescue = False #NEWLINE# self . vmops . _create_vm_record ( context , instance , name_label , di_type , kernel_file , ramdisk_file , image_meta , rescue ) . AndReturn ( vm_ref ) #NEWLINE# if resize_instance : #NEWLINE# #INDENT# self . vmops . _resize_up_vdis ( instance , vdis ) #NEWLINE# #UNINDENT# self . vmops . _attach_disks ( instance , image_meta , vm_ref , name_label , vdis , di_type , network_info , False , None , None ) #NEWLINE# self . vmops . _attach_mapped_block_devices ( instance , block_device_info ) #NEWLINE# pci_manager . get_instance_pci_devs ( instance ) . AndReturn ( [ ] ) #NEWLINE# self . vmops . _inject_instance_metadata ( instance , vm_ref ) #NEWLINE# self . vmops . _inject_auto_disk_config ( instance , vm_ref ) #NEWLINE# self . vmops . _file_inject_vm_settings ( instance , vm_ref , vdis , network_info ) #NEWLINE# self . vmops . inject_network_info ( instance , network_info , vm_ref ) #NEWLINE# self . vmops . _create_vifs ( instance , vm_ref , network_info ) #NEWLINE# self . vmops . firewall_driver . setup_basic_filtering ( instance , network_info ) . AndRaise ( NotImplementedError ) #NEWLINE# self . vmops . firewall_driver . prepare_instance_filter ( instance , network_info ) #NEWLINE# if power_on : #NEWLINE# #INDENT# self . vmops . _start ( instance , vm_ref , start_pause = True ) #NEWLINE# #UNINDENT# self . vmops . firewall_driver . apply_instance_filter ( instance , network_info ) #NEWLINE# if power_on : #NEWLINE# #INDENT# self . vmops . _session . call_xenapi ( 'VM.unpause' , vm_ref ) #NEWLINE# self . vmops . _wait_for_instance_to_start ( instance , vm_ref ) #NEWLINE# self . vmops . _update_last_dom_id ( vm_ref ) #NEWLINE# #UNINDENT# last_call = self . vmops . _update_instance_progress ( context , instance , step = 5 , total_steps = 5 ) #NEWLINE# if throw_exception : #NEWLINE# #INDENT# last_call . AndRaise ( throw_exception ) #NEWLINE# self . vmops . _destroy ( instance , vm_ref , network_info = network_info ) #NEWLINE# vm_utils . destroy_kernel_ramdisk ( self . vmops . _session , instance , kernel_file , ramdisk_file ) #NEWLINE# vm_utils . safe_destroy_vdis ( self . vmops . _session , [ 'fake_ref_e' , 'fake_ref' ] ) #NEWLINE# #UNINDENT# self . mox . ReplayAll ( ) #NEWLINE# self . vmops . finish_migration ( context , migration , ephemeral_vdi , disk_info , network_info , image_meta , resize_instance , block_device_info , power_on )