<s> import mock <EOL> from oslo_config import cfg <EOL> from nova . cells import utils as cells_utils <EOL> from nova import objects <EOL> from nova . tests . functional . api_sample_tests import api_sample_base <EOL> CONF = cfg . CONF <EOL> CONF . import_opt ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class HypervisorsSampleJsonTests ( api_sample_base . ApiSampleTestBaseV21 ) : <EOL> ADMIN_API = True <EOL> extension_name = "<STR_LIT>" <EOL> def _get_flags ( self ) : <EOL> f = super ( HypervisorsSampleJsonTests , self ) . _get_flags ( ) <EOL> f [ '<STR_LIT>' ] = CONF . osapi_compute_extension [ : ] <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' ) <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f <EOL> def test_hypervisors_list ( self ) : <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <NUM_LIT:200> ) <EOL> def test_hypervisors_search ( self ) : <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <NUM_LIT:200> ) <EOL> def test_hypervisors_without_servers ( self ) : <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , <EOL> { } , response , <NUM_LIT:200> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_hypervisors_with_servers ( self , mock_instance_get ) : <EOL> instance = [ <EOL> { <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ] <EOL> mock_instance_get . return_value = instance <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , <EOL> response , <NUM_LIT:200> ) <EOL> def test_hypervisors_detail ( self ) : <EOL> hypervisor_id = '<STR_LIT:1>' <EOL> subs = { <EOL> '<STR_LIT>' : hypervisor_id <EOL> } <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> def test_hypervisors_show ( self ) : <EOL> hypervisor_id = '<STR_LIT:1>' <EOL> subs = { <EOL> '<STR_LIT>' : hypervisor_id <EOL> } <EOL> response = self . _do_get ( '<STR_LIT>' % hypervisor_id ) <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> def test_hypervisors_statistics ( self ) : <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <NUM_LIT:200> ) <EOL> def test_hypervisors_uptime ( self ) : <EOL> def fake_get_host_uptime ( self , context , hyp ) : <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . stub_out ( '<STR_LIT>' , <EOL> fake_get_host_uptime ) <EOL> hypervisor_id = '<STR_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>' , subs , response , <NUM_LIT:200> ) <EOL> @ mock . patch ( "<STR_LIT>" , return_value = True ) <EOL> class HypervisorsCellsSampleJsonTests ( api_sample_base . ApiSampleTestBaseV21 ) : <EOL> ADMIN_API = True <EOL> extension_name = "<STR_LIT>" <EOL> def _get_flags ( self ) : <EOL> f = super ( HypervisorsCellsSampleJsonTests , self ) . _get_flags ( ) <EOL> f [ '<STR_LIT>' ] = CONF . osapi_compute_extension [ : ] <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' ) <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f <EOL> def setUp ( self ) : <EOL> self . flags ( enable = True , cell_type = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> super ( HypervisorsCellsSampleJsonTests , self ) . setUp ( ) <EOL> def test_hypervisor_uptime ( self , mocks ) : <EOL> fake_hypervisor = objects . ComputeNode ( id = <NUM_LIT:1> , host = '<STR_LIT>' , <EOL> hypervisor_hostname = '<STR_LIT>' ) <EOL> def fake_get_host_uptime ( self , context , hyp ) : <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def fake_compute_node_get ( self , context , hyp ) : <EOL> return fake_hypervisor <EOL> def fake_service_get_by_compute_host ( self , context , host ) : <EOL> return cells_utils . ServiceProxy ( <EOL> objects . Service ( id = <NUM_LIT:1> , host = '<STR_LIT>' , disabled = False , <EOL> disabled_reason = None ) , <EOL> '<STR_LIT>' ) <EOL> self . stub_out ( <EOL> '<STR_LIT>' , <EOL> fake_compute_node_get ) <EOL> self . stub_out ( <EOL> '<STR_LIT>' , <EOL> fake_service_get_by_compute_host ) <EOL> self . stub_out ( <EOL> '<STR_LIT>' , <EOL> fake_get_host_uptime ) <EOL> hypervisor_id = fake_hypervisor . id <EOL> response = self . _do_get ( '<STR_LIT>' % hypervisor_id ) <EOL> subs = { '<STR_LIT>' : str ( hypervisor_id ) } <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) </s>
