<s> import collections <EOL> import mock <EOL> from oslo_serialization import jsonutils <EOL> import testtools <EOL> from nova import objects <EOL> from nova . objects import fields <EOL> from nova . objects import pci_device_pool <EOL> from nova . tests . functional . api_sample_tests import api_sample_base <EOL> from nova . tests . functional . api_sample_tests import test_servers <EOL> skip_msg = "<STR_LIT>" <EOL> fake_db_dev_1 = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : fields . PciDeviceType . SRIOV_VF , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> fake_db_dev_2 = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:id>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : fields . PciDeviceType . SRIOV_VF , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> class ExtendedServerPciSampleJsonTest ( test_servers . ServersSampleBase ) : <EOL> extension_name = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> raise testtools . TestCase . skipException ( skip_msg ) <EOL> def test_show ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> response = self . _do_get ( '<STR_LIT>' % uuid ) <EOL> subs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> def test_detail ( self ) : <EOL> self . _post_server ( ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> subs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> class ExtendedHyervisorPciSampleJsonTest ( api_sample_base . ApiSampleTestBaseV21 ) : <EOL> ADMIN_API = True <EOL> extra_extensions_to_load = [ '<STR_LIT>' ] <EOL> extension_name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> raise testtools . TestCase . skipException ( skip_msg ) <EOL> super ( ExtendedHyervisorPciSampleJsonTest , self ) . setUp ( ) <EOL> cpu_info = collections . OrderedDict ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } ) , <EOL> ] ) <EOL> self . fake_compute_node = objects . ComputeNode ( <EOL> cpu_info = jsonutils . dumps ( cpu_info ) , <EOL> current_workload = <NUM_LIT:0> , <EOL> disk_available_least = <NUM_LIT:0> , <EOL> host_ip = "<STR_LIT>" , <EOL> state = "<STR_LIT>" , <EOL> status = "<STR_LIT>" , <EOL> free_disk_gb = <NUM_LIT> , <EOL> free_ram_mb = <NUM_LIT> , <EOL> hypervisor_hostname = "<STR_LIT>" , <EOL> hypervisor_type = "<STR_LIT>" , <EOL> hypervisor_version = <NUM_LIT:1000> , <EOL> id = <NUM_LIT:1> , <EOL> local_gb = <NUM_LIT> , <EOL> local_gb_used = <NUM_LIT:0> , <EOL> memory_mb = <NUM_LIT> , <EOL> memory_mb_used = <NUM_LIT> , <EOL> running_vms = <NUM_LIT:0> , <EOL> vcpus = <NUM_LIT:1> , <EOL> vcpus_used = <NUM_LIT:0> , <EOL> service_id = <NUM_LIT:2> , <EOL> host = '<STR_LIT>' , <EOL> pci_device_pools = pci_device_pool . from_pci_stats ( <EOL> { "<STR_LIT:count>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> } ) , ) <EOL> self . fake_service = objects . Service ( <EOL> id = <NUM_LIT:2> , <EOL> host = '<STR_LIT>' , <EOL> disabled = False , <EOL> disabled_reason = None ) <EOL> @ mock . patch ( "<STR_LIT>" , return_value = True ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_pci_show ( self , mock_obj , mock_svc_get , mock_service ) : <EOL> mock_obj . return_value = self . fake_compute_node <EOL> mock_svc_get . return_value = self . fake_service <EOL> hypervisor_id = <NUM_LIT:1> <EOL> response = self . _do_get ( '<STR_LIT>' % hypervisor_id ) <EOL> subs = { <EOL> '<STR_LIT>' : hypervisor_id , <EOL> } <EOL> self . _verify_response ( '<STR_LIT>' , <EOL> subs , response , <NUM_LIT:200> ) <EOL> @ mock . patch ( "<STR_LIT>" , return_value = True ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_pci_detail ( self , mock_obj , mock_svc_get , mock_service ) : <EOL> mock_obj . return_value = [ self . fake_compute_node ] <EOL> mock_svc_get . return_value = self . fake_service <EOL> hypervisor_id = <NUM_LIT:1> <EOL> subs = { <EOL> '<STR_LIT>' : hypervisor_id <EOL> } <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , <EOL> subs , response , <NUM_LIT:200> ) <EOL> class PciSampleJsonTest ( api_sample_base . ApiSampleTestBaseV21 ) : <EOL> ADMIN_API = True <EOL> extension_name = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> raise testtools . TestCase . skipException ( skip_msg ) <EOL> def _fake_pci_device_get_by_id ( self , context , id ) : <EOL> return fake_db_dev_1 <EOL> def _fake_pci_device_get_all_by_node ( self , context , id ) : <EOL> return [ fake_db_dev_1 , fake_db_dev_2 ] <EOL> def test_pci_show ( self ) : <EOL> self . stub_out ( '<STR_LIT>' , <EOL> self . _fake_pci_device_get_by_id ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <NUM_LIT:200> ) <EOL> def test_pci_index ( self ) : <EOL> self . stub_out ( '<STR_LIT>' , <EOL> self . _fake_pci_device_get_all_by_node ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <NUM_LIT:200> ) <EOL> def test_pci_detail ( self ) : <EOL> self . stub_out ( '<STR_LIT>' , <EOL> self . _fake_pci_device_get_all_by_node ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <NUM_LIT:200> ) </s>
