<s> import mock <EOL> from oslo_serialization import jsonutils <EOL> from oslo_utils import units <EOL> from oslo_utils import uuidutils <EOL> from oslo_vmware import exceptions as vexc <EOL> from oslo_vmware . objects import datastore as ds_obj <EOL> from oslo_vmware import vim_util as vutil <EOL> import six <EOL> from nova . compute import power_state <EOL> from nova import context <EOL> from nova import exception <EOL> from nova . network import model as network_model <EOL> from nova import objects <EOL> from nova import test <EOL> from nova . tests . unit import fake_flavor <EOL> from nova . tests . unit import fake_instance <EOL> import nova . tests . unit . image . fake <EOL> from nova . tests . unit . virt . vmwareapi import fake as vmwareapi_fake <EOL> from nova . tests . unit . virt . vmwareapi import stubs <EOL> from nova . tests import uuidsentinel <EOL> from nova import utils <EOL> from nova import version <EOL> from nova . virt import hardware <EOL> from nova . virt . vmwareapi import constants <EOL> from nova . virt . vmwareapi import driver <EOL> from nova . virt . vmwareapi import ds_util <EOL> from nova . virt . vmwareapi import images <EOL> from nova . virt . vmwareapi import vif <EOL> from nova . virt . vmwareapi import vim_util <EOL> from nova . virt . vmwareapi import vm_util <EOL> from nova . virt . vmwareapi import vmops <EOL> class DsPathMatcher ( object ) : <EOL> def __init__ ( self , expected_ds_path_str ) : <EOL> self . expected_ds_path_str = expected_ds_path_str <EOL> def __eq__ ( self , ds_path_param ) : <EOL> return str ( ds_path_param ) == self . expected_ds_path_str <EOL> class VMwareVMOpsTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( VMwareVMOpsTestCase , self ) . setUp ( ) <EOL> ds_util . dc_cache_reset ( ) <EOL> vmwareapi_fake . reset ( ) <EOL> stubs . set_stubs ( self ) <EOL> self . flags ( enabled = True , group = '<STR_LIT>' ) <EOL> self . flags ( image_cache_subdirectory_name = '<STR_LIT>' , <EOL> my_ip = '<STR_LIT>' , <EOL> flat_injected = True ) <EOL> self . _context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _session = driver . VMwareAPISession ( ) <EOL> self . _virtapi = mock . Mock ( ) <EOL> self . _image_id = nova . tests . unit . image . fake . get_valid_image_id ( ) <EOL> fake_ds_ref = vmwareapi_fake . ManagedObjectReference ( '<STR_LIT>' ) <EOL> self . _ds = ds_obj . Datastore ( <EOL> ref = fake_ds_ref , name = '<STR_LIT>' , <EOL> capacity = <NUM_LIT:10> * units . Gi , <EOL> freespace = <NUM_LIT:10> * units . Gi ) <EOL> self . _dc_info = ds_util . DcInfo ( <EOL> ref = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> vmFolder = '<STR_LIT>' ) <EOL> cluster = vmwareapi_fake . create_cluster ( '<STR_LIT>' , fake_ds_ref ) <EOL> self . _uuid = uuidsentinel . foo <EOL> self . _instance_values = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . _uuid , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : self . _image_id , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : '<STR_LIT>' % ( cluster . mo_id , cluster . name ) , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> self . _instance = fake_instance . fake_instance_obj ( <EOL> self . _context , ** self . _instance_values ) <EOL> self . _flavor = objects . Flavor ( name = '<STR_LIT>' , memory_mb = <NUM_LIT> , vcpus = <NUM_LIT:1> , <EOL> root_gb = <NUM_LIT:10> , ephemeral_gb = <NUM_LIT:0> , swap = <NUM_LIT:0> , <EOL> extra_specs = { } ) <EOL> self . _instance . flavor = self . _flavor <EOL> self . _vmops = vmops . VMwareVMOps ( self . _session , self . _virtapi , None , <EOL> cluster = cluster . obj ) <EOL> self . _cluster = cluster <EOL> self . _image_meta = objects . ImageMeta . from_dict ( { '<STR_LIT:id>' : self . _image_id } ) <EOL> subnet_4 = network_model . Subnet ( cidr = '<STR_LIT>' , <EOL> dns = [ network_model . IP ( '<STR_LIT>' ) ] , <EOL> gateway = <EOL> network_model . IP ( '<STR_LIT>' ) , <EOL> ips = [ <EOL> network_model . IP ( '<STR_LIT>' ) ] , <EOL> routes = None ) <EOL> subnet_6 = network_model . Subnet ( cidr = '<STR_LIT>' , <EOL> dns = None , <EOL> gateway = <EOL> network_model . IP ( '<STR_LIT>' ) , <EOL> ips = [ network_model . IP ( <EOL> '<STR_LIT>' ) ] , <EOL> routes = None ) <EOL> network = network_model . Network ( id = <NUM_LIT:0> , <EOL> bridge = '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> subnets = [ subnet_4 , subnet_6 ] , <EOL> vlan = None , <EOL> bridge_interface = None , <EOL> injected = True ) <EOL> self . _network_values = { <EOL> '<STR_LIT:id>' : None , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : network , <EOL> '<STR_LIT:type>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:3> <EOL> } <EOL> self . network_info = network_model . NetworkInfo ( [ <EOL> network_model . VIF ( ** self . _network_values ) <EOL> ] ) <EOL> pure_IPv6_network = network_model . Network ( id = <NUM_LIT:0> , <EOL> bridge = '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> subnets = [ subnet_6 ] , <EOL> vlan = None , <EOL> bridge_interface = None , <EOL> injected = True ) <EOL> self . pure_IPv6_network_info = network_model . NetworkInfo ( [ <EOL> network_model . VIF ( id = None , <EOL> address = '<STR_LIT>' , <EOL> network = pure_IPv6_network , <EOL> type = None , <EOL> devname = None , <EOL> ovs_interfaceid = None , <EOL> rxtx_cap = <NUM_LIT:3> ) <EOL> ] ) <EOL> self . _metadata = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % version . version_string_with_package ( ) ) <EOL> def test_get_machine_id_str ( self ) : <EOL> result = vmops . VMwareVMOps . _get_machine_id_str ( self . network_info ) <EOL> self . assertEqual ( '<STR_LIT>' <EOL> '<STR_LIT>' , result ) <EOL> result = vmops . VMwareVMOps . _get_machine_id_str ( <EOL> self . pure_IPv6_network_info ) <EOL> self . assertEqual ( '<STR_LIT>' , result ) <EOL> def _setup_create_folder_mocks ( self ) : <EOL> ops = vmops . VMwareVMOps ( mock . Mock ( ) , mock . Mock ( ) , mock . Mock ( ) ) <EOL> base_name = '<STR_LIT>' <EOL> ds_name = "<STR_LIT>" <EOL> ds_ref = mock . Mock ( ) <EOL> ds_ref . value = <NUM_LIT:1> <EOL> dc_ref = mock . Mock ( ) <EOL> ds_util . _DS_DC_MAPPING [ ds_ref . value ] = ds_util . DcInfo ( <EOL> ref = dc_ref , <EOL> name = '<STR_LIT>' , <EOL> vmFolder = '<STR_LIT>' ) <EOL> path = ds_obj . DatastorePath ( ds_name , base_name ) <EOL> return ds_name , ds_ref , ops , path , dc_ref <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> def test_create_folder_if_missing ( self , mock_mkdir ) : <EOL> ds_name , ds_ref , ops , path , dc = self . _setup_create_folder_mocks ( ) <EOL> ops . _create_folder_if_missing ( ds_name , ds_ref , '<STR_LIT>' ) <EOL> mock_mkdir . assert_called_with ( ops . _session , path , dc ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> def test_create_folder_if_missing_exception ( self , mock_mkdir ) : <EOL> ds_name , ds_ref , ops , path , dc = self . _setup_create_folder_mocks ( ) <EOL> ds_util . mkdir . side_effect = vexc . FileAlreadyExistsException ( ) <EOL> ops . _create_folder_if_missing ( ds_name , ds_ref , '<STR_LIT>' ) <EOL> mock_mkdir . assert_called_with ( ops . _session , path , dc ) <EOL> @ mock . patch . object ( vutil , '<STR_LIT>' , return_value = None ) <EOL> def test_get_valid_vms_from_retrieve_result ( self , _mock_cont ) : <EOL> ops = vmops . VMwareVMOps ( self . _session , mock . Mock ( ) , mock . Mock ( ) ) <EOL> fake_objects = vmwareapi_fake . FakeRetrieveResult ( ) <EOL> for x in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> vm = vmwareapi_fake . VirtualMachine ( ) <EOL> vm . set ( '<STR_LIT>' , <EOL> vmwareapi_fake . OptionValue ( <EOL> value = uuidutils . generate_uuid ( ) ) ) <EOL> fake_objects . add_object ( vm ) <EOL> vms = ops . _get_valid_vms_from_retrieve_result ( fake_objects ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( vms ) ) <EOL> @ mock . patch . object ( vutil , '<STR_LIT>' , return_value = None ) <EOL> def test_get_valid_vms_from_retrieve_result_with_invalid ( self , <EOL> _mock_cont ) : <EOL> ops = vmops . VMwareVMOps ( self . _session , mock . Mock ( ) , mock . Mock ( ) ) <EOL> fake_objects = vmwareapi_fake . FakeRetrieveResult ( ) <EOL> valid_vm = vmwareapi_fake . VirtualMachine ( ) <EOL> valid_vm . set ( '<STR_LIT>' , <EOL> vmwareapi_fake . OptionValue ( <EOL> value = uuidutils . generate_uuid ( ) ) ) <EOL> fake_objects . add_object ( valid_vm ) <EOL> invalid_vm1 = vmwareapi_fake . VirtualMachine ( ) <EOL> invalid_vm1 . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> invalid_vm1 . set ( '<STR_LIT>' , <EOL> vmwareapi_fake . OptionValue ( <EOL> value = uuidutils . generate_uuid ( ) ) ) <EOL> invalid_vm2 = vmwareapi_fake . VirtualMachine ( ) <EOL> invalid_vm2 . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> invalid_vm2 . set ( '<STR_LIT>' , <EOL> vmwareapi_fake . OptionValue ( <EOL> value = uuidutils . generate_uuid ( ) ) ) <EOL> fake_objects . add_object ( invalid_vm1 ) <EOL> fake_objects . add_object ( invalid_vm2 ) <EOL> vms = ops . _get_valid_vms_from_retrieve_result ( fake_objects ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( vms ) ) <EOL> def test_delete_vm_snapshot ( self ) : <EOL> def fake_call_method ( module , method , * args , ** kwargs ) : <EOL> self . assertEqual ( '<STR_LIT>' , method ) <EOL> self . assertEqual ( '<STR_LIT>' , args [ <NUM_LIT:0> ] ) <EOL> self . assertFalse ( kwargs [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( kwargs [ '<STR_LIT>' ] ) <EOL> return '<STR_LIT>' <EOL> with test . nested ( <EOL> mock . patch . object ( self . _session , '<STR_LIT>' ) , <EOL> mock . patch . object ( self . _session , '<STR_LIT>' , fake_call_method ) <EOL> ) as ( _wait_for_task , _call_method ) : <EOL> self . _vmops . _delete_vm_snapshot ( self . _instance , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> _wait_for_task . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' ) ] ) <EOL> def test_create_vm_snapshot ( self ) : <EOL> method_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def fake_call_method ( module , method , * args , ** kwargs ) : <EOL> expected_method = method_list . pop ( <NUM_LIT:0> ) <EOL> self . assertEqual ( expected_method , method ) <EOL> if ( expected_method == '<STR_LIT>' ) : <EOL> self . assertEqual ( '<STR_LIT>' , args [ <NUM_LIT:0> ] ) <EOL> self . assertFalse ( kwargs [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( kwargs [ '<STR_LIT>' ] ) <EOL> return '<STR_LIT>' <EOL> elif ( expected_method == '<STR_LIT>' ) : <EOL> task_info = mock . Mock ( ) <EOL> task_info . result = "<STR_LIT>" <EOL> self . assertEqual ( ( '<STR_LIT>' , '<STR_LIT:info>' ) , args ) <EOL> return task_info <EOL> with test . nested ( <EOL> mock . patch . object ( self . _session , '<STR_LIT>' ) , <EOL> mock . patch . object ( self . _session , '<STR_LIT>' , fake_call_method ) <EOL> ) as ( _wait_for_task , _call_method ) : <EOL> snap = self . _vmops . _create_vm_snapshot ( self . _instance , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" , snap ) <EOL> _wait_for_task . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' ) ] ) <EOL> def test_update_instance_progress ( self ) : <EOL> with mock . patch . object ( self . _instance , '<STR_LIT>' ) as mock_save : <EOL> self . _vmops . _update_instance_progress ( self . _instance . _context , <EOL> self . _instance , <NUM_LIT:5> , <NUM_LIT:10> ) <EOL> mock_save . assert_called_once_with ( ) <EOL> self . assertEqual ( <NUM_LIT:50> , self . _instance . progress ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_get_info ( self , mock_get_vm_ref ) : <EOL> result = { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def mock_call_method ( module , method , * args , ** kwargs ) : <EOL> if method == '<STR_LIT>' : <EOL> return <EOL> return result <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> mock_call_method ) : <EOL> info = self . _vmops . get_info ( self . _instance ) <EOL> mock_get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> expected = hardware . InstanceInfo ( state = power_state . RUNNING , <EOL> max_mem_kb = <NUM_LIT> * <NUM_LIT> , <EOL> mem_kb = <NUM_LIT> * <NUM_LIT> , <EOL> num_cpu = <NUM_LIT:4> ) <EOL> self . assertEqual ( expected , info ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_get_info_when_ds_unavailable ( self , mock_get_vm_ref ) : <EOL> result = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def mock_call_method ( module , method , * args , ** kwargs ) : <EOL> if method == '<STR_LIT>' : <EOL> return <EOL> return result <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> mock_call_method ) : <EOL> info = self . _vmops . get_info ( self . _instance ) <EOL> mock_get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> self . assertEqual ( hardware . InstanceInfo ( state = power_state . SHUTDOWN ) , <EOL> info ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_get_info_instance_deleted ( self , mock_get_vm_ref ) : <EOL> props = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> prop_cpu = vmwareapi_fake . Prop ( props [ <NUM_LIT:0> ] , <NUM_LIT:4> ) <EOL> prop_mem = vmwareapi_fake . Prop ( props [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> prop_state = vmwareapi_fake . Prop ( props [ <NUM_LIT:2> ] , '<STR_LIT>' ) <EOL> prop_list = [ prop_state , prop_mem , prop_cpu ] <EOL> obj_content = vmwareapi_fake . ObjectContent ( None , prop_list = prop_list ) <EOL> result = vmwareapi_fake . FakeRetrieveResult ( ) <EOL> result . add_object ( obj_content ) <EOL> def mock_call_method ( module , method , * args , ** kwargs ) : <EOL> raise vexc . ManagedObjectNotFoundException ( ) <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> mock_call_method ) : <EOL> self . assertRaises ( exception . InstanceNotFound , <EOL> self . _vmops . get_info , <EOL> self . _instance ) <EOL> mock_get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> def _test_get_datacenter_ref_and_name ( self , ds_ref_exists = False ) : <EOL> instance_ds_ref = mock . Mock ( ) <EOL> instance_ds_ref . value = "<STR_LIT>" <EOL> _vcvmops = vmops . VMwareVMOps ( self . _session , None , None ) <EOL> if ds_ref_exists : <EOL> ds_ref = mock . Mock ( ) <EOL> ds_ref . value = "<STR_LIT>" <EOL> else : <EOL> ds_ref = None <EOL> self . _continue_retrieval = True <EOL> self . _fake_object1 = vmwareapi_fake . FakeRetrieveResult ( ) <EOL> self . _fake_object2 = vmwareapi_fake . FakeRetrieveResult ( ) <EOL> def fake_call_method ( module , method , * args , ** kwargs ) : <EOL> self . _fake_object1 . add_object ( vmwareapi_fake . Datacenter ( <EOL> ds_ref = ds_ref ) ) <EOL> if not ds_ref : <EOL> setattr ( self . _fake_object1 , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . _continue_retrieval : <EOL> if self . _continue_retrieval : <EOL> self . _continue_retrieval = False <EOL> self . _fake_object2 . add_object ( <EOL> vmwareapi_fake . Datacenter ( ) ) <EOL> return self . _fake_object2 <EOL> return <EOL> if method == "<STR_LIT>" : <EOL> return <EOL> return self . _fake_object1 <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> side_effect = fake_call_method ) as fake_call : <EOL> dc_info = _vcvmops . get_datacenter_ref_and_name ( instance_ds_ref ) <EOL> if ds_ref : <EOL> self . assertEqual ( <NUM_LIT:1> , len ( ds_util . _DS_DC_MAPPING ) ) <EOL> calls = [ mock . call ( vim_util , "<STR_LIT>" , "<STR_LIT>" , <EOL> [ "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> mock . call ( vutil , '<STR_LIT>' , <EOL> self . _fake_object1 ) ] <EOL> fake_call . assert_has_calls ( calls ) <EOL> self . assertEqual ( "<STR_LIT>" , dc_info . name ) <EOL> else : <EOL> calls = [ mock . call ( vim_util , "<STR_LIT>" , "<STR_LIT>" , <EOL> [ "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> mock . call ( vutil , '<STR_LIT>' , <EOL> self . _fake_object2 ) ] <EOL> fake_call . assert_has_calls ( calls ) <EOL> self . assertIsNone ( dc_info ) <EOL> def test_get_datacenter_ref_and_name ( self ) : <EOL> self . _test_get_datacenter_ref_and_name ( ds_ref_exists = True ) <EOL> def test_get_datacenter_ref_and_name_with_no_datastore ( self ) : <EOL> self . _test_get_datacenter_ref_and_name ( ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_obj , '<STR_LIT>' ) <EOL> def test_rescue ( self , mock_get_ds_by_ref , mock_power_on , mock_reconfigure , <EOL> mock_get_boot_spec , mock_find_rescue , <EOL> mock_get_vm_ref , mock_disk_copy , <EOL> mock_power_off , mock_fetch_image_if_missing ) : <EOL> _volumeops = mock . Mock ( ) <EOL> self . _vmops . _volumeops = _volumeops <EOL> ds = ds_obj . Datastore ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mock_get_ds_by_ref . return_value = ds <EOL> mock_find_rescue . return_value = '<STR_LIT>' <EOL> mock_get_boot_spec . return_value = '<STR_LIT>' <EOL> vm_ref = vmwareapi_fake . ManagedObjectReference ( ) <EOL> mock_get_vm_ref . return_value = vm_ref <EOL> device = vmwareapi_fake . DataObject ( ) <EOL> backing = vmwareapi_fake . DataObject ( ) <EOL> backing . datastore = ds . ref <EOL> device . backing = backing <EOL> vmdk = vm_util . VmdkInfo ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> device ) <EOL> with test . nested ( <EOL> mock . patch . object ( self . _vmops , '<STR_LIT>' ) , <EOL> mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = vmdk ) <EOL> ) as ( _get_dc_ref_and_name , fake_vmdk_info ) : <EOL> dc_info = mock . Mock ( ) <EOL> _get_dc_ref_and_name . return_value = dc_info <EOL> self . _vmops . rescue ( <EOL> self . _context , self . _instance , None , self . _image_meta ) <EOL> mock_fetch_image_if_missing ( self . _context , mock . ANY ) <EOL> mock_power_off . assert_called_once_with ( self . _session , <EOL> self . _instance , <EOL> vm_ref ) <EOL> uuid = self . _instance . image_ref <EOL> cache_path = ds . build_path ( '<STR_LIT>' , uuid , uuid + '<STR_LIT>' ) <EOL> rescue_path = ds . build_path ( self . _uuid , uuid + '<STR_LIT>' ) <EOL> mock_disk_copy . assert_called_once_with ( self . _session , dc_info . ref , <EOL> cache_path , rescue_path ) <EOL> _volumeops . attach_disk_to_vm . assert_called_once_with ( vm_ref , <EOL> self . _instance , mock . ANY , mock . ANY , rescue_path ) <EOL> mock_get_boot_spec . assert_called_once_with ( mock . ANY , <EOL> '<STR_LIT>' ) <EOL> mock_reconfigure . assert_called_once_with ( self . _session , <EOL> vm_ref , <EOL> '<STR_LIT>' ) <EOL> mock_power_on . assert_called_once_with ( self . _session , <EOL> self . _instance , <EOL> vm_ref = vm_ref ) <EOL> def test_unrescue_power_on ( self ) : <EOL> self . _test_unrescue ( True ) <EOL> def test_unrescue_power_off ( self ) : <EOL> self . _test_unrescue ( False ) <EOL> def _test_unrescue ( self , power_on ) : <EOL> _volumeops = mock . Mock ( ) <EOL> self . _vmops . _volumeops = _volumeops <EOL> vm_ref = mock . Mock ( ) <EOL> def fake_call_method ( module , method , * args , ** kwargs ) : <EOL> expected_args = ( vm_ref , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , method ) <EOL> self . assertEqual ( expected_args , args ) <EOL> with test . nested ( <EOL> mock . patch . object ( vm_util , '<STR_LIT>' ) , <EOL> mock . patch . object ( vm_util , '<STR_LIT>' ) , <EOL> mock . patch . object ( vm_util , '<STR_LIT>' , return_value = vm_ref ) , <EOL> mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> fake_call_method ) , <EOL> mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> ) as ( _power_on_instance , _find_rescue , _get_vm_ref , <EOL> _call_method , _power_off ) : <EOL> self . _vmops . unrescue ( self . _instance , power_on = power_on ) <EOL> if power_on : <EOL> _power_on_instance . assert_called_once_with ( self . _session , <EOL> self . _instance , vm_ref = vm_ref ) <EOL> else : <EOL> self . assertFalse ( _power_on_instance . called ) <EOL> _get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> _power_off . assert_called_once_with ( self . _session , self . _instance , <EOL> vm_ref ) <EOL> _volumeops . detach_disk_from_vm . assert_called_once_with ( <EOL> vm_ref , self . _instance , mock . ANY , destroy_disk = True ) <EOL> def _test_finish_migration ( self , power_on = True , resize_instance = False ) : <EOL> with test . nested ( <EOL> mock . patch . object ( self . _vmops , <EOL> '<STR_LIT>' ) , <EOL> mock . patch . object ( self . _vmops , "<STR_LIT>" ) , <EOL> mock . patch . object ( vm_util , "<STR_LIT>" ) , <EOL> mock . patch . object ( vm_util , "<STR_LIT>" , <EOL> return_value = '<STR_LIT>' ) <EOL> ) as ( fake_resize_create_ephemerals_and_swap , <EOL> fake_update_instance_progress , fake_power_on , fake_get_vm_ref ) : <EOL> self . _vmops . finish_migration ( context = self . _context , <EOL> migration = None , <EOL> instance = self . _instance , <EOL> disk_info = None , <EOL> network_info = None , <EOL> block_device_info = None , <EOL> resize_instance = resize_instance , <EOL> image_meta = None , <EOL> power_on = power_on ) <EOL> fake_resize_create_ephemerals_and_swap . assert_called_once_with ( <EOL> '<STR_LIT>' , self . _instance , None ) <EOL> if power_on : <EOL> fake_power_on . assert_called_once_with ( self . _session , <EOL> self . _instance , <EOL> vm_ref = '<STR_LIT>' ) <EOL> else : <EOL> self . assertFalse ( fake_power_on . called ) <EOL> calls = [ <EOL> mock . call ( self . _context , self . _instance , step = <NUM_LIT:5> , <EOL> total_steps = vmops . RESIZE_TOTAL_STEPS ) , <EOL> mock . call ( self . _context , self . _instance , step = <NUM_LIT:6> , <EOL> total_steps = vmops . RESIZE_TOTAL_STEPS ) ] <EOL> fake_update_instance_progress . assert_has_calls ( calls ) <EOL> def test_finish_migration_power_on ( self ) : <EOL> self . _test_finish_migration ( power_on = True , resize_instance = False ) <EOL> def test_finish_migration_power_off ( self ) : <EOL> self . _test_finish_migration ( power_on = False , resize_instance = False ) <EOL> def test_finish_migration_power_on_resize ( self ) : <EOL> self . _test_finish_migration ( power_on = True , resize_instance = True ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' , <EOL> return_value = True ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> def _test_finish_revert_migration ( self , fake_power_on , <EOL> fake_get_vm_ref , fake_power_off , <EOL> fake_resize_spec , fake_reconfigure_vm , <EOL> fake_get_browser , <EOL> fake_original_exists , fake_disk_move , <EOL> fake_disk_delete , <EOL> fake_remove_ephemerals_and_swap , <EOL> fake_resize_create_ephemerals_and_swap , <EOL> fake_get_extra_specs , <EOL> power_on ) : <EOL> """<STR_LIT>""" <EOL> datastore = ds_obj . Datastore ( ref = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> device = vmwareapi_fake . DataObject ( ) <EOL> backing = vmwareapi_fake . DataObject ( ) <EOL> backing . datastore = datastore . ref <EOL> device . backing = backing <EOL> vmdk = vm_util . VmdkInfo ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> device ) <EOL> dc_info = ds_util . DcInfo ( ref = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> vmFolder = '<STR_LIT>' ) <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> fake_get_extra_specs . return_value = extra_specs <EOL> with test . nested ( <EOL> mock . patch . object ( self . _vmops , '<STR_LIT>' , <EOL> return_value = dc_info ) , <EOL> mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = vmdk ) <EOL> ) as ( fake_get_dc_ref_and_name , fake_get_vmdk_info ) : <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> mock_attach_disk = self . _vmops . _volumeops . attach_disk_to_vm <EOL> mock_detach_disk = self . _vmops . _volumeops . detach_disk_from_vm <EOL> self . _vmops . finish_revert_migration ( self . _context , <EOL> instance = self . _instance , <EOL> network_info = None , <EOL> block_device_info = None , <EOL> power_on = power_on ) <EOL> fake_get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> fake_power_off . assert_called_once_with ( self . _session , <EOL> self . _instance , <EOL> '<STR_LIT>' ) <EOL> metadata = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % version . version_string_with_package ( ) ) <EOL> fake_resize_spec . assert_called_once_with ( <EOL> self . _session . vim . client . factory , <EOL> int ( self . _instance . vcpus ) , <EOL> int ( self . _instance . memory_mb ) , <EOL> extra_specs , <EOL> metadata = metadata ) <EOL> fake_reconfigure_vm . assert_called_once_with ( self . _session , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> fake_get_vmdk_info . assert_called_once_with ( <EOL> self . _session , '<STR_LIT>' , uuid = self . _instance . uuid ) <EOL> fake_get_browser . assert_called_once_with ( '<STR_LIT>' ) <EOL> fake_original_exists . assert_called_once_with ( <EOL> self . _session , '<STR_LIT>' , <EOL> ds_obj . DatastorePath ( datastore . name , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> mock_detach_disk . assert_called_once_with ( '<STR_LIT>' , <EOL> self . _instance , <EOL> device ) <EOL> fake_disk_delete . assert_called_once_with ( <EOL> self . _session , dc_info . ref , '<STR_LIT>' ) <EOL> fake_disk_move . assert_called_once_with ( <EOL> self . _session , dc_info . ref , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> mock_attach_disk . assert_called_once_with ( <EOL> '<STR_LIT>' , self . _instance , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> fake_remove_ephemerals_and_swap . assert_called_once_with ( '<STR_LIT>' ) <EOL> fake_resize_create_ephemerals_and_swap . assert_called_once_with ( <EOL> '<STR_LIT>' , self . _instance , None ) <EOL> if power_on : <EOL> fake_power_on . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> else : <EOL> self . assertFalse ( fake_power_on . called ) <EOL> def test_finish_revert_migration_power_on ( self ) : <EOL> self . _test_finish_revert_migration ( power_on = True ) <EOL> def test_finish_revert_migration_power_off ( self ) : <EOL> self . _test_finish_revert_migration ( power_on = False ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> def test_resize_vm ( self , fake_resize_spec , fake_reconfigure , <EOL> fake_get_extra_specs , fake_get_metadata ) : <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> fake_get_extra_specs . return_value = extra_specs <EOL> fake_get_metadata . return_value = self . _metadata <EOL> flavor = objects . Flavor ( name = '<STR_LIT>' , <EOL> memory_mb = <NUM_LIT> , <EOL> vcpus = <NUM_LIT:2> , <EOL> extra_specs = { } ) <EOL> self . _vmops . _resize_vm ( self . _context , self . _instance , '<STR_LIT>' , flavor , <EOL> None ) <EOL> fake_resize_spec . assert_called_once_with ( <EOL> self . _session . vim . client . factory , <NUM_LIT:2> , <NUM_LIT> , extra_specs , <EOL> metadata = self . _metadata ) <EOL> fake_reconfigure . assert_called_once_with ( self . _session , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> def test_resize_disk ( self , fake_disk_copy , fake_disk_move , <EOL> fake_extend ) : <EOL> datastore = ds_obj . Datastore ( ref = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> device = vmwareapi_fake . DataObject ( ) <EOL> backing = vmwareapi_fake . DataObject ( ) <EOL> backing . datastore = datastore . ref <EOL> device . backing = backing <EOL> vmdk = vm_util . VmdkInfo ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> self . _instance . root_gb * units . Gi , <EOL> device ) <EOL> dc_info = ds_util . DcInfo ( ref = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> vmFolder = '<STR_LIT>' ) <EOL> with mock . patch . object ( self . _vmops , '<STR_LIT>' , <EOL> return_value = dc_info ) as fake_get_dc_ref_and_name : <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> mock_attach_disk = self . _vmops . _volumeops . attach_disk_to_vm <EOL> mock_detach_disk = self . _vmops . _volumeops . detach_disk_from_vm <EOL> flavor = fake_flavor . fake_flavor_obj ( self . _context , <EOL> root_gb = self . _instance . root_gb + <NUM_LIT:1> ) <EOL> self . _vmops . _resize_disk ( self . _instance , '<STR_LIT>' , vmdk , flavor ) <EOL> fake_get_dc_ref_and_name . assert_called_once_with ( datastore . ref ) <EOL> fake_disk_copy . assert_called_once_with ( <EOL> self . _session , dc_info . ref , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> mock_detach_disk . assert_called_once_with ( '<STR_LIT>' , <EOL> self . _instance , <EOL> device ) <EOL> fake_extend . assert_called_once_with ( <EOL> self . _instance , flavor [ '<STR_LIT>' ] * units . Mi , <EOL> '<STR_LIT>' , dc_info . ref ) <EOL> calls = [ <EOL> mock . call ( self . _session , dc_info . ref , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> mock . call ( self . _session , dc_info . ref , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ] <EOL> fake_disk_move . assert_has_calls ( calls ) <EOL> mock_attach_disk . assert_called_once_with ( <EOL> '<STR_LIT>' , self . _instance , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> def test_remove_ephemerals_and_swap ( self , get_ephemerals , get_swap , <EOL> detach_devices ) : <EOL> get_ephemerals . return_value = [ mock . sentinel . ephemeral0 , <EOL> mock . sentinel . ephemeral1 ] <EOL> get_swap . return_value = mock . sentinel . swap <EOL> devices = [ mock . sentinel . ephemeral0 , mock . sentinel . ephemeral1 , <EOL> mock . sentinel . swap ] <EOL> self . _vmops . _remove_ephemerals_and_swap ( mock . sentinel . vm_ref ) <EOL> detach_devices . assert_called_once_with ( self . _vmops . _session , <EOL> mock . sentinel . vm_ref , devices ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' , <EOL> return_value = True ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_confirm_migration ( self , fake_get_vm_ref , fake_get_browser , <EOL> fake_original_exists , <EOL> fake_disk_delete ) : <EOL> """<STR_LIT>""" <EOL> datastore = ds_obj . Datastore ( ref = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> device = vmwareapi_fake . DataObject ( ) <EOL> backing = vmwareapi_fake . DataObject ( ) <EOL> backing . datastore = datastore . ref <EOL> device . backing = backing <EOL> vmdk = vm_util . VmdkInfo ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> device ) <EOL> dc_info = ds_util . DcInfo ( ref = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> vmFolder = '<STR_LIT>' ) <EOL> with test . nested ( <EOL> mock . patch . object ( self . _vmops , '<STR_LIT>' , <EOL> return_value = dc_info ) , <EOL> mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = vmdk ) <EOL> ) as ( fake_get_dc_ref_and_name , fake_get_vmdk_info ) : <EOL> self . _vmops . confirm_migration ( None , <EOL> self . _instance , <EOL> None ) <EOL> fake_get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> fake_get_vmdk_info . assert_called_once_with ( <EOL> self . _session , '<STR_LIT>' , uuid = self . _instance . uuid ) <EOL> fake_get_browser . assert_called_once_with ( '<STR_LIT>' ) <EOL> fake_original_exists . assert_called_once_with ( <EOL> self . _session , '<STR_LIT>' , <EOL> ds_obj . DatastorePath ( datastore . name , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> fake_disk_delete . assert_called_once_with ( <EOL> self . _session , dc_info . ref , '<STR_LIT>' ) <EOL> def test_migrate_disk_and_power_off ( self ) : <EOL> self . _test_migrate_disk_and_power_off ( <EOL> flavor_root_gb = self . _instance . root_gb + <NUM_LIT:1> ) <EOL> def test_migrate_disk_and_power_off_zero_disk_flavor ( self ) : <EOL> self . _instance . root_gb = <NUM_LIT:0> <EOL> self . _test_migrate_disk_and_power_off ( flavor_root_gb = <NUM_LIT:0> ) <EOL> def test_migrate_disk_and_power_off_disk_shrink ( self ) : <EOL> self . assertRaises ( exception . InstanceFaultRollback , <EOL> self . _test_migrate_disk_and_power_off , <EOL> flavor_root_gb = self . _instance . root_gb - <NUM_LIT:1> ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , "<STR_LIT>" ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , "<STR_LIT>" ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , "<STR_LIT>" ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , "<STR_LIT>" ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def _test_migrate_disk_and_power_off ( self , fake_get_vm_ref , fake_progress , <EOL> fake_power_off , fake_resize_vm , <EOL> fake_resize_disk , fake_get_vmdk_info , <EOL> fake_remove_ephemerals_and_swap , <EOL> flavor_root_gb ) : <EOL> vmdk = vm_util . VmdkInfo ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> self . _instance . root_gb * units . Gi , <EOL> '<STR_LIT>' ) <EOL> fake_get_vmdk_info . return_value = vmdk <EOL> flavor = fake_flavor . fake_flavor_obj ( self . _context , <EOL> root_gb = flavor_root_gb ) <EOL> self . _vmops . migrate_disk_and_power_off ( self . _context , <EOL> self . _instance , <EOL> None , <EOL> flavor ) <EOL> fake_get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> fake_power_off . assert_called_once_with ( self . _session , <EOL> self . _instance , <EOL> '<STR_LIT>' ) <EOL> fake_resize_vm . assert_called_once_with ( self . _context , self . _instance , <EOL> '<STR_LIT>' , flavor , mock . ANY ) <EOL> fake_resize_disk . assert_called_once_with ( self . _instance , '<STR_LIT>' , <EOL> vmdk , flavor ) <EOL> calls = [ mock . call ( self . _context , self . _instance , step = i , <EOL> total_steps = vmops . RESIZE_TOTAL_STEPS ) <EOL> for i in range ( <NUM_LIT:4> ) ] <EOL> fake_progress . assert_has_calls ( calls ) <EOL> @ mock . patch . object ( vutil , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> def test_configure_config_drive ( self , <EOL> mock_create_config_drive , <EOL> mock_attach_cdrom_to_vm , <EOL> mock_get_inventory_path ) : <EOL> injected_files = mock . Mock ( ) <EOL> admin_password = mock . Mock ( ) <EOL> network_info = mock . Mock ( ) <EOL> vm_ref = mock . Mock ( ) <EOL> mock_create_config_drive . return_value = "<STR_LIT>" <EOL> self . _vmops . _configure_config_drive ( <EOL> self . _instance , vm_ref , self . _dc_info , self . _ds , <EOL> injected_files , admin_password , network_info ) <EOL> upload_iso_path = self . _ds . build_path ( "<STR_LIT>" ) <EOL> mock_get_inventory_path . assert_called_once_with ( self . _session . vim , <EOL> self . _dc_info . ref ) <EOL> mock_create_config_drive . assert_called_once_with ( self . _instance , <EOL> injected_files , admin_password , network_info , self . _ds . name , <EOL> '<STR_LIT>' , self . _instance . uuid , "<STR_LIT>" ) <EOL> mock_attach_cdrom_to_vm . assert_called_once_with ( <EOL> vm_ref , self . _instance , self . _ds . ref , str ( upload_iso_path ) ) <EOL> @ mock . patch . object ( vmops . LOG , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . lockutils , '<STR_LIT>' ) <EOL> def test_spawn_mask_block_device_info_password ( self , mock_lock , <EOL> mock_build_virtual_machine , mock_get_vm_config_info , <EOL> mock_fetch_image_if_missing , mock_debug ) : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' } <EOL> bdm = [ { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : constants . DEFAULT_ADAPTER_TYPE , <EOL> '<STR_LIT>' : { '<STR_LIT:data>' : data } } ] <EOL> bdi = { '<STR_LIT>' : bdm } <EOL> self . password_logged = False <EOL> def fake_debug ( * args , ** kwargs ) : <EOL> if '<STR_LIT>' in args [ <NUM_LIT:0> ] : <EOL> self . password_logged = True <EOL> self . assertNotIn ( '<STR_LIT>' , args [ <NUM_LIT:0> ] ) <EOL> mock_debug . side_effect = fake_debug <EOL> self . flags ( flat_injected = False ) <EOL> self . flags ( enabled = False , group = '<STR_LIT>' ) <EOL> with mock . patch . object ( self . _vmops , '<STR_LIT>' ) as mock_vo : <EOL> mock_vo . attach_root_volume . side_effect = test . TestingException <EOL> try : <EOL> self . _vmops . spawn ( <EOL> self . _context , self . _instance , self . _image_meta , <EOL> injected_files = None , admin_password = None , <EOL> network_info = [ ] , block_device_info = bdi <EOL> ) <EOL> except test . TestingException : <EOL> pass <EOL> self . assertTrue ( self . password_logged ) <EOL> def _get_metadata ( self , is_image_used = True ) : <EOL> if is_image_used : <EOL> image_id = '<STR_LIT>' <EOL> else : <EOL> image_id = None <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { <EOL> '<STR_LIT>' : image_id , <EOL> '<STR_LIT:version>' : version . version_string_with_package ( ) } ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( nova . virt . vmwareapi . images . VMwareImage , <EOL> '<STR_LIT>' ) <EOL> def test_spawn_non_root_block_device ( self , from_image , <EOL> get_extra_specs , <EOL> get_vm_config_info , <EOL> build_virtual_machine , <EOL> enlist_image , fetch_image , <EOL> use_disk_image , <EOL> power_on_instance , <EOL> create_folders , <EOL> rename_vm ) : <EOL> self . _instance . flavor = self . _flavor <EOL> extra_specs = get_extra_specs . return_value <EOL> connection_info1 = { '<STR_LIT:data>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> connection_info2 = { '<STR_LIT:data>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> bdm = [ { '<STR_LIT>' : connection_info1 , <EOL> '<STR_LIT>' : constants . ADAPTER_TYPE_IDE , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : connection_info2 , <EOL> '<STR_LIT>' : constants . DEFAULT_ADAPTER_TYPE , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> bdi = { '<STR_LIT>' : bdm , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . flags ( flat_injected = False ) <EOL> self . flags ( enabled = False , group = '<STR_LIT>' ) <EOL> image_size = ( self . _instance . root_gb ) * units . Gi / <NUM_LIT:2> <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = image_size ) <EOL> vi = get_vm_config_info . return_value <EOL> from_image . return_value = image_info <EOL> build_virtual_machine . return_value = '<STR_LIT>' <EOL> with mock . patch . object ( self . _vmops , '<STR_LIT>' ) as volumeops : <EOL> self . _vmops . spawn ( self . _context , self . _instance , self . _image_meta , <EOL> injected_files = None , admin_password = None , <EOL> network_info = [ ] , block_device_info = bdi ) <EOL> from_image . assert_called_once_with ( self . _instance . image_ref , <EOL> self . _image_meta ) <EOL> get_vm_config_info . assert_called_once_with ( self . _instance , <EOL> image_info , extra_specs ) <EOL> build_virtual_machine . assert_called_once_with ( self . _instance , <EOL> image_info , vi . dc_info , vi . datastore , [ ] , <EOL> extra_specs , self . _get_metadata ( ) ) <EOL> enlist_image . assert_called_once_with ( image_info . image_id , <EOL> vi . datastore , vi . dc_info . ref ) <EOL> fetch_image . assert_called_once_with ( self . _context , vi ) <EOL> use_disk_image . assert_called_once_with ( '<STR_LIT>' , vi ) <EOL> volumeops . attach_volume . assert_any_call ( <EOL> connection_info1 , self . _instance , constants . ADAPTER_TYPE_IDE ) <EOL> volumeops . attach_volume . assert_any_call ( <EOL> connection_info2 , self . _instance , <EOL> constants . DEFAULT_ADAPTER_TYPE ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( nova . virt . vmwareapi . images . VMwareImage , <EOL> '<STR_LIT>' ) <EOL> def test_spawn_with_no_image_and_block_devices ( self , from_image , <EOL> get_extra_specs , <EOL> get_vm_config_info , <EOL> build_virtual_machine , <EOL> power_on_instance , <EOL> create_folders , <EOL> rename_vm ) : <EOL> self . _instance . image_ref = None <EOL> self . _instance . flavor = self . _flavor <EOL> extra_specs = get_extra_specs . return_value <EOL> connection_info1 = { '<STR_LIT:data>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> connection_info2 = { '<STR_LIT:data>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> connection_info3 = { '<STR_LIT:data>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> bdm = [ { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : connection_info1 , <EOL> '<STR_LIT>' : constants . ADAPTER_TYPE_IDE } , <EOL> { '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : connection_info2 , <EOL> '<STR_LIT>' : constants . DEFAULT_ADAPTER_TYPE } , <EOL> { '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : connection_info3 , <EOL> '<STR_LIT>' : constants . ADAPTER_TYPE_LSILOGICSAS } ] <EOL> bdi = { '<STR_LIT>' : bdm } <EOL> self . flags ( flat_injected = False ) <EOL> self . flags ( enabled = False , group = '<STR_LIT>' ) <EOL> image_info = mock . sentinel . image_info <EOL> vi = get_vm_config_info . return_value <EOL> from_image . return_value = image_info <EOL> build_virtual_machine . return_value = '<STR_LIT>' <EOL> with mock . patch . object ( self . _vmops , '<STR_LIT>' ) as volumeops : <EOL> self . _vmops . spawn ( self . _context , self . _instance , self . _image_meta , <EOL> injected_files = None , admin_password = None , <EOL> network_info = [ ] , block_device_info = bdi ) <EOL> from_image . assert_called_once_with ( self . _instance . image_ref , <EOL> self . _image_meta ) <EOL> get_vm_config_info . assert_called_once_with ( self . _instance , <EOL> image_info , extra_specs ) <EOL> build_virtual_machine . assert_called_once_with ( self . _instance , <EOL> image_info , vi . dc_info , vi . datastore , [ ] , <EOL> extra_specs , self . _get_metadata ( is_image_used = False ) ) <EOL> volumeops . attach_root_volume . assert_called_once_with ( <EOL> connection_info1 , self . _instance , vi . datastore . ref , <EOL> constants . ADAPTER_TYPE_IDE ) <EOL> volumeops . attach_volume . assert_any_call ( <EOL> connection_info2 , self . _instance , <EOL> constants . DEFAULT_ADAPTER_TYPE ) <EOL> volumeops . attach_volume . assert_any_call ( <EOL> connection_info3 , self . _instance , <EOL> constants . ADAPTER_TYPE_LSILOGICSAS ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( nova . virt . vmwareapi . images . VMwareImage , <EOL> '<STR_LIT>' ) <EOL> def test_spawn_unsupported_hardware ( self , from_image , <EOL> get_extra_specs , <EOL> get_vm_config_info , <EOL> build_virtual_machine , <EOL> power_on_instance , <EOL> create_folders ) : <EOL> self . _instance . image_ref = None <EOL> self . _instance . flavor = self . _flavor <EOL> extra_specs = get_extra_specs . return_value <EOL> connection_info = { '<STR_LIT:data>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> bdm = [ { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : connection_info , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> bdi = { '<STR_LIT>' : bdm } <EOL> self . flags ( flat_injected = False ) <EOL> self . flags ( enabled = False , group = '<STR_LIT>' ) <EOL> image_info = mock . sentinel . image_info <EOL> vi = get_vm_config_info . return_value <EOL> from_image . return_value = image_info <EOL> build_virtual_machine . return_value = '<STR_LIT>' <EOL> self . assertRaises ( exception . UnsupportedHardware , self . _vmops . spawn , <EOL> self . _context , self . _instance , self . _image_meta , <EOL> injected_files = None , <EOL> admin_password = None , network_info = [ ] , <EOL> block_device_info = bdi ) <EOL> from_image . assert_called_once_with ( self . _instance . image_ref , <EOL> self . _image_meta ) <EOL> get_vm_config_info . assert_called_once_with ( <EOL> self . _instance , image_info , extra_specs ) <EOL> build_virtual_machine . assert_called_once_with ( self . _instance , <EOL> image_info , vi . dc_info , vi . datastore , [ ] , <EOL> extra_specs , self . _get_metadata ( is_image_used = False ) ) <EOL> def test_get_ds_browser ( self ) : <EOL> cache = self . _vmops . _datastore_browser_mapping <EOL> ds_browser = mock . Mock ( ) <EOL> moref = vmwareapi_fake . ManagedObjectReference ( '<STR_LIT>' ) <EOL> self . assertIsNone ( cache . get ( moref . value ) ) <EOL> mock_call_method = mock . Mock ( return_value = ds_browser ) <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> mock_call_method ) : <EOL> ret = self . _vmops . _get_ds_browser ( moref ) <EOL> mock_call_method . assert_called_once_with ( vutil , <EOL> '<STR_LIT>' , moref , '<STR_LIT>' ) <EOL> self . assertIs ( ds_browser , ret ) <EOL> self . assertIs ( ds_browser , cache . get ( moref . value ) ) <EOL> @ mock . patch . object ( <EOL> vmops . VMwareVMOps , '<STR_LIT>' , return_value = False ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> def _test_use_disk_image_as_linked_clone ( self , <EOL> mock_copy_virtual_disk , <EOL> mock_extend_virtual_disk , <EOL> mock_sized_image_exists , <EOL> flavor_fits_image = False ) : <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> file_size = <NUM_LIT:10> * units . Gi if flavor_fits_image else <NUM_LIT:5> * units . Gi <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = file_size , <EOL> linked_clone = False ) <EOL> cache_root_folder = self . _ds . build_path ( "<STR_LIT>" , self . _image_id ) <EOL> mock_imagecache = mock . Mock ( ) <EOL> mock_imagecache . get_image_cache_folder . return_value = cache_root_folder <EOL> vi = vmops . VirtualMachineInstanceConfigInfo ( <EOL> self . _instance , image_info , <EOL> self . _ds , self . _dc_info , mock_imagecache , extra_specs ) <EOL> sized_cached_image_ds_loc = cache_root_folder . join ( <EOL> "<STR_LIT>" % ( self . _image_id , vi . root_gb ) ) <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> mock_attach_disk_to_vm = self . _vmops . _volumeops . attach_disk_to_vm <EOL> self . _vmops . _use_disk_image_as_linked_clone ( "<STR_LIT>" , vi ) <EOL> mock_copy_virtual_disk . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> str ( vi . cache_image_path ) , <EOL> str ( sized_cached_image_ds_loc ) ) <EOL> if not flavor_fits_image : <EOL> mock_extend_virtual_disk . assert_called_once_with ( <EOL> self . _instance , vi . root_gb * units . Mi , <EOL> str ( sized_cached_image_ds_loc ) , <EOL> self . _dc_info . ref ) <EOL> mock_attach_disk_to_vm . assert_called_once_with ( <EOL> "<STR_LIT>" , self . _instance , vi . ii . adapter_type , <EOL> vi . ii . disk_type , <EOL> str ( sized_cached_image_ds_loc ) , <EOL> vi . root_gb * units . Mi , False , <EOL> disk_io_limits = vi . _extra_specs . disk_io_limits ) <EOL> def test_use_disk_image_as_linked_clone ( self ) : <EOL> self . _test_use_disk_image_as_linked_clone ( ) <EOL> def test_use_disk_image_as_linked_clone_flavor_fits_image ( self ) : <EOL> self . _test_use_disk_image_as_linked_clone ( flavor_fits_image = True ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> def _test_use_disk_image_as_full_clone ( self , <EOL> mock_copy_virtual_disk , <EOL> mock_extend_virtual_disk , <EOL> flavor_fits_image = False ) : <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> file_size = <NUM_LIT:10> * units . Gi if flavor_fits_image else <NUM_LIT:5> * units . Gi <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = file_size , <EOL> linked_clone = False ) <EOL> cache_root_folder = self . _ds . build_path ( "<STR_LIT>" , self . _image_id ) <EOL> mock_imagecache = mock . Mock ( ) <EOL> mock_imagecache . get_image_cache_folder . return_value = cache_root_folder <EOL> vi = vmops . VirtualMachineInstanceConfigInfo ( <EOL> self . _instance , image_info , <EOL> self . _ds , self . _dc_info , mock_imagecache , <EOL> extra_specs ) <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> mock_attach_disk_to_vm = self . _vmops . _volumeops . attach_disk_to_vm <EOL> self . _vmops . _use_disk_image_as_full_clone ( "<STR_LIT>" , vi ) <EOL> fake_path = '<STR_LIT>' % { '<STR_LIT>' : self . _uuid } <EOL> mock_copy_virtual_disk . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> str ( vi . cache_image_path ) , <EOL> fake_path ) <EOL> if not flavor_fits_image : <EOL> mock_extend_virtual_disk . assert_called_once_with ( <EOL> self . _instance , vi . root_gb * units . Mi , <EOL> fake_path , self . _dc_info . ref ) <EOL> mock_attach_disk_to_vm . assert_called_once_with ( <EOL> "<STR_LIT>" , self . _instance , vi . ii . adapter_type , <EOL> vi . ii . disk_type , fake_path , <EOL> vi . root_gb * units . Mi , False , <EOL> disk_io_limits = vi . _extra_specs . disk_io_limits ) <EOL> def test_use_disk_image_as_full_clone ( self ) : <EOL> self . _test_use_disk_image_as_full_clone ( ) <EOL> def test_use_disk_image_as_full_clone_image_too_big ( self ) : <EOL> self . _test_use_disk_image_as_full_clone ( flavor_fits_image = True ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> def _test_use_iso_image ( self , <EOL> mock_create_virtual_disk , <EOL> mock_attach_cdrom , <EOL> with_root_disk ) : <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = <NUM_LIT:10> * units . Mi , <EOL> linked_clone = True ) <EOL> cache_root_folder = self . _ds . build_path ( "<STR_LIT>" , self . _image_id ) <EOL> mock_imagecache = mock . Mock ( ) <EOL> mock_imagecache . get_image_cache_folder . return_value = cache_root_folder <EOL> vi = vmops . VirtualMachineInstanceConfigInfo ( <EOL> self . _instance , image_info , <EOL> self . _ds , self . _dc_info , mock_imagecache , extra_specs ) <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> mock_attach_disk_to_vm = self . _vmops . _volumeops . attach_disk_to_vm <EOL> self . _vmops . _use_iso_image ( "<STR_LIT>" , vi ) <EOL> mock_attach_cdrom . assert_called_once_with ( <EOL> "<STR_LIT>" , self . _instance , self . _ds . ref , <EOL> str ( vi . cache_image_path ) ) <EOL> fake_path = '<STR_LIT>' % { '<STR_LIT>' : self . _uuid } <EOL> if with_root_disk : <EOL> mock_create_virtual_disk . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> vi . ii . adapter_type , vi . ii . disk_type , <EOL> fake_path , <EOL> vi . root_gb * units . Mi ) <EOL> linked_clone = False <EOL> mock_attach_disk_to_vm . assert_called_once_with ( <EOL> "<STR_LIT>" , self . _instance , <EOL> vi . ii . adapter_type , vi . ii . disk_type , <EOL> fake_path , <EOL> vi . root_gb * units . Mi , linked_clone , <EOL> disk_io_limits = vi . _extra_specs . disk_io_limits ) <EOL> def test_use_iso_image_with_root_disk ( self ) : <EOL> self . _test_use_iso_image ( with_root_disk = True ) <EOL> def test_use_iso_image_without_root_disk ( self ) : <EOL> self . _test_use_iso_image ( with_root_disk = False ) <EOL> def _verify_spawn_method_calls ( self , mock_call_method , extras = None ) : <EOL> expected_methods = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> if extras : <EOL> expected_methods . extend ( extras ) <EOL> expected_methods . append ( '<STR_LIT>' ) <EOL> recorded_methods = [ c [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] for c in mock_call_method . mock_calls ] <EOL> self . assertEqual ( expected_methods , recorded_methods ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> return_value = [ ] ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> return_value = False ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def _test_spawn ( self , <EOL> mock_copy_virtual_disk , <EOL> mock_power_on_instance , <EOL> mock_get_and_set_vnc_config , <EOL> mock_enlist_image , <EOL> mock_set_machine_id , <EOL> mock_mkdir , <EOL> mock_create_vm , <EOL> mock_get_create_spec , <EOL> mock_is_neutron , <EOL> mock_get_vif_info , <EOL> mock_get_datacenter_ref_and_name , <EOL> mock_get_datastore , <EOL> mock_configure_config_drive , <EOL> mock_update_vnic_index , <EOL> mock_create_folders , <EOL> block_device_info = None , <EOL> extra_specs = None , <EOL> config_drive = False ) : <EOL> if extra_specs is None : <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> image_size = ( self . _instance . root_gb ) * units . Gi / <NUM_LIT:2> <EOL> image = { <EOL> '<STR_LIT:id>' : self . _image_id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : image_size , <EOL> } <EOL> image = objects . ImageMeta . from_dict ( image ) <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = image_size ) <EOL> vi = self . _vmops . _get_vm_config_info ( <EOL> self . _instance , image_info , extra_specs ) <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> network_info = mock . Mock ( ) <EOL> mock_get_datastore . return_value = self . _ds <EOL> mock_get_datacenter_ref_and_name . return_value = self . _dc_info <EOL> mock_call_method = mock . Mock ( return_value = '<STR_LIT>' ) <EOL> if extra_specs is None : <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> with test . nested ( <EOL> mock . patch . object ( self . _session , '<STR_LIT>' ) , <EOL> mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> mock_call_method ) , <EOL> mock . patch . object ( uuidutils , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) , <EOL> mock . patch . object ( images , '<STR_LIT>' ) , <EOL> mock . patch . object ( vutil , '<STR_LIT>' , <EOL> return_value = self . _dc_info . name ) , <EOL> mock . patch . object ( self . _vmops , '<STR_LIT>' , <EOL> return_value = extra_specs ) , <EOL> mock . patch . object ( self . _vmops , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> ) as ( _wait_for_task , _call_method , _generate_uuid , _fetch_image , <EOL> _get_inventory_path , _get_extra_specs , _get_instance_metadata ) : <EOL> self . _vmops . spawn ( self . _context , self . _instance , image , <EOL> injected_files = '<STR_LIT>' , <EOL> admin_password = '<STR_LIT:password>' , <EOL> network_info = network_info , <EOL> block_device_info = block_device_info ) <EOL> mock_is_neutron . assert_called_once_with ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , mock_mkdir . call_count ) <EOL> mock_get_vif_info . assert_called_once_with ( <EOL> self . _session , self . _cluster . obj , False , <EOL> constants . DEFAULT_VIF_MODEL , network_info ) <EOL> mock_get_create_spec . assert_called_once_with ( <EOL> self . _session . vim . client . factory , <EOL> self . _instance , <EOL> '<STR_LIT>' , <EOL> [ ] , <EOL> extra_specs , <EOL> constants . DEFAULT_OS_TYPE , <EOL> profile_spec = None , <EOL> metadata = '<STR_LIT>' ) <EOL> mock_create_vm . assert_called_once_with ( <EOL> self . _session , <EOL> self . _instance , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> self . _cluster . resourcePool ) <EOL> mock_get_and_set_vnc_config . assert_called_once_with ( <EOL> self . _session . vim . client . factory , <EOL> self . _instance , <EOL> '<STR_LIT>' ) <EOL> mock_set_machine_id . assert_called_once_with ( <EOL> self . _session . vim . client . factory , <EOL> self . _instance , <EOL> network_info , <EOL> vm_ref = '<STR_LIT>' ) <EOL> mock_power_on_instance . assert_called_once_with ( <EOL> self . _session , self . _instance , vm_ref = '<STR_LIT>' ) <EOL> if ( block_device_info and <EOL> '<STR_LIT>' in block_device_info ) : <EOL> bdms = block_device_info [ '<STR_LIT>' ] <EOL> for bdm in bdms : <EOL> mock_attach_root = ( <EOL> self . _vmops . _volumeops . attach_root_volume ) <EOL> mock_attach = self . _vmops . _volumeops . attach_volume <EOL> adapter_type = bdm . get ( '<STR_LIT>' ) or vi . ii . adapter_type <EOL> if bdm . get ( '<STR_LIT>' ) == <NUM_LIT:0> : <EOL> mock_attach_root . assert_any_call ( <EOL> bdm [ '<STR_LIT>' ] , self . _instance , <EOL> self . _ds . ref , adapter_type ) <EOL> else : <EOL> mock_attach . assert_any_call ( <EOL> bdm [ '<STR_LIT>' ] , self . _instance , <EOL> self . _ds . ref , adapter_type ) <EOL> mock_enlist_image . assert_called_once_with ( <EOL> self . _image_id , self . _ds , self . _dc_info . ref ) <EOL> upload_file_name = '<STR_LIT>' % ( <EOL> self . _image_id , self . _image_id ) <EOL> _fetch_image . assert_called_once_with ( <EOL> self . _context , <EOL> self . _instance , <EOL> self . _session . _host , <EOL> self . _session . _port , <EOL> self . _dc_info . name , <EOL> self . _ds . name , <EOL> upload_file_name , <EOL> cookies = '<STR_LIT>' ) <EOL> self . assertTrue ( len ( _wait_for_task . mock_calls ) > <NUM_LIT:0> ) <EOL> _get_inventory_path . call_count = <NUM_LIT:1> <EOL> extras = None <EOL> if block_device_info and ( '<STR_LIT>' in block_device_info or <EOL> '<STR_LIT>' in block_device_info ) : <EOL> extras = [ '<STR_LIT>' ] <EOL> self . _verify_spawn_method_calls ( _call_method , extras ) <EOL> dc_ref = '<STR_LIT>' <EOL> source_file = six . text_type ( '<STR_LIT>' % <EOL> ( self . _image_id , self . _image_id ) ) <EOL> dest_file = six . text_type ( '<STR_LIT>' % <EOL> ( self . _image_id , self . _image_id , <EOL> self . _instance [ '<STR_LIT>' ] ) ) <EOL> mock_copy_virtual_disk . assert_called_with ( self . _session , <EOL> dc_ref , <EOL> source_file , <EOL> dest_file ) <EOL> if config_drive : <EOL> mock_configure_config_drive . assert_called_once_with ( <EOL> self . _instance , '<STR_LIT>' , self . _dc_info , <EOL> self . _ds , '<STR_LIT>' , '<STR_LIT:password>' , network_info ) <EOL> mock_update_vnic_index . assert_called_once_with ( <EOL> self . _context , self . _instance , network_info ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> def _test_get_spawn_vm_config_info ( self , <EOL> mock_get_datacenter_ref_and_name , <EOL> mock_get_datastore , <EOL> image_size_bytes = <NUM_LIT:0> ) : <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = image_size_bytes , <EOL> linked_clone = True ) <EOL> mock_get_datastore . return_value = self . _ds <EOL> mock_get_datacenter_ref_and_name . return_value = self . _dc_info <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> vi = self . _vmops . _get_vm_config_info ( self . _instance , image_info , <EOL> extra_specs ) <EOL> self . assertEqual ( image_info , vi . ii ) <EOL> self . assertEqual ( self . _ds , vi . datastore ) <EOL> self . assertEqual ( self . _instance . root_gb , vi . root_gb ) <EOL> self . assertEqual ( self . _instance , vi . instance ) <EOL> self . assertEqual ( self . _instance . uuid , vi . instance . uuid ) <EOL> self . assertEqual ( extra_specs , vi . _extra_specs ) <EOL> cache_image_path = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id , self . _image_id ) <EOL> self . assertEqual ( cache_image_path , str ( vi . cache_image_path ) ) <EOL> cache_image_folder = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id ) <EOL> self . assertEqual ( cache_image_folder , str ( vi . cache_image_folder ) ) <EOL> def test_get_spawn_vm_config_info ( self ) : <EOL> image_size = ( self . _instance . root_gb ) * units . Gi / <NUM_LIT:2> <EOL> self . _test_get_spawn_vm_config_info ( image_size_bytes = image_size ) <EOL> def test_get_spawn_vm_config_info_image_too_big ( self ) : <EOL> image_size = ( self . _instance . root_gb + <NUM_LIT:1> ) * units . Gi <EOL> self . assertRaises ( exception . InstanceUnacceptable , <EOL> self . _test_get_spawn_vm_config_info , <EOL> image_size_bytes = image_size ) <EOL> def test_spawn ( self ) : <EOL> self . _test_spawn ( ) <EOL> def test_spawn_config_drive_enabled ( self ) : <EOL> self . flags ( force_config_drive = True ) <EOL> self . _test_spawn ( config_drive = True ) <EOL> def test_spawn_with_block_device_info ( self ) : <EOL> block_device_info = { <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> } <EOL> self . _test_spawn ( block_device_info = block_device_info ) <EOL> def test_spawn_with_block_device_info_with_config_drive ( self ) : <EOL> self . flags ( force_config_drive = True ) <EOL> block_device_info = { <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> } <EOL> self . _test_spawn ( block_device_info = block_device_info , <EOL> config_drive = True ) <EOL> def _spawn_with_block_device_info_ephemerals ( self , ephemerals ) : <EOL> block_device_info = { '<STR_LIT>' : ephemerals } <EOL> self . _test_spawn ( block_device_info = block_device_info ) <EOL> def test_spawn_with_block_device_info_ephemerals ( self ) : <EOL> ephemerals = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:1> } ] <EOL> self . _spawn_with_block_device_info_ephemerals ( ephemerals ) <EOL> def test_spawn_with_block_device_info_ephemerals_no_disk_bus ( self ) : <EOL> ephemerals = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:1> } ] <EOL> self . _spawn_with_block_device_info_ephemerals ( ephemerals ) <EOL> def test_spawn_with_block_device_info_swap ( self ) : <EOL> block_device_info = { '<STR_LIT>' : { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . _test_spawn ( block_device_info = block_device_info ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( nova . virt . vmwareapi . images . VMwareImage , <EOL> '<STR_LIT>' ) <EOL> def test_spawn_with_ephemerals_and_swap ( self , from_image , <EOL> get_extra_specs , <EOL> get_vm_config_info , <EOL> build_virtual_machine , <EOL> enlist_image , <EOL> fetch_image , <EOL> use_disk_image , <EOL> create_and_attach_thin_disk , <EOL> power_on_instance , <EOL> rename_vm ) : <EOL> self . _instance . flavor = objects . Flavor ( vcpus = <NUM_LIT:1> , memory_mb = <NUM_LIT> , <EOL> name = "<STR_LIT>" , root_gb = <NUM_LIT:1> , <EOL> ephemeral_gb = <NUM_LIT:1> , swap = <NUM_LIT> , <EOL> extra_specs = { } ) <EOL> extra_specs = self . _vmops . _get_extra_specs ( self . _instance . flavor ) <EOL> ephemerals = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:1> } ] <EOL> swap = { '<STR_LIT>' : None , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> bdi = { '<STR_LIT>' : [ ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ephemerals , '<STR_LIT>' : swap } <EOL> metadata = self . _vmops . _get_instance_metadata ( self . _context , <EOL> self . _instance ) <EOL> self . flags ( enabled = False , group = '<STR_LIT>' ) <EOL> self . flags ( flat_injected = False ) <EOL> image_size = ( self . _instance . root_gb ) * units . Gi / <NUM_LIT:2> <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = image_size ) <EOL> vi = get_vm_config_info . return_value <EOL> from_image . return_value = image_info <EOL> build_virtual_machine . return_value = '<STR_LIT>' <EOL> self . _vmops . spawn ( self . _context , self . _instance , { } , <EOL> injected_files = None , admin_password = None , <EOL> network_info = [ ] , block_device_info = bdi ) <EOL> from_image . assert_called_once_with ( self . _instance . image_ref , { } ) <EOL> get_vm_config_info . assert_called_once_with ( self . _instance , <EOL> image_info , extra_specs ) <EOL> build_virtual_machine . assert_called_once_with ( self . _instance , <EOL> image_info , vi . dc_info , vi . datastore , [ ] , extra_specs , metadata ) <EOL> enlist_image . assert_called_once_with ( image_info . image_id , <EOL> vi . datastore , vi . dc_info . ref ) <EOL> fetch_image . assert_called_once_with ( self . _context , vi ) <EOL> use_disk_image . assert_called_once_with ( '<STR_LIT>' , vi ) <EOL> eph0_path = str ( ds_obj . DatastorePath ( vi . datastore . name , <EOL> self . _uuid , <EOL> '<STR_LIT>' ) ) <EOL> eph1_path = str ( ds_obj . DatastorePath ( vi . datastore . name , <EOL> self . _uuid , <EOL> '<STR_LIT>' ) ) <EOL> swap_path = str ( ds_obj . DatastorePath ( vi . datastore . name , <EOL> self . _uuid , <EOL> '<STR_LIT>' ) ) <EOL> create_and_attach_thin_disk . assert_has_calls ( [ <EOL> mock . call ( self . _instance , '<STR_LIT>' , vi . dc_info , <EOL> ephemerals [ <NUM_LIT:0> ] [ '<STR_LIT:size>' ] * units . Mi , vi . ii . adapter_type , <EOL> eph0_path ) , <EOL> mock . call ( self . _instance , '<STR_LIT>' , vi . dc_info , <EOL> ephemerals [ <NUM_LIT:1> ] [ '<STR_LIT:size>' ] * units . Mi , vi . ii . adapter_type , <EOL> eph1_path ) , <EOL> mock . call ( self . _instance , '<STR_LIT>' , vi . dc_info , <EOL> swap [ '<STR_LIT>' ] * units . Ki , vi . ii . adapter_type , <EOL> swap_path ) <EOL> ] ) <EOL> power_on_instance . assert_called_once_with ( self . _session , <EOL> self . _instance , <EOL> vm_ref = '<STR_LIT>' ) <EOL> def _get_fake_vi ( self ) : <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = <NUM_LIT:7> , <EOL> linked_clone = False ) <EOL> vi = vmops . VirtualMachineInstanceConfigInfo ( <EOL> self . _instance , image_info , <EOL> self . _ds , self . _dc_info , mock . Mock ( ) ) <EOL> return vi <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> def test_create_and_attach_thin_disk ( self , mock_create ) : <EOL> vi = self . _get_fake_vi ( ) <EOL> self . _vmops . _volumeops = mock . Mock ( ) <EOL> mock_attach_disk_to_vm = self . _vmops . _volumeops . attach_disk_to_vm <EOL> path = str ( ds_obj . DatastorePath ( vi . datastore . name , self . _uuid , <EOL> '<STR_LIT>' ) ) <EOL> self . _vmops . _create_and_attach_thin_disk ( self . _instance , <EOL> '<STR_LIT>' , <EOL> vi . dc_info , <NUM_LIT:1> , <EOL> '<STR_LIT>' , <EOL> path ) <EOL> mock_create . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , '<STR_LIT>' , <EOL> '<STR_LIT>' , path , <NUM_LIT:1> ) <EOL> mock_attach_disk_to_vm . assert_called_once_with ( <EOL> '<STR_LIT>' , self . _instance , '<STR_LIT>' , <EOL> '<STR_LIT>' , path , <NUM_LIT:1> , False ) <EOL> def test_create_ephemeral_with_bdi ( self ) : <EOL> ephemerals = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:1> } ] <EOL> block_device_info = { '<STR_LIT>' : ephemerals } <EOL> vi = self . _get_fake_vi ( ) <EOL> with mock . patch . object ( <EOL> self . _vmops , '<STR_LIT>' ) as mock_caa : <EOL> self . _vmops . _create_ephemeral ( block_device_info , <EOL> self . _instance , <EOL> '<STR_LIT>' , <EOL> vi . dc_info , vi . datastore , <EOL> self . _uuid , <EOL> vi . ii . adapter_type ) <EOL> mock_caa . assert_called_once_with ( <EOL> self . _instance , '<STR_LIT>' , <EOL> vi . dc_info , <NUM_LIT:1> * units . Mi , '<STR_LIT>' , <EOL> '<STR_LIT>' % self . _uuid ) <EOL> def _test_create_ephemeral_from_instance ( self , bdi ) : <EOL> vi = self . _get_fake_vi ( ) <EOL> with mock . patch . object ( <EOL> self . _vmops , '<STR_LIT>' ) as mock_caa : <EOL> self . _vmops . _create_ephemeral ( bdi , <EOL> self . _instance , <EOL> '<STR_LIT>' , <EOL> vi . dc_info , vi . datastore , <EOL> self . _uuid , <EOL> vi . ii . adapter_type ) <EOL> mock_caa . assert_called_once_with ( <EOL> self . _instance , '<STR_LIT>' , <EOL> vi . dc_info , <NUM_LIT:1> * units . Mi , constants . DEFAULT_ADAPTER_TYPE , <EOL> '<STR_LIT>' % self . _uuid ) <EOL> def test_create_ephemeral_with_bdi_but_no_ephemerals ( self ) : <EOL> block_device_info = { '<STR_LIT>' : [ ] } <EOL> self . _instance . ephemeral_gb = <NUM_LIT:1> <EOL> self . _test_create_ephemeral_from_instance ( block_device_info ) <EOL> def test_create_ephemeral_with_no_bdi ( self ) : <EOL> self . _instance . ephemeral_gb = <NUM_LIT:1> <EOL> self . _test_create_ephemeral_from_instance ( None ) <EOL> def _test_create_swap_from_instance ( self , bdi ) : <EOL> vi = self . _get_fake_vi ( ) <EOL> flavor = objects . Flavor ( vcpus = <NUM_LIT:1> , memory_mb = <NUM_LIT> , ephemeral_gb = <NUM_LIT:1> , <EOL> swap = <NUM_LIT> , extra_specs = { } ) <EOL> self . _instance . flavor = flavor <EOL> with mock . patch . object ( <EOL> self . _vmops , '<STR_LIT>' <EOL> ) as create_and_attach : <EOL> self . _vmops . _create_swap ( bdi , self . _instance , '<STR_LIT>' , <EOL> vi . dc_info , vi . datastore , self . _uuid , <EOL> '<STR_LIT>' ) <EOL> size = flavor . swap * units . Ki <EOL> if bdi is not None : <EOL> swap = bdi . get ( '<STR_LIT>' , { } ) <EOL> size = swap . get ( '<STR_LIT>' , <NUM_LIT:0> ) * units . Ki <EOL> path = str ( ds_obj . DatastorePath ( vi . datastore . name , self . _uuid , <EOL> '<STR_LIT>' ) ) <EOL> create_and_attach . assert_called_once_with ( self . _instance , <EOL> '<STR_LIT>' , vi . dc_info , size , '<STR_LIT>' , path ) <EOL> def test_create_swap_with_bdi ( self ) : <EOL> block_device_info = { '<STR_LIT>' : { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . _test_create_swap_from_instance ( block_device_info ) <EOL> def test_create_swap_with_no_bdi ( self ) : <EOL> self . _test_create_swap_from_instance ( None ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> def test_build_virtual_machine ( self , mock_create_folder ) : <EOL> image_id = nova . tests . unit . image . fake . get_valid_image_id ( ) <EOL> image = images . VMwareImage ( image_id = image_id ) <EOL> extra_specs = vm_util . ExtraSpecs ( ) <EOL> vm_ref = self . _vmops . build_virtual_machine ( self . _instance , <EOL> image , self . _dc_info , <EOL> self . _ds , <EOL> self . network_info , <EOL> extra_specs , <EOL> self . _metadata ) <EOL> vm = vmwareapi_fake . _get_object ( vm_ref ) <EOL> self . assertEqual ( self . _instance . uuid , vm . name ) <EOL> self . assertEqual ( self . _instance . uuid , <EOL> vm . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . _instance_values [ '<STR_LIT>' ] , <EOL> vm . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . _instance_values [ '<STR_LIT>' ] , <EOL> vm . get ( '<STR_LIT>' ) ) <EOL> for optval in vm . get ( '<STR_LIT>' ) . OptionValue : <EOL> if optval . key == '<STR_LIT>' : <EOL> self . assertEqual ( self . _instance_values [ '<STR_LIT>' ] , optval . value ) <EOL> break <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> datastores = vm . datastore . ManagedObjectReference <EOL> self . assertEqual ( <NUM_LIT:1> , len ( datastores ) ) <EOL> datastore = vmwareapi_fake . _get_object ( datastores [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( self . _ds . name , datastore . get ( '<STR_LIT>' ) ) <EOL> devices = vm . get ( '<STR_LIT>' ) . VirtualDevice <EOL> for device in devices : <EOL> if device . obj_name != '<STR_LIT>' : <EOL> continue <EOL> self . assertEqual ( self . _network_values [ '<STR_LIT:address>' ] , <EOL> device . macAddress ) <EOL> break <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_spawn_cpu_limit ( self ) : <EOL> cpu_limits = vm_util . Limits ( limit = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_cpu_reservation ( self ) : <EOL> cpu_limits = vm_util . Limits ( reservation = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_cpu_allocations ( self ) : <EOL> cpu_limits = vm_util . Limits ( limit = <NUM_LIT:7> , <EOL> reservation = <NUM_LIT:6> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_cpu_shares_level ( self ) : <EOL> cpu_limits = vm_util . Limits ( shares_level = '<STR_LIT>' ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_cpu_shares_custom ( self ) : <EOL> cpu_limits = vm_util . Limits ( shares_level = '<STR_LIT>' , <EOL> shares_share = <NUM_LIT> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_memory_limit ( self ) : <EOL> memory_limits = vm_util . Limits ( limit = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( memory_limits = memory_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_memory_reservation ( self ) : <EOL> memory_limits = vm_util . Limits ( reservation = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( memory_limits = memory_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_memory_allocations ( self ) : <EOL> memory_limits = vm_util . Limits ( limit = <NUM_LIT:7> , <EOL> reservation = <NUM_LIT:6> ) <EOL> extra_specs = vm_util . ExtraSpecs ( memory_limits = memory_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_memory_shares_level ( self ) : <EOL> memory_limits = vm_util . Limits ( shares_level = '<STR_LIT>' ) <EOL> extra_specs = vm_util . ExtraSpecs ( memory_limits = memory_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_memory_shares_custom ( self ) : <EOL> memory_limits = vm_util . Limits ( shares_level = '<STR_LIT>' , <EOL> shares_share = <NUM_LIT> ) <EOL> extra_specs = vm_util . ExtraSpecs ( memory_limits = memory_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_vif_limit ( self ) : <EOL> vif_limits = vm_util . Limits ( limit = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( vif_limits = vif_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_vif_reservation ( self ) : <EOL> vif_limits = vm_util . Limits ( reservation = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( vif_limits = vif_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_vif_shares_level ( self ) : <EOL> vif_limits = vm_util . Limits ( shares_level = '<STR_LIT>' ) <EOL> extra_specs = vm_util . ExtraSpecs ( vif_limits = vif_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def test_spawn_vif_shares_custom ( self ) : <EOL> vif_limits = vm_util . Limits ( shares_level = '<STR_LIT>' , <EOL> shares_share = <NUM_LIT> ) <EOL> extra_specs = vm_util . ExtraSpecs ( vif_limits = vif_limits ) <EOL> self . _test_spawn ( extra_specs = extra_specs ) <EOL> def _validate_extra_specs ( self , expected , actual ) : <EOL> self . assertEqual ( expected . cpu_limits . limit , <EOL> actual . cpu_limits . limit ) <EOL> self . assertEqual ( expected . cpu_limits . reservation , <EOL> actual . cpu_limits . reservation ) <EOL> self . assertEqual ( expected . cpu_limits . shares_level , <EOL> actual . cpu_limits . shares_level ) <EOL> self . assertEqual ( expected . cpu_limits . shares_share , <EOL> actual . cpu_limits . shares_share ) <EOL> def _validate_flavor_extra_specs ( self , flavor_extra_specs , expected ) : <EOL> flavor = objects . Flavor ( name = '<STR_LIT>' , <EOL> memory_mb = <NUM_LIT:6> , <EOL> vcpus = <NUM_LIT> , <EOL> root_gb = <NUM_LIT> , <EOL> ephemeral_gb = <NUM_LIT> , <EOL> swap = <NUM_LIT> , <EOL> extra_specs = flavor_extra_specs ) <EOL> flavor_extra_specs = self . _vmops . _get_extra_specs ( flavor , None ) <EOL> self . _validate_extra_specs ( expected , flavor_extra_specs ) <EOL> def test_extra_specs_cpu_limit ( self ) : <EOL> flavor_extra_specs = { '<STR_LIT>' : <NUM_LIT:7> } <EOL> cpu_limits = vm_util . Limits ( limit = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _validate_flavor_extra_specs ( flavor_extra_specs , extra_specs ) <EOL> def test_extra_specs_cpu_reservations ( self ) : <EOL> flavor_extra_specs = { '<STR_LIT>' : <NUM_LIT:7> } <EOL> cpu_limits = vm_util . Limits ( reservation = <NUM_LIT:7> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _validate_flavor_extra_specs ( flavor_extra_specs , extra_specs ) <EOL> def test_extra_specs_cpu_allocations ( self ) : <EOL> flavor_extra_specs = { '<STR_LIT>' : <NUM_LIT:7> , <EOL> '<STR_LIT>' : <NUM_LIT:6> } <EOL> cpu_limits = vm_util . Limits ( limit = <NUM_LIT:7> , <EOL> reservation = <NUM_LIT:6> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _validate_flavor_extra_specs ( flavor_extra_specs , extra_specs ) <EOL> def test_extra_specs_cpu_shares_level ( self ) : <EOL> flavor_extra_specs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> cpu_limits = vm_util . Limits ( shares_level = '<STR_LIT>' ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _validate_flavor_extra_specs ( flavor_extra_specs , extra_specs ) <EOL> def test_extra_specs_cpu_shares_custom ( self ) : <EOL> flavor_extra_specs = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> cpu_limits = vm_util . Limits ( shares_level = '<STR_LIT>' , <EOL> shares_share = <NUM_LIT> ) <EOL> extra_specs = vm_util . ExtraSpecs ( cpu_limits = cpu_limits ) <EOL> self . _validate_flavor_extra_specs ( flavor_extra_specs , extra_specs ) <EOL> def _make_vm_config_info ( self , is_iso = False , is_sparse_disk = False ) : <EOL> disk_type = ( constants . DISK_TYPE_SPARSE if is_sparse_disk <EOL> else constants . DEFAULT_DISK_TYPE ) <EOL> file_type = ( constants . DISK_FORMAT_ISO if is_iso <EOL> else constants . DEFAULT_DISK_FORMAT ) <EOL> image_info = images . VMwareImage ( <EOL> image_id = self . _image_id , <EOL> file_size = <NUM_LIT:10> * units . Mi , <EOL> file_type = file_type , <EOL> disk_type = disk_type , <EOL> linked_clone = True ) <EOL> cache_root_folder = self . _ds . build_path ( "<STR_LIT>" , self . _image_id ) <EOL> mock_imagecache = mock . Mock ( ) <EOL> mock_imagecache . get_image_cache_folder . return_value = cache_root_folder <EOL> vi = vmops . VirtualMachineInstanceConfigInfo ( <EOL> self . _instance , image_info , <EOL> self . _ds , self . _dc_info , mock_imagecache ) <EOL> return vi <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> def _test_fetch_image_if_missing ( self , <EOL> mock_delete_datastore_file , <EOL> mock_cache_flat_image , <EOL> mock_cache_sparse_image , <EOL> mock_cache_iso_image , <EOL> mock_prepare_flat_image , <EOL> mock_prepare_sparse_image , <EOL> mock_prepare_iso_image , <EOL> mock_fetch_image_as_file , <EOL> mock_check_cache_folder , <EOL> is_iso = False , <EOL> is_sparse_disk = False ) : <EOL> tmp_dir_path = mock . Mock ( ) <EOL> tmp_image_path = mock . Mock ( ) <EOL> if is_iso : <EOL> mock_prepare = mock_prepare_iso_image <EOL> mock_cache = mock_cache_iso_image <EOL> elif is_sparse_disk : <EOL> mock_prepare = mock_prepare_sparse_image <EOL> mock_cache = mock_cache_sparse_image <EOL> else : <EOL> mock_prepare = mock_prepare_flat_image <EOL> mock_cache = mock_cache_flat_image <EOL> mock_prepare . return_value = tmp_dir_path , tmp_image_path <EOL> vi = self . _make_vm_config_info ( is_iso , is_sparse_disk ) <EOL> self . _vmops . _fetch_image_if_missing ( self . _context , vi ) <EOL> mock_check_cache_folder . assert_called_once_with ( <EOL> self . _ds . name , self . _ds . ref ) <EOL> mock_prepare . assert_called_once_with ( vi ) <EOL> mock_fetch_image_as_file . assert_called_once_with ( <EOL> self . _context , vi , tmp_image_path ) <EOL> mock_cache . assert_called_once_with ( vi , tmp_image_path ) <EOL> mock_delete_datastore_file . assert_called_once_with ( <EOL> str ( tmp_dir_path ) , self . _dc_info . ref ) <EOL> def test_fetch_image_if_missing ( self ) : <EOL> self . _test_fetch_image_if_missing ( ) <EOL> def test_fetch_image_if_missing_with_sparse ( self ) : <EOL> self . _test_fetch_image_if_missing ( <EOL> is_sparse_disk = True ) <EOL> def test_fetch_image_if_missing_with_iso ( self ) : <EOL> self . _test_fetch_image_if_missing ( <EOL> is_iso = True ) <EOL> def test_get_esx_host_and_cookies ( self ) : <EOL> datastore = mock . Mock ( ) <EOL> datastore . get_connected_hosts . return_value = [ '<STR_LIT>' ] <EOL> file_path = mock . Mock ( ) <EOL> def fake_invoke ( module , method , * args , ** kwargs ) : <EOL> if method == '<STR_LIT>' : <EOL> ticket = mock . Mock ( ) <EOL> ticket . id = '<STR_LIT>' <EOL> return ticket <EOL> elif method == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , fake_invoke ) : <EOL> result = self . _vmops . _get_esx_host_and_cookies ( datastore , <EOL> '<STR_LIT>' , <EOL> file_path ) <EOL> self . assertEqual ( '<STR_LIT>' , result [ <NUM_LIT:0> ] ) <EOL> cookies = result [ <NUM_LIT:1> ] <EOL> self . assertEqual ( <NUM_LIT:1> , len ( cookies ) ) <EOL> self . assertEqual ( '<STR_LIT>' , cookies [ <NUM_LIT:0> ] . name ) <EOL> self . assertEqual ( '<STR_LIT>' , cookies [ <NUM_LIT:0> ] . value ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> def test_fetch_image_as_file ( self , <EOL> mock_get_esx_host_and_cookies , <EOL> mock_fetch_image ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> image_ds_loc = mock . Mock ( ) <EOL> host = mock . Mock ( ) <EOL> dc_name = '<STR_LIT>' <EOL> cookies = mock . Mock ( ) <EOL> mock_get_esx_host_and_cookies . return_value = host , cookies <EOL> self . _vmops . _fetch_image_as_file ( self . _context , vi , image_ds_loc ) <EOL> mock_get_esx_host_and_cookies . assert_called_once_with ( <EOL> vi . datastore , <EOL> dc_name , <EOL> image_ds_loc . rel_path ) <EOL> mock_fetch_image . assert_called_once_with ( <EOL> self . _context , <EOL> vi . instance , <EOL> host , <EOL> self . _session . _port , <EOL> dc_name , <EOL> self . _ds . name , <EOL> image_ds_loc . rel_path , <EOL> cookies = cookies ) <EOL> @ mock . patch . object ( vutil , '<STR_LIT>' ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> def test_fetch_image_as_file_exception ( self , <EOL> mock_get_esx_host_and_cookies , <EOL> mock_fetch_image , <EOL> mock_get_inventory_path ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> image_ds_loc = mock . Mock ( ) <EOL> dc_name = '<STR_LIT>' <EOL> mock_get_esx_host_and_cookies . side_effect = exception . HostNotFound ( host = '<STR_LIT>' ) <EOL> mock_get_inventory_path . return_value = self . _dc_info . name <EOL> self . _vmops . _fetch_image_as_file ( self . _context , vi , image_ds_loc ) <EOL> mock_get_esx_host_and_cookies . assert_called_once_with ( <EOL> vi . datastore , <EOL> dc_name , <EOL> image_ds_loc . rel_path ) <EOL> mock_fetch_image . assert_called_once_with ( <EOL> self . _context , <EOL> vi . instance , <EOL> self . _session . _host , <EOL> self . _session . _port , <EOL> self . _dc_info . name , <EOL> self . _ds . name , <EOL> image_ds_loc . rel_path , <EOL> cookies = '<STR_LIT>' ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' , <EOL> return_value = <NUM_LIT> ) <EOL> def test_fetch_image_as_vapp ( self , mock_fetch_image ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> image_ds_loc = mock . Mock ( ) <EOL> image_ds_loc . parent . basename = '<STR_LIT>' <EOL> self . _vmops . _fetch_image_as_vapp ( self . _context , vi , image_ds_loc ) <EOL> mock_fetch_image . assert_called_once_with ( <EOL> self . _context , <EOL> vi . instance , <EOL> self . _session , <EOL> '<STR_LIT>' , <EOL> self . _ds . name , <EOL> vi . dc_info . vmFolder , <EOL> self . _vmops . _root_resource_pool ) <EOL> self . assertEqual ( vi . ii . file_size , <NUM_LIT> ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' , return_value = <NUM_LIT> ) <EOL> def test_fetch_image_as_ova ( self , mock_fetch_image ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> image_ds_loc = mock . Mock ( ) <EOL> image_ds_loc . parent . basename = '<STR_LIT>' <EOL> self . _vmops . _fetch_image_as_ova ( self . _context , vi , image_ds_loc ) <EOL> mock_fetch_image . assert_called_once_with ( <EOL> self . _context , <EOL> vi . instance , <EOL> self . _session , <EOL> '<STR_LIT>' , <EOL> self . _ds . name , <EOL> vi . dc_info . vmFolder , <EOL> self . _vmops . _root_resource_pool ) <EOL> self . assertEqual ( vi . ii . file_size , <NUM_LIT> ) <EOL> @ mock . patch . object ( uuidutils , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_prepare_iso_image ( self , mock_generate_uuid ) : <EOL> vi = self . _make_vm_config_info ( is_iso = True ) <EOL> tmp_dir_loc , tmp_image_ds_loc = self . _vmops . _prepare_iso_image ( vi ) <EOL> expected_tmp_dir_path = '<STR_LIT>' % ( self . _ds . name ) <EOL> expected_image_path = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id , self . _image_id ) <EOL> self . assertEqual ( str ( tmp_dir_loc ) , expected_tmp_dir_path ) <EOL> self . assertEqual ( str ( tmp_image_ds_loc ) , expected_image_path ) <EOL> @ mock . patch . object ( uuidutils , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_prepare_sparse_image ( self , mock_generate_uuid ) : <EOL> vi = self . _make_vm_config_info ( is_sparse_disk = True ) <EOL> tmp_dir_loc , tmp_image_ds_loc = self . _vmops . _prepare_sparse_image ( vi ) <EOL> expected_tmp_dir_path = '<STR_LIT>' % ( self . _ds . name ) <EOL> expected_image_path = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( tmp_dir_loc ) , expected_tmp_dir_path ) <EOL> self . assertEqual ( str ( tmp_image_ds_loc ) , expected_image_path ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( uuidutils , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_prepare_flat_image ( self , <EOL> mock_generate_uuid , <EOL> mock_delete_datastore_file , <EOL> mock_create_virtual_disk , <EOL> mock_mkdir ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> tmp_dir_loc , tmp_image_ds_loc = self . _vmops . _prepare_flat_image ( vi ) <EOL> expected_tmp_dir_path = '<STR_LIT>' % ( self . _ds . name ) <EOL> expected_image_path = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id , self . _image_id ) <EOL> expected_image_path_parent = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id ) <EOL> expected_path_to_create = '<STR_LIT>' % ( <EOL> self . _ds . name , self . _image_id , self . _image_id ) <EOL> mock_mkdir . assert_called_once_with ( <EOL> self . _session , DsPathMatcher ( expected_image_path_parent ) , <EOL> self . _dc_info . ref ) <EOL> self . assertEqual ( str ( tmp_dir_loc ) , expected_tmp_dir_path ) <EOL> self . assertEqual ( str ( tmp_image_ds_loc ) , expected_image_path ) <EOL> image_info = vi . ii <EOL> mock_create_virtual_disk . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> image_info . adapter_type , <EOL> image_info . disk_type , <EOL> DsPathMatcher ( expected_path_to_create ) , <EOL> image_info . file_size_in_kb ) <EOL> mock_delete_datastore_file . assert_called_once_with ( <EOL> DsPathMatcher ( expected_image_path ) , <EOL> self . _dc_info . ref ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> def test_cache_iso_image ( self , mock_file_move ) : <EOL> vi = self . _make_vm_config_info ( is_iso = True ) <EOL> tmp_image_ds_loc = mock . Mock ( ) <EOL> self . _vmops . _cache_iso_image ( vi , tmp_image_ds_loc ) <EOL> mock_file_move . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> tmp_image_ds_loc . parent , <EOL> DsPathMatcher ( '<STR_LIT>' % self . _image_id ) ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> def test_cache_flat_image ( self , mock_file_move ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> tmp_image_ds_loc = mock . Mock ( ) <EOL> self . _vmops . _cache_flat_image ( vi , tmp_image_ds_loc ) <EOL> mock_file_move . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> tmp_image_ds_loc . parent , <EOL> DsPathMatcher ( '<STR_LIT>' % self . _image_id ) ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> def test_cache_stream_optimized_image ( self , mock_mkdir , mock_disk_move ) : <EOL> vi = self . _make_vm_config_info ( ) <EOL> self . _vmops . _cache_stream_optimized_image ( vi , mock . sentinel . tmp_image ) <EOL> mock_mkdir . assert_called_once_with ( <EOL> self . _session , <EOL> DsPathMatcher ( '<STR_LIT>' % self . _image_id ) , <EOL> self . _dc_info . ref ) <EOL> mock_disk_move . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> mock . sentinel . tmp_image , <EOL> DsPathMatcher ( '<STR_LIT>' % <EOL> ( self . _image_id , self . _image_id ) ) ) <EOL> @ mock . patch . object ( ds_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vmops . VMwareVMOps , '<STR_LIT>' ) <EOL> def test_cache_sparse_image ( self , <EOL> mock_update_image_size , <EOL> mock_delete_datastore_file , <EOL> mock_copy_virtual_disk , <EOL> mock_file_move ) : <EOL> vi = self . _make_vm_config_info ( is_sparse_disk = True ) <EOL> sparse_disk_path = "<STR_LIT>" % ( <EOL> self . _ds . name , self . _image_id ) <EOL> tmp_image_ds_loc = ds_obj . DatastorePath . parse ( sparse_disk_path ) <EOL> self . _vmops . _cache_sparse_image ( vi , tmp_image_ds_loc ) <EOL> target_disk_path = "<STR_LIT>" % ( <EOL> self . _ds . name , <EOL> self . _image_id , self . _image_id ) <EOL> mock_copy_virtual_disk . assert_called_once_with ( <EOL> self . _session , self . _dc_info . ref , <EOL> sparse_disk_path , <EOL> DsPathMatcher ( target_disk_path ) ) <EOL> mock_update_image_size . assert_called_once_with ( vi ) <EOL> def test_get_storage_policy_none ( self ) : <EOL> flavor = objects . Flavor ( name = '<STR_LIT>' , <EOL> memory_mb = <NUM_LIT:6> , <EOL> vcpus = <NUM_LIT> , <EOL> root_gb = <NUM_LIT> , <EOL> ephemeral_gb = <NUM_LIT> , <EOL> swap = <NUM_LIT> , <EOL> extra_specs = { } ) <EOL> self . flags ( pbm_enabled = True , <EOL> pbm_default_policy = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> extra_specs = self . _vmops . _get_extra_specs ( flavor , None ) <EOL> self . assertEqual ( '<STR_LIT>' , extra_specs . storage_policy ) <EOL> def test_get_storage_policy_extra_specs ( self ) : <EOL> extra_specs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> flavor = objects . Flavor ( name = '<STR_LIT>' , <EOL> memory_mb = <NUM_LIT:6> , <EOL> vcpus = <NUM_LIT> , <EOL> root_gb = <NUM_LIT> , <EOL> ephemeral_gb = <NUM_LIT> , <EOL> swap = <NUM_LIT> , <EOL> extra_specs = extra_specs ) <EOL> self . flags ( pbm_enabled = True , <EOL> pbm_default_policy = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> extra_specs = self . _vmops . _get_extra_specs ( flavor , None ) <EOL> self . assertEqual ( '<STR_LIT>' , extra_specs . storage_policy ) <EOL> def test_get_base_folder_not_set ( self ) : <EOL> self . flags ( image_cache_subdirectory_name = '<STR_LIT>' ) <EOL> base_folder = self . _vmops . _get_base_folder ( ) <EOL> self . assertEqual ( '<STR_LIT>' , base_folder ) <EOL> def test_get_base_folder_host_ip ( self ) : <EOL> self . flags ( my_ip = '<STR_LIT>' , <EOL> image_cache_subdirectory_name = '<STR_LIT>' ) <EOL> base_folder = self . _vmops . _get_base_folder ( ) <EOL> self . assertEqual ( '<STR_LIT>' , base_folder ) <EOL> def test_get_base_folder_cache_prefix ( self ) : <EOL> self . flags ( cache_prefix = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> self . flags ( image_cache_subdirectory_name = '<STR_LIT>' ) <EOL> base_folder = self . _vmops . _get_base_folder ( ) <EOL> self . assertEqual ( '<STR_LIT>' , base_folder ) <EOL> def _test_reboot_vm ( self , reboot_type = "<STR_LIT>" ) : <EOL> expected_methods = [ '<STR_LIT>' ] <EOL> if reboot_type == "<STR_LIT>" : <EOL> expected_methods . append ( '<STR_LIT>' ) <EOL> else : <EOL> expected_methods . append ( '<STR_LIT>' ) <EOL> query = { } <EOL> query [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> query [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> query [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def fake_call_method ( module , method , * args , ** kwargs ) : <EOL> expected_method = expected_methods . pop ( <NUM_LIT:0> ) <EOL> self . assertEqual ( expected_method , method ) <EOL> if expected_method == '<STR_LIT>' : <EOL> return query <EOL> elif expected_method == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> with test . nested ( <EOL> mock . patch . object ( vm_util , "<STR_LIT>" , <EOL> return_value = '<STR_LIT>' ) , <EOL> mock . patch . object ( self . _session , "<STR_LIT>" , <EOL> fake_call_method ) , <EOL> mock . patch . object ( self . _session , "<STR_LIT>" ) <EOL> ) as ( _get_vm_ref , fake_call_method , _wait_for_task ) : <EOL> self . _vmops . reboot ( self . _instance , self . network_info , reboot_type ) <EOL> _get_vm_ref . assert_called_once_with ( self . _session , <EOL> self . _instance ) <EOL> if reboot_type == "<STR_LIT>" : <EOL> _wait_for_task . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' ) ] ) <EOL> def test_reboot_vm_soft ( self ) : <EOL> self . _test_reboot_vm ( ) <EOL> def test_reboot_vm_hard ( self ) : <EOL> self . _test_reboot_vm ( reboot_type = "<STR_LIT>" ) <EOL> def test_get_instance_metadata ( self ) : <EOL> flavor = objects . Flavor ( id = <NUM_LIT:7> , <EOL> name = '<STR_LIT>' , <EOL> memory_mb = <NUM_LIT:6> , <EOL> vcpus = <NUM_LIT> , <EOL> root_gb = <NUM_LIT> , <EOL> ephemeral_gb = <NUM_LIT> , <EOL> swap = <NUM_LIT> , <EOL> extra_specs = { } ) <EOL> self . _instance . flavor = flavor <EOL> metadata = self . _vmops . _get_instance_metadata ( <EOL> self . _context , self . _instance ) <EOL> expected = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % version . version_string_with_package ( ) ) <EOL> self . assertEqual ( expected , metadata ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = <NUM_LIT:1> ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_attach_interface ( self , mock_get_vm_ref , <EOL> mock_get_attach_port_index , <EOL> mock_get_network_attach_config_spec , <EOL> mock_reconfigure_vm ) : <EOL> _network_api = mock . Mock ( ) <EOL> self . _vmops . _network_api = _network_api <EOL> vif_info = vif . get_vif_dict ( self . _session , self . _cluster , <EOL> '<STR_LIT>' , <EOL> utils . is_neutron ( ) , <EOL> self . _network_values ) <EOL> self . _vmops . attach_interface ( self . _instance , self . _image_meta , <EOL> self . _network_values ) <EOL> mock_get_vm_ref . assert_called_once_with ( self . _session , self . _instance ) <EOL> mock_get_attach_port_index ( self . _session , '<STR_LIT>' ) <EOL> mock_get_network_attach_config_spec . assert_called_once_with ( <EOL> self . _session . vim . client . factory , vif_info , <NUM_LIT:1> ) <EOL> mock_reconfigure_vm . assert_called_once_with ( self . _session , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> _network_api . update_instance_vnic_index ( mock . ANY , <EOL> self . _instance , self . _network_values , <NUM_LIT:1> ) <EOL> @ mock . patch . object ( vif , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = <NUM_LIT:1> ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_detach_interface ( self , mock_get_vm_ref , <EOL> mock_get_detach_port_index , <EOL> mock_get_network_detach_config_spec , <EOL> mock_reconfigure_vm , <EOL> mock_get_network_device ) : <EOL> _network_api = mock . Mock ( ) <EOL> self . _vmops . _network_api = _network_api <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) : <EOL> self . _vmops . detach_interface ( self . _instance , self . _network_values ) <EOL> mock_get_vm_ref . assert_called_once_with ( self . _session , self . _instance ) <EOL> mock_get_detach_port_index ( self . _session , '<STR_LIT>' ) <EOL> mock_get_network_detach_config_spec . assert_called_once_with ( <EOL> self . _session . vim . client . factory , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> mock_reconfigure_vm . assert_called_once_with ( self . _session , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> _network_api . update_instance_vnic_index ( mock . ANY , <EOL> self . _instance , self . _network_values , None ) <EOL> @ mock . patch . object ( vm_util , '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_get_mks_console ( self , mock_get_vm_ref ) : <EOL> ticket = mock . MagicMock ( ) <EOL> ticket . host = '<STR_LIT>' <EOL> ticket . port = <NUM_LIT> <EOL> ticket . ticket = '<STR_LIT>' <EOL> ticket . sslThumbprint = '<STR_LIT>' <EOL> ticket . cfgFile = '<STR_LIT>' <EOL> with mock . patch . object ( self . _session , '<STR_LIT>' , <EOL> return_value = ticket ) : <EOL> console = self . _vmops . get_mks_console ( self . _instance ) <EOL> self . assertEqual ( '<STR_LIT>' , console . host ) <EOL> self . assertEqual ( <NUM_LIT> , console . port ) <EOL> path = jsonutils . loads ( console . internal_access_path ) <EOL> self . assertEqual ( '<STR_LIT>' , path [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , path [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , path [ '<STR_LIT>' ] ) <EOL> def test_get_cores_per_socket ( self ) : <EOL> extra_specs = { '<STR_LIT>' : <NUM_LIT:7> } <EOL> flavor = objects . Flavor ( name = '<STR_LIT>' , <EOL> memory_mb = <NUM_LIT:6> , <EOL> vcpus = <NUM_LIT> , <EOL> root_gb = <NUM_LIT> , <EOL> ephemeral_gb = <NUM_LIT> , <EOL> swap = <NUM_LIT> , <EOL> extra_specs = extra_specs ) <EOL> extra_specs = self . _vmops . _get_extra_specs ( flavor , None ) <EOL> self . assertEqual ( <NUM_LIT:4> , int ( extra_specs . cores_per_socket ) ) <EOL> def test_get_folder_name ( self ) : <EOL> uuid = uuidutils . generate_uuid ( ) <EOL> name = '<STR_LIT>' <EOL> expected = '<STR_LIT>' % uuid <EOL> folder_name = self . _vmops . _get_folder_name ( name , uuid ) <EOL> self . assertEqual ( expected , folder_name ) <EOL> name = '<STR_LIT:X>' * <NUM_LIT:255> <EOL> expected = '<STR_LIT>' % ( '<STR_LIT:X>' * <NUM_LIT> , uuid ) <EOL> folder_name = self . _vmops . _get_folder_name ( name , uuid ) <EOL> self . assertEqual ( expected , folder_name ) <EOL> self . assertEqual ( <NUM_LIT> , len ( folder_name ) ) </s>
