<s> import math <EOL> import mock <EOL> from oslo_utils import units <EOL> from nova . compute import arch <EOL> from nova . tests . unit . virt . xenapi import stubs <EOL> from nova . virt import driver <EOL> from nova . virt import fake <EOL> from nova . virt import xenapi <EOL> from nova . virt . xenapi import driver as xenapi_driver <EOL> class XenAPIDriverTestCase ( stubs . XenAPITestBaseNoDB ) : <EOL> """<STR_LIT>""" <EOL> def _get_driver ( self ) : <EOL> stubs . stubout_session ( self . stubs , stubs . FakeSessionForVMTests ) <EOL> self . flags ( connection_url = '<STR_LIT>' , <EOL> connection_password = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> return xenapi . XenAPIDriver ( fake . FakeVirtAPI ( ) , False ) <EOL> def host_stats ( self , refresh = True ) : <EOL> return { '<STR_LIT>' : <NUM_LIT:3> * units . Mi , <EOL> '<STR_LIT>' : <NUM_LIT:2> * units . Mi , <EOL> '<STR_LIT>' : <NUM_LIT:5> * units . Gi , <EOL> '<STR_LIT>' : <NUM_LIT:2> * units . Gi , <EOL> '<STR_LIT>' : <NUM_LIT:4> * units . Gi , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : arch . X86_64 , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:50> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] , <EOL> } , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> def test_available_resource ( self ) : <EOL> driver = self . _get_driver ( ) <EOL> driver . _session . product_version = ( <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:2> ) <EOL> self . stubs . Set ( driver . host_state , '<STR_LIT>' , self . host_stats ) <EOL> resources = driver . get_available_resource ( None ) <EOL> self . assertEqual ( <NUM_LIT> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:50> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:3> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:5> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:10> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:3> - <NUM_LIT:2> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , resources [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , resources [ '<STR_LIT>' ] ) <EOL> def test_overhead ( self ) : <EOL> driver = self . _get_driver ( ) <EOL> instance = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:4> } <EOL> expected = ( ( instance [ '<STR_LIT>' ] * xenapi_driver . OVERHEAD_PER_MB ) + <EOL> ( instance [ '<STR_LIT>' ] * xenapi_driver . OVERHEAD_PER_VCPU ) + <EOL> xenapi_driver . OVERHEAD_BASE ) <EOL> expected = math . ceil ( expected ) <EOL> overhead = driver . estimate_instance_overhead ( instance ) <EOL> self . assertEqual ( expected , overhead [ '<STR_LIT>' ] ) <EOL> def test_set_bootable ( self ) : <EOL> driver = self . _get_driver ( ) <EOL> self . mox . StubOutWithMock ( driver . _vmops , '<STR_LIT>' ) <EOL> driver . _vmops . set_bootable ( '<STR_LIT>' , True ) <EOL> self . mox . ReplayAll ( ) <EOL> driver . set_bootable ( '<STR_LIT>' , True ) <EOL> def test_post_interrupted_snapshot_cleanup ( self ) : <EOL> driver = self . _get_driver ( ) <EOL> fake_vmops_cleanup = mock . Mock ( ) <EOL> driver . _vmops . post_interrupted_snapshot_cleanup = fake_vmops_cleanup <EOL> driver . post_interrupted_snapshot_cleanup ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> fake_vmops_cleanup . assert_called_once_with ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_public_api_signatures ( self ) : <EOL> inst = self . _get_driver ( ) <EOL> self . assertPublicAPISignatures ( driver . ComputeDriver ( None ) , inst ) <EOL> def test_get_volume_connector ( self ) : <EOL> ip = '<STR_LIT>' <EOL> driver = self . _get_driver ( ) <EOL> self . flags ( connection_url = '<STR_LIT>' % ip , <EOL> connection_password = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> self . stubs . Set ( driver . host_state , '<STR_LIT>' , self . host_stats ) <EOL> connector = driver . get_volume_connector ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertIn ( '<STR_LIT>' , connector ) <EOL> self . assertEqual ( connector [ '<STR_LIT>' ] , ip ) <EOL> self . assertIn ( '<STR_LIT>' , connector ) <EOL> self . assertEqual ( connector [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_get_block_storage_ip ( self ) : <EOL> my_ip = '<STR_LIT>' <EOL> connection_ip = '<STR_LIT>' <EOL> driver = self . _get_driver ( ) <EOL> self . flags ( connection_url = '<STR_LIT>' % connection_ip , <EOL> group = '<STR_LIT>' ) <EOL> self . flags ( my_ip = my_ip , my_block_storage_ip = my_ip ) <EOL> ip = driver . _get_block_storage_ip ( ) <EOL> self . assertEqual ( connection_ip , ip ) <EOL> def test_get_block_storage_ip_conf ( self ) : <EOL> driver = self . _get_driver ( ) <EOL> my_ip = '<STR_LIT>' <EOL> my_block_storage_ip = '<STR_LIT>' <EOL> self . flags ( my_ip = my_ip , my_block_storage_ip = my_block_storage_ip ) <EOL> ip = driver . _get_block_storage_ip ( ) <EOL> self . assertEqual ( my_block_storage_ip , ip ) </s>
