<s> import mock <EOL> import oslo_messaging as messaging <EOL> from nova . compute import power_state <EOL> from nova . compute import rpcapi as compute_rpcapi <EOL> from nova . compute import vm_states <EOL> from nova . conductor . tasks import live_migrate <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova . scheduler import client as scheduler_client <EOL> from nova . scheduler import utils as scheduler_utils <EOL> from nova import servicegroup <EOL> from nova import test <EOL> from nova . tests . unit import fake_instance <EOL> from nova . tests import uuidsentinel as uuids <EOL> from nova import utils <EOL> class LiveMigrationTaskTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( LiveMigrationTaskTestCase , self ) . setUp ( ) <EOL> self . context = "<STR_LIT>" <EOL> self . instance_host = "<STR_LIT:host>" <EOL> self . instance_uuid = uuids . instance <EOL> self . instance_image = "<STR_LIT>" <EOL> db_instance = fake_instance . fake_db_instance ( <EOL> host = self . instance_host , <EOL> uuid = self . instance_uuid , <EOL> power_state = power_state . RUNNING , <EOL> vm_state = vm_states . ACTIVE , <EOL> memory_mb = <NUM_LIT> , <EOL> image_ref = self . instance_image ) <EOL> self . instance = objects . Instance . _from_db_object ( <EOL> self . context , objects . Instance ( ) , db_instance ) <EOL> self . instance . system_metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . destination = "<STR_LIT>" <EOL> self . block_migration = "<STR_LIT>" <EOL> self . disk_over_commit = "<STR_LIT>" <EOL> self . migration = objects . Migration ( ) <EOL> self . fake_spec = objects . RequestSpec ( ) <EOL> self . _generate_task ( ) <EOL> def _generate_task ( self ) : <EOL> self . task = live_migrate . LiveMigrationTask ( self . context , <EOL> self . instance , self . destination , self . block_migration , <EOL> self . disk_over_commit , self . migration , compute_rpcapi . ComputeAPI ( ) , <EOL> servicegroup . API ( ) , scheduler_client . SchedulerClient ( ) , <EOL> self . fake_spec ) <EOL> def test_execute_with_destination ( self ) : <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . compute_rpcapi , '<STR_LIT>' ) <EOL> self . task . _check_host_is_up ( self . instance_host ) <EOL> self . task . _check_requested_destination ( ) <EOL> self . task . compute_rpcapi . live_migration ( self . context , <EOL> host = self . instance_host , <EOL> instance = self . instance , <EOL> dest = self . destination , <EOL> block_migration = self . block_migration , <EOL> migration = self . migration , <EOL> migrate_data = None ) . AndReturn ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . execute ( ) ) <EOL> def test_execute_without_destination ( self ) : <EOL> self . destination = None <EOL> self . _generate_task ( ) <EOL> self . assertIsNone ( self . task . destination ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . compute_rpcapi , '<STR_LIT>' ) <EOL> self . task . _check_host_is_up ( self . instance_host ) <EOL> self . task . _find_destination ( ) . AndReturn ( "<STR_LIT>" ) <EOL> self . task . compute_rpcapi . live_migration ( self . context , <EOL> host = self . instance_host , <EOL> instance = self . instance , <EOL> dest = "<STR_LIT>" , <EOL> block_migration = self . block_migration , <EOL> migration = self . migration , <EOL> migrate_data = None ) . AndReturn ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> with mock . patch . object ( self . migration , '<STR_LIT>' ) as mock_save : <EOL> self . assertEqual ( "<STR_LIT>" , self . task . execute ( ) ) <EOL> self . assertTrue ( mock_save . called ) <EOL> self . assertEqual ( '<STR_LIT>' , self . migration . dest_compute ) <EOL> def test_check_instance_is_active_passes_when_paused ( self ) : <EOL> self . task . instance [ '<STR_LIT>' ] = power_state . PAUSED <EOL> self . task . _check_instance_is_active ( ) <EOL> def test_check_instance_is_active_fails_when_shutdown ( self ) : <EOL> self . task . instance [ '<STR_LIT>' ] = power_state . SHUTDOWN <EOL> self . assertRaises ( exception . InstanceInvalidState , <EOL> self . task . _check_instance_is_active ) <EOL> def test_check_instance_host_is_up ( self ) : <EOL> self . mox . StubOutWithMock ( objects . Service , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . servicegroup_api , '<STR_LIT>' ) <EOL> objects . Service . get_by_compute_host ( self . context , <EOL> "<STR_LIT:host>" ) . AndReturn ( "<STR_LIT>" ) <EOL> self . task . servicegroup_api . service_is_up ( "<STR_LIT>" ) . AndReturn ( True ) <EOL> self . mox . ReplayAll ( ) <EOL> self . task . _check_host_is_up ( "<STR_LIT:host>" ) <EOL> def test_check_instance_host_is_up_fails_if_not_up ( self ) : <EOL> self . mox . StubOutWithMock ( objects . Service , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . servicegroup_api , '<STR_LIT>' ) <EOL> objects . Service . get_by_compute_host ( self . context , <EOL> "<STR_LIT:host>" ) . AndReturn ( "<STR_LIT>" ) <EOL> self . task . servicegroup_api . service_is_up ( "<STR_LIT>" ) . AndReturn ( False ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . ComputeServiceUnavailable , <EOL> self . task . _check_host_is_up , "<STR_LIT:host>" ) <EOL> def test_check_instance_host_is_up_fails_if_not_found ( self ) : <EOL> self . mox . StubOutWithMock ( objects . Service , '<STR_LIT>' ) <EOL> objects . Service . get_by_compute_host ( <EOL> self . context , "<STR_LIT:host>" ) . AndRaise ( exception . NotFound ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . ComputeServiceUnavailable , <EOL> self . task . _check_host_is_up , "<STR_LIT:host>" ) <EOL> def test_check_requested_destination ( self ) : <EOL> self . mox . StubOutWithMock ( objects . Service , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . servicegroup_api , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . compute_rpcapi , <EOL> '<STR_LIT>' ) <EOL> objects . Service . get_by_compute_host ( <EOL> self . context , self . destination ) . AndReturn ( "<STR_LIT>" ) <EOL> self . task . servicegroup_api . service_is_up ( "<STR_LIT>" ) . AndReturn ( True ) <EOL> hypervisor_details = objects . ComputeNode ( <EOL> hypervisor_type = "<STR_LIT:a>" , <EOL> hypervisor_version = <NUM_LIT> , <EOL> free_ram_mb = <NUM_LIT> , <EOL> memory_mb = <NUM_LIT> , <EOL> ram_allocation_ratio = <NUM_LIT:1.0> , <EOL> ) <EOL> self . task . _get_compute_info ( self . destination ) . AndReturn ( hypervisor_details ) <EOL> self . task . _get_compute_info ( self . instance_host ) . AndReturn ( hypervisor_details ) <EOL> self . task . _get_compute_info ( self . destination ) . AndReturn ( hypervisor_details ) <EOL> self . task . compute_rpcapi . check_can_live_migrate_destination ( <EOL> self . context , self . instance , self . destination , <EOL> self . block_migration , self . disk_over_commit ) . AndReturn ( <EOL> "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . task . _check_requested_destination ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . migrate_data ) <EOL> def test_check_requested_destination_fails_with_same_dest ( self ) : <EOL> self . task . destination = "<STR_LIT>" <EOL> self . task . source = "<STR_LIT>" <EOL> self . assertRaises ( exception . UnableToMigrateToSelf , <EOL> self . task . _check_requested_destination ) <EOL> def test_check_requested_destination_fails_when_destination_is_up ( self ) : <EOL> self . mox . StubOutWithMock ( objects . Service , '<STR_LIT>' ) <EOL> objects . Service . get_by_compute_host ( <EOL> self . context , self . destination ) . AndRaise ( exception . NotFound ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . ComputeServiceUnavailable , <EOL> self . task . _check_requested_destination ) <EOL> def test_check_requested_destination_fails_with_not_enough_memory ( self ) : <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( objects . ComputeNode , <EOL> '<STR_LIT>' ) <EOL> self . task . _check_host_is_up ( self . destination ) <EOL> objects . ComputeNode . get_first_node_by_host_for_old_compat ( self . context , <EOL> self . destination ) . AndReturn ( <EOL> objects . ComputeNode ( free_ram_mb = <NUM_LIT> , <EOL> memory_mb = <NUM_LIT> , <EOL> ram_allocation_ratio = <NUM_LIT> , <EOL> ) ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . MigrationPreCheckError , <EOL> self . task . _check_requested_destination ) <EOL> def test_check_requested_destination_fails_with_hypervisor_diff ( self ) : <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . task . _check_host_is_up ( self . destination ) <EOL> self . task . _check_destination_has_enough_memory ( ) <EOL> self . task . _get_compute_info ( self . instance_host ) . AndReturn ( <EOL> objects . ComputeNode ( hypervisor_type = '<STR_LIT:b>' ) <EOL> ) <EOL> self . task . _get_compute_info ( self . destination ) . AndReturn ( <EOL> objects . ComputeNode ( hypervisor_type = '<STR_LIT:a>' ) <EOL> ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . InvalidHypervisorType , <EOL> self . task . _check_requested_destination ) <EOL> def test_check_requested_destination_fails_with_hypervisor_too_old ( self ) : <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> self . task . _check_host_is_up ( self . destination ) <EOL> self . task . _check_destination_has_enough_memory ( ) <EOL> host1 = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : <NUM_LIT:7> } <EOL> self . task . _get_compute_info ( self . instance_host ) . AndReturn ( <EOL> objects . ComputeNode ( ** host1 ) <EOL> ) <EOL> host2 = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : <NUM_LIT:6> } <EOL> self . task . _get_compute_info ( self . destination ) . AndReturn ( <EOL> objects . ComputeNode ( ** host2 ) <EOL> ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . DestinationHypervisorTooOld , <EOL> self . task . _check_requested_destination ) <EOL> def test_find_destination_works ( self ) : <EOL> self . mox . StubOutWithMock ( utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( objects . RequestSpec , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> utils . get_image_from_system_metadata ( <EOL> self . instance . system_metadata ) . AndReturn ( "<STR_LIT:image>" ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . fake_spec . reset_forced_destinations ( ) <EOL> self . task . scheduler_client . select_destinations ( <EOL> self . context , self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . _find_destination ( ) ) <EOL> def test_find_destination_works_with_no_request_spec ( self ) : <EOL> task = live_migrate . LiveMigrationTask ( <EOL> self . context , self . instance , self . destination , <EOL> self . block_migration , self . disk_over_commit , self . migration , <EOL> compute_rpcapi . ComputeAPI ( ) , servicegroup . API ( ) , <EOL> scheduler_client . SchedulerClient ( ) , request_spec = None ) <EOL> another_spec = objects . RequestSpec ( ) <EOL> self . instance . flavor = objects . Flavor ( ) <EOL> self . instance . numa_topology = None <EOL> self . instance . pci_requests = None <EOL> @ mock . patch . object ( task , '<STR_LIT>' ) <EOL> @ mock . patch . object ( task , '<STR_LIT>' ) <EOL> @ mock . patch . object ( task . scheduler_client , '<STR_LIT>' ) <EOL> @ mock . patch . object ( objects . RequestSpec , '<STR_LIT>' ) <EOL> @ mock . patch . object ( scheduler_utils , '<STR_LIT>' ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' ) <EOL> def do_test ( get_image , setup_ig , from_components , select_dest , <EOL> check_compat , call_livem_checks ) : <EOL> get_image . return_value = "<STR_LIT:image>" <EOL> from_components . return_value = another_spec <EOL> select_dest . return_value = [ { '<STR_LIT:host>' : '<STR_LIT>' } ] <EOL> self . assertEqual ( "<STR_LIT>" , task . _find_destination ( ) ) <EOL> get_image . assert_called_once_with ( self . instance . system_metadata ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> setup_ig . assert_called_once_with ( <EOL> self . context , fake_props , <EOL> { '<STR_LIT>' : [ self . instance_host ] } <EOL> ) <EOL> select_dest . assert_called_once_with ( self . context , another_spec ) <EOL> check_compat . assert_called_once_with ( "<STR_LIT>" ) <EOL> call_livem_checks . assert_called_once_with ( "<STR_LIT>" ) <EOL> do_test ( ) <EOL> def test_find_destination_no_image_works ( self ) : <EOL> self . instance [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . _find_destination ( ) ) <EOL> def _test_find_destination_retry_hypervisor_raises ( self , error ) : <EOL> self . mox . StubOutWithMock ( utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> utils . get_image_from_system_metadata ( <EOL> self . instance . system_metadata ) . AndReturn ( "<STR_LIT:image>" ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) . AndRaise ( error ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . _find_destination ( ) ) <EOL> def test_find_destination_retry_with_old_hypervisor ( self ) : <EOL> self . _test_find_destination_retry_hypervisor_raises ( <EOL> exception . DestinationHypervisorTooOld ) <EOL> def test_find_destination_retry_with_invalid_hypervisor_type ( self ) : <EOL> self . _test_find_destination_retry_hypervisor_raises ( <EOL> exception . InvalidHypervisorType ) <EOL> def test_find_destination_retry_with_invalid_livem_checks ( self ) : <EOL> self . flags ( migrate_max_retries = <NUM_LIT:1> ) <EOL> self . mox . StubOutWithMock ( utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> utils . get_image_from_system_metadata ( <EOL> self . instance . system_metadata ) . AndReturn ( "<STR_LIT:image>" ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) . AndRaise ( exception . Invalid ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . _find_destination ( ) ) <EOL> def test_find_destination_retry_with_failed_migration_pre_checks ( self ) : <EOL> self . flags ( migrate_max_retries = <NUM_LIT:1> ) <EOL> self . mox . StubOutWithMock ( utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , '<STR_LIT>' ) <EOL> utils . get_image_from_system_metadata ( <EOL> self . instance . system_metadata ) . AndReturn ( "<STR_LIT:image>" ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) . AndRaise ( exception . MigrationPreCheckError ( "<STR_LIT>" ) ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) <EOL> self . task . _call_livem_checks_on_host ( "<STR_LIT>" ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . task . _find_destination ( ) ) <EOL> def test_find_destination_retry_exceeds_max ( self ) : <EOL> self . flags ( migrate_max_retries = <NUM_LIT:0> ) <EOL> self . mox . StubOutWithMock ( utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task , <EOL> '<STR_LIT>' ) <EOL> utils . get_image_from_system_metadata ( <EOL> self . instance . system_metadata ) . AndReturn ( "<STR_LIT:image>" ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndReturn ( <EOL> [ { '<STR_LIT:host>' : '<STR_LIT>' } ] ) <EOL> self . task . _check_compatible_with_source_hypervisor ( "<STR_LIT>" ) . AndRaise ( exception . DestinationHypervisorTooOld ) <EOL> self . mox . ReplayAll ( ) <EOL> with mock . patch . object ( self . task . migration , '<STR_LIT>' ) as save_mock : <EOL> self . assertRaises ( exception . MaxRetriesExceeded , <EOL> self . task . _find_destination ) <EOL> self . assertEqual ( '<STR_LIT>' , self . task . migration . status ) <EOL> save_mock . assert_called_once_with ( ) <EOL> def test_find_destination_when_runs_out_of_hosts ( self ) : <EOL> self . mox . StubOutWithMock ( utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( scheduler_utils , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) <EOL> utils . get_image_from_system_metadata ( <EOL> self . instance . system_metadata ) . AndReturn ( "<STR_LIT:image>" ) <EOL> fake_props = { '<STR_LIT>' : { '<STR_LIT>' : self . instance_uuid } } <EOL> scheduler_utils . setup_instance_group ( <EOL> self . context , fake_props , { '<STR_LIT>' : [ self . instance_host ] } ) <EOL> self . task . scheduler_client . select_destinations ( self . context , <EOL> self . fake_spec ) . AndRaise ( <EOL> exception . NoValidHost ( reason = "<STR_LIT>" ) ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertRaises ( exception . NoValidHost , self . task . _find_destination ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_find_destination_with_remoteError ( self , <EOL> m_from_primitives , m_setup_instance_group , <EOL> m_build_request_spec , m_get_image_from_system_metadata ) : <EOL> m_get_image_from_system_metadata . return_value = { '<STR_LIT>' : { } } <EOL> m_build_request_spec . return_value = { } <EOL> fake_spec = objects . RequestSpec ( ) <EOL> m_from_primitives . return_value = fake_spec <EOL> with mock . patch . object ( self . task . scheduler_client , <EOL> '<STR_LIT>' ) as m_select_destinations : <EOL> error = messaging . RemoteError ( ) <EOL> m_select_destinations . side_effect = error <EOL> self . assertRaises ( exception . MigrationSchedulerRPCError , <EOL> self . task . _find_destination ) <EOL> def test_call_livem_checks_on_host ( self ) : <EOL> with mock . patch . object ( self . task . compute_rpcapi , <EOL> '<STR_LIT>' , <EOL> side_effect = messaging . MessagingTimeout ) : <EOL> self . assertRaises ( exception . MigrationPreCheckError , <EOL> self . task . _call_livem_checks_on_host , { } ) </s>
