<s> import mock <EOL> import oslo_messaging as messaging <EOL> from nova import context <EOL> from nova import objects <EOL> from nova . objects import pci_device_pool <EOL> from nova . scheduler import client as scheduler_client <EOL> from nova . scheduler . client import query as scheduler_query_client <EOL> from nova . scheduler . client import report as scheduler_report_client <EOL> from nova . scheduler import rpcapi as scheduler_rpcapi <EOL> from nova import test <EOL> """<STR_LIT>""" <EOL> class SchedulerReportClientTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SchedulerReportClientTestCase , self ) . setUp ( ) <EOL> self . context = context . get_admin_context ( ) <EOL> self . flags ( use_local = True , group = '<STR_LIT>' ) <EOL> self . client = scheduler_report_client . SchedulerReportClient ( ) <EOL> @ mock . patch . object ( objects . ComputeNode , '<STR_LIT>' ) <EOL> def test_update_resource_stats_saves ( self , mock_save ) : <EOL> cn = objects . ComputeNode ( ) <EOL> cn . host = '<STR_LIT>' <EOL> cn . hypervisor_hostname = '<STR_LIT>' <EOL> cn . pci_device_pools = pci_device_pool . from_pci_stats ( <EOL> [ { "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT:count>" : <NUM_LIT:1> , <EOL> "<STR_LIT:a>" : "<STR_LIT:b>" } ] ) <EOL> self . client . update_resource_stats ( cn ) <EOL> mock_save . assert_called_once_with ( ) <EOL> class SchedulerQueryClientTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SchedulerQueryClientTestCase , self ) . setUp ( ) <EOL> self . context = context . get_admin_context ( ) <EOL> self . client = scheduler_query_client . SchedulerQueryClient ( ) <EOL> def test_constructor ( self ) : <EOL> self . assertIsNotNone ( self . client . scheduler_rpcapi ) <EOL> @ mock . patch . object ( scheduler_rpcapi . SchedulerAPI , '<STR_LIT>' ) <EOL> def test_select_destinations ( self , mock_select_destinations ) : <EOL> fake_spec = objects . RequestSpec ( ) <EOL> self . client . select_destinations ( <EOL> context = self . context , <EOL> spec_obj = fake_spec <EOL> ) <EOL> mock_select_destinations . assert_called_once_with ( <EOL> self . context , fake_spec ) <EOL> @ mock . patch . object ( scheduler_rpcapi . SchedulerAPI , '<STR_LIT>' ) <EOL> def test_update_aggregates ( self , mock_update_aggs ) : <EOL> aggregates = [ objects . Aggregate ( id = <NUM_LIT:1> ) ] <EOL> self . client . update_aggregates ( <EOL> context = self . context , <EOL> aggregates = aggregates ) <EOL> mock_update_aggs . assert_called_once_with ( <EOL> self . context , aggregates ) <EOL> @ mock . patch . object ( scheduler_rpcapi . SchedulerAPI , '<STR_LIT>' ) <EOL> def test_delete_aggregate ( self , mock_delete_agg ) : <EOL> aggregate = objects . Aggregate ( id = <NUM_LIT:1> ) <EOL> self . client . delete_aggregate ( <EOL> context = self . context , <EOL> aggregate = aggregate ) <EOL> mock_delete_agg . assert_called_once_with ( <EOL> self . context , aggregate ) <EOL> class SchedulerClientTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SchedulerClientTestCase , self ) . setUp ( ) <EOL> self . client = scheduler_client . SchedulerClient ( ) <EOL> def test_constructor ( self ) : <EOL> self . assertIsNotNone ( self . client . queryclient ) <EOL> self . assertIsNotNone ( self . client . reportclient ) <EOL> @ mock . patch . object ( scheduler_query_client . SchedulerQueryClient , <EOL> '<STR_LIT>' ) <EOL> def test_select_destinations ( self , mock_select_destinations ) : <EOL> fake_spec = objects . RequestSpec ( ) <EOL> self . assertIsNone ( self . client . queryclient . instance ) <EOL> self . client . select_destinations ( '<STR_LIT>' , fake_spec ) <EOL> self . assertIsNotNone ( self . client . queryclient . instance ) <EOL> mock_select_destinations . assert_called_once_with ( '<STR_LIT>' , fake_spec ) <EOL> @ mock . patch . object ( scheduler_query_client . SchedulerQueryClient , <EOL> '<STR_LIT>' , <EOL> side_effect = messaging . MessagingTimeout ( ) ) <EOL> def test_select_destinations_timeout ( self , mock_select_destinations ) : <EOL> fake_spec = objects . RequestSpec ( ) <EOL> fake_args = [ '<STR_LIT>' , fake_spec ] <EOL> self . assertRaises ( messaging . MessagingTimeout , <EOL> self . client . select_destinations , * fake_args ) <EOL> mock_select_destinations . assert_has_calls ( [ mock . call ( * fake_args ) ] * <NUM_LIT:2> ) <EOL> @ mock . patch . object ( scheduler_query_client . SchedulerQueryClient , <EOL> '<STR_LIT>' , side_effect = [ <EOL> messaging . MessagingTimeout ( ) , mock . DEFAULT ] ) <EOL> def test_select_destinations_timeout_once ( self , mock_select_destinations ) : <EOL> fake_spec = objects . RequestSpec ( ) <EOL> fake_args = [ '<STR_LIT>' , fake_spec ] <EOL> self . client . select_destinations ( * fake_args ) <EOL> mock_select_destinations . assert_has_calls ( [ mock . call ( * fake_args ) ] * <NUM_LIT:2> ) <EOL> @ mock . patch . object ( scheduler_query_client . SchedulerQueryClient , <EOL> '<STR_LIT>' ) <EOL> def test_update_aggregates ( self , mock_update_aggs ) : <EOL> aggregates = [ objects . Aggregate ( id = <NUM_LIT:1> ) ] <EOL> self . client . update_aggregates ( <EOL> context = '<STR_LIT>' , <EOL> aggregates = aggregates ) <EOL> mock_update_aggs . assert_called_once_with ( <EOL> '<STR_LIT>' , aggregates ) <EOL> @ mock . patch . object ( scheduler_query_client . SchedulerQueryClient , <EOL> '<STR_LIT>' ) <EOL> def test_delete_aggregate ( self , mock_delete_agg ) : <EOL> aggregate = objects . Aggregate ( id = <NUM_LIT:1> ) <EOL> self . client . delete_aggregate ( <EOL> context = '<STR_LIT>' , <EOL> aggregate = aggregate ) <EOL> mock_delete_agg . assert_called_once_with ( <EOL> '<STR_LIT>' , aggregate ) <EOL> @ mock . patch . object ( scheduler_report_client . SchedulerReportClient , <EOL> '<STR_LIT>' ) <EOL> def test_update_resource_stats ( self , mock_update_resource_stats ) : <EOL> self . assertIsNone ( self . client . reportclient . instance ) <EOL> self . client . update_resource_stats ( mock . sentinel . cn ) <EOL> self . assertIsNotNone ( self . client . reportclient . instance ) <EOL> mock_update_resource_stats . assert_called_once_with ( mock . sentinel . cn ) </s>
