<s> """<STR_LIT>""" <EOL> import mock <EOL> from mock import patch <EOL> import os_client_config <EOL> from neutronclient . common import exceptions as n_exc <EOL> from shade import _utils <EOL> from shade import exc <EOL> from shade import meta <EOL> from shade import OpenStackCloud <EOL> from shade . tests import fakes <EOL> from shade . tests . unit import base <EOL> class TestFloatingIP ( base . TestCase ) : <EOL> mock_floating_ip_list_rep = { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } , <EOL> { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> } <EOL> mock_floating_ip_new_rep = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> mock_get_network_rep = { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' <EOL> ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None <EOL> } <EOL> mock_search_ports_rep = [ <EOL> { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> ] , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> def assertAreInstances ( self , elements , elem_type ) : <EOL> for e in elements : <EOL> self . assertIsInstance ( e , elem_type ) <EOL> def setUp ( self ) : <EOL> super ( TestFloatingIP , self ) . setUp ( ) <EOL> config = os_client_config . OpenStackConfig ( ) <EOL> self . client = OpenStackCloud ( <EOL> cloud_config = config . get_one_cloud ( validate = False ) ) <EOL> self . fake_server = meta . obj_to_dict ( <EOL> fakes . FakeServer ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> addresses = { u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : '<STR_LIT>' , <EOL> u'<STR_LIT:version>' : <NUM_LIT:4> , <EOL> u'<STR_LIT>' : <EOL> u'<STR_LIT>' } ] } ) ) <EOL> self . floating_ip = _utils . normalize_neutron_floating_ips ( <EOL> self . mock_floating_ip_list_rep [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_list_floating_ips ( self , mock_has_service , mock_neutron_client ) : <EOL> mock_has_service . return_value = True <EOL> mock_neutron_client . list_floatingips . return_value = self . mock_floating_ip_list_rep <EOL> floating_ips = self . client . list_floating_ips ( ) <EOL> mock_neutron_client . list_floatingips . assert_called_with ( ) <EOL> self . assertIsInstance ( floating_ips , list ) <EOL> self . assertAreInstances ( floating_ips , dict ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( floating_ips ) ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_search_floating_ips ( self , mock_has_service , mock_neutron_client ) : <EOL> mock_has_service . return_value = True <EOL> mock_neutron_client . list_floatingips . return_value = self . mock_floating_ip_list_rep <EOL> floating_ips = self . client . search_floating_ips ( <EOL> filters = { '<STR_LIT>' : False } ) <EOL> mock_neutron_client . list_floatingips . assert_called_with ( ) <EOL> self . assertIsInstance ( floating_ips , list ) <EOL> self . assertAreInstances ( floating_ips , dict ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( floating_ips ) ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_get_floating_ip ( self , mock_has_service , mock_neutron_client ) : <EOL> mock_has_service . return_value = True <EOL> mock_neutron_client . list_floatingips . return_value = self . mock_floating_ip_list_rep <EOL> floating_ip = self . client . get_floating_ip ( <EOL> id = '<STR_LIT>' ) <EOL> mock_neutron_client . list_floatingips . assert_called_with ( ) <EOL> self . assertIsInstance ( floating_ip , dict ) <EOL> self . assertEqual ( '<STR_LIT>' , floating_ip [ '<STR_LIT>' ] ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_get_floating_ip_not_found ( <EOL> self , mock_has_service , mock_neutron_client ) : <EOL> mock_has_service . return_value = True <EOL> mock_neutron_client . list_floatingips . return_value = self . mock_floating_ip_list_rep <EOL> floating_ip = self . client . get_floating_ip ( id = '<STR_LIT>' ) <EOL> self . assertIsNone ( floating_ip ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_create_floating_ip ( <EOL> self , mock_has_service , mock_search_networks , mock_neutron_client ) : <EOL> mock_has_service . return_value = True <EOL> mock_search_networks . return_value = [ self . mock_get_network_rep ] <EOL> mock_neutron_client . create_floatingip . return_value = self . mock_floating_ip_new_rep <EOL> ip = self . client . create_floating_ip ( network = '<STR_LIT>' ) <EOL> mock_neutron_client . create_floatingip . assert_called_with ( <EOL> body = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> ) <EOL> self . assertEqual ( <EOL> self . mock_floating_ip_new_rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> ip [ '<STR_LIT>' ] ) <EOL> @ patch . object ( _utils , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_available_floating_ip_neutron ( self , <EOL> mock_keystone , <EOL> mock_has_service , <EOL> mock__neutron_call , <EOL> mock_normalize ) : <EOL> """<STR_LIT>""" <EOL> mock_has_service . return_value = True <EOL> mock__neutron_call . return_value = [ ] <EOL> self . client . available_floating_ip ( network = '<STR_LIT>' ) <EOL> mock_has_service . assert_called_once_with ( '<STR_LIT>' ) <EOL> mock__neutron_call . assert_called_once_with ( network = '<STR_LIT>' , <EOL> server = None ) <EOL> mock_normalize . assert_called_once_with ( [ ] ) <EOL> @ patch . object ( _utils , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test__neutron_available_floating_ips ( <EOL> self , <EOL> mock_keystone_session , <EOL> mock_get_ext_nets , <EOL> mock__neutron_list_fips , <EOL> mock__neutron_create_fip , <EOL> mock__filter_list ) : <EOL> """<STR_LIT>""" <EOL> mock_keystone_session . get_project_id . return_value = '<STR_LIT>' <EOL> mock_get_ext_nets . return_value = [ self . mock_get_network_rep ] <EOL> mock__neutron_list_fips . return_value = [ ] <EOL> mock__filter_list . return_value = [ ] <EOL> self . client . _neutron_available_floating_ips ( ) <EOL> mock_keystone_session . get_project_id . assert_called_once_with ( ) <EOL> mock_get_ext_nets . assert_called_once_with ( ) <EOL> mock__neutron_list_fips . assert_called_once_with ( ) <EOL> mock__filter_list . assert_called_once_with ( <EOL> [ ] , name_or_id = None , <EOL> filters = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : self . mock_get_network_rep [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> mock__neutron_create_fip . assert_called_once_with ( <EOL> network_name_or_id = self . mock_get_network_rep [ '<STR_LIT:id>' ] , <EOL> server = None <EOL> ) <EOL> @ patch . object ( _utils , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test__neutron_available_floating_ips_network ( <EOL> self , <EOL> mock_keystone_session , <EOL> mock_get_ext_nets , <EOL> mock__neutron_list_fips , <EOL> mock__neutron_create_fip , <EOL> mock__filter_list ) : <EOL> """<STR_LIT>""" <EOL> mock_keystone_session . get_project_id . return_value = '<STR_LIT>' <EOL> mock_get_ext_nets . return_value = [ self . mock_get_network_rep ] <EOL> mock__neutron_list_fips . return_value = [ ] <EOL> mock__filter_list . return_value = [ ] <EOL> self . client . _neutron_available_floating_ips ( <EOL> network = self . mock_get_network_rep [ '<STR_LIT:name>' ] <EOL> ) <EOL> mock_keystone_session . get_project_id . assert_called_once_with ( ) <EOL> mock_get_ext_nets . assert_called_once_with ( ) <EOL> mock__neutron_list_fips . assert_called_once_with ( ) <EOL> mock__filter_list . assert_called_once_with ( <EOL> [ ] , name_or_id = None , <EOL> filters = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : self . mock_get_network_rep [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> mock__neutron_create_fip . assert_called_once_with ( <EOL> network_name_or_id = self . mock_get_network_rep [ '<STR_LIT:id>' ] , <EOL> server = None <EOL> ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test__neutron_available_floating_ips_invalid_network ( <EOL> self , <EOL> mock_keystone_session , <EOL> mock_get_ext_nets ) : <EOL> """<STR_LIT>""" <EOL> mock_keystone_session . get_project_id . return_value = '<STR_LIT>' <EOL> mock_get_ext_nets . return_value = [ ] <EOL> self . assertRaises ( exc . OpenStackCloudException , <EOL> self . client . _neutron_available_floating_ips , <EOL> network = '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_auto_ip_pool_no_reuse ( <EOL> self , mock_has_service , <EOL> mock_attach_ip_to_server , <EOL> mock__neutron_create_floating_ip , <EOL> mock_keystone_session , <EOL> mock_nova_client ) : <EOL> mock_has_service . return_value = True <EOL> fip = _utils . normalize_neutron_floating_ips ( <EOL> self . mock_floating_ip_list_rep [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> mock__neutron_create_floating_ip . return_value = fip <EOL> mock_keystone_session . get_project_id . return_value = '<STR_LIT>' <EOL> fake_server = meta . obj_to_dict ( fakes . FakeServer ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . client . add_ips_to_server ( <EOL> fake_server , ip_pool = '<STR_LIT>' , reuse = False ) <EOL> mock__neutron_create_floating_ip . assert_called_once_with ( <EOL> network_name_or_id = '<STR_LIT>' , server = None , <EOL> fixed_address = None , nat_destination = None , wait = False , timeout = <NUM_LIT> ) <EOL> mock_attach_ip_to_server . assert_called_once_with ( <EOL> server = fake_server , fixed_address = None , <EOL> floating_ip = fip , wait = False , timeout = mock . ANY ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_available_floating_ip_new ( <EOL> self , mock_has_service , mock_list_networks , <EOL> mock__neutron_list_floating_ips , <EOL> mock__neutron_create_floating_ip , mock_keystone_session ) : <EOL> mock_has_service . return_value = True <EOL> mock_list_networks . return_value = [ self . mock_get_network_rep ] <EOL> mock__neutron_list_floating_ips . return_value = [ ] <EOL> mock__neutron_create_floating_ip . return_value = self . mock_floating_ip_new_rep [ '<STR_LIT>' ] <EOL> mock_keystone_session . get_project_id . return_value = '<STR_LIT>' <EOL> ip = self . client . available_floating_ip ( network = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . mock_floating_ip_new_rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> ip [ '<STR_LIT>' ] ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_delete_floating_ip_existing ( <EOL> self , mock_has_service , mock_neutron_client , mock_get_floating_ip ) : <EOL> mock_has_service . return_value = True <EOL> fake_fip = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> mock_get_floating_ip . side_effect = [ fake_fip , fake_fip , None ] <EOL> mock_neutron_client . delete_floatingip . return_value = None <EOL> ret = self . client . delete_floating_ip ( <EOL> floating_ip_id = '<STR_LIT>' , <EOL> retry = <NUM_LIT:2> ) <EOL> mock_neutron_client . delete_floatingip . assert_called_with ( <EOL> floatingip = '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( mock_get_floating_ip . call_count , <NUM_LIT:3> ) <EOL> self . assertTrue ( ret ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_delete_floating_ip_existing_no_delete ( <EOL> self , mock_has_service , mock_neutron_client , mock_get_floating_ip ) : <EOL> mock_has_service . return_value = True <EOL> fake_fip = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> mock_get_floating_ip . side_effect = [ fake_fip , fake_fip , fake_fip ] <EOL> mock_neutron_client . delete_floatingip . return_value = None <EOL> self . assertRaises ( <EOL> exc . OpenStackCloudException , <EOL> self . client . delete_floating_ip , <EOL> floating_ip_id = '<STR_LIT>' , <EOL> retry = <NUM_LIT:2> ) <EOL> mock_neutron_client . delete_floatingip . assert_called_with ( <EOL> floatingip = '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( mock_get_floating_ip . call_count , <NUM_LIT:3> ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_delete_floating_ip_not_found ( <EOL> self , mock_has_service , mock_neutron_client ) : <EOL> mock_has_service . return_value = True <EOL> mock_neutron_client . delete_floatingip . side_effect = n_exc . NotFound ( ) <EOL> ret = self . client . delete_floating_ip ( <EOL> floating_ip_id = '<STR_LIT>' ) <EOL> self . assertFalse ( ret ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_attach_ip_to_server ( <EOL> self , mock_has_service , mock_neutron_client , mock_search_ports ) : <EOL> mock_has_service . return_value = True <EOL> mock_search_ports . return_value = self . mock_search_ports_rep <EOL> mock_neutron_client . list_floatingips . return_value = self . mock_floating_ip_list_rep <EOL> self . client . _attach_ip_to_server ( <EOL> server = self . fake_server , <EOL> floating_ip = self . floating_ip ) <EOL> mock_neutron_client . update_floatingip . assert_called_with ( <EOL> floatingip = self . mock_floating_ip_list_rep [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> body = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . mock_search_ports_rep [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : self . mock_search_ports_rep [ <NUM_LIT:0> ] [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> } <EOL> } <EOL> ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_add_ip_refresh_timeout ( <EOL> self , mock_has_service , mock_create_floating_ip , <EOL> mock_get_server_by_id , mock_delete_floating_ip ) : <EOL> mock_has_service . return_value = True <EOL> mock_create_floating_ip . return_value = self . floating_ip <EOL> mock_get_server_by_id . return_value = self . fake_server <EOL> self . assertRaises ( <EOL> exc . OpenStackCloudTimeout , <EOL> self . client . _add_auto_ip , <EOL> server = self . fake_server , <EOL> wait = True , timeout = <NUM_LIT:2> , <EOL> reuse = False ) <EOL> mock_delete_floating_ip . assert_called_once_with ( <EOL> self . floating_ip [ '<STR_LIT:id>' ] ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_detach_ip_from_server ( <EOL> self , mock_has_service , mock_neutron_client , <EOL> mock_get_floating_ip ) : <EOL> mock_has_service . return_value = True <EOL> mock_get_floating_ip . return_value = _utils . normalize_neutron_floating_ips ( <EOL> self . mock_floating_ip_list_rep [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> self . client . detach_ip_from_server ( <EOL> server_id = '<STR_LIT>' , <EOL> floating_ip_id = '<STR_LIT>' ) <EOL> mock_neutron_client . update_floatingip . assert_called_with ( <EOL> floatingip = '<STR_LIT>' , <EOL> body = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : None <EOL> } <EOL> } <EOL> ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_add_ip_from_pool ( <EOL> self , mock_has_service , mock_available_floating_ip , <EOL> mock_attach_ip_to_server ) : <EOL> mock_has_service . return_value = True <EOL> mock_available_floating_ip . return_value = _utils . normalize_neutron_floating_ips ( [ <EOL> self . mock_floating_ip_new_rep [ '<STR_LIT>' ] ] ) [ <NUM_LIT:0> ] <EOL> mock_attach_ip_to_server . return_value = self . fake_server <EOL> server = self . client . _add_ip_from_pool ( <EOL> server = self . fake_server , <EOL> network = '<STR_LIT>' , <EOL> fixed_address = '<STR_LIT>' ) <EOL> self . assertEqual ( server , self . fake_server ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_cleanup_floating_ips ( <EOL> self , mock_use_neutron_floating , mock_list_floating_ips , <EOL> mock_delete_floating_ip ) : <EOL> mock_use_neutron_floating . return_value = True <EOL> floating_ips = [ { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:status>" : "<STR_LIT>" <EOL> } , { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT:status>" : "<STR_LIT>" <EOL> } ] <EOL> mock_list_floating_ips . return_value = floating_ips <EOL> self . client . delete_unattached_floating_ips ( ) <EOL> mock_delete_floating_ip . assert_called_once_with ( <EOL> id = "<STR_LIT>" , <EOL> timeout = <NUM_LIT> , wait = False ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_create_floating_ip_no_port ( <EOL> self , mock_get_ext_nets , mock_get_free_fixed_port , <EOL> mock_submit_create_fip ) : <EOL> fake_port = dict ( id = '<STR_LIT>' ) <EOL> mock_get_ext_nets . return_value = [ self . mock_get_network_rep ] <EOL> mock_get_free_fixed_port . return_value = ( fake_port , '<STR_LIT>' ) <EOL> mock_submit_create_fip . return_value = dict ( port_id = None ) <EOL> self . assertRaises ( <EOL> exc . OpenStackCloudException , <EOL> self . client . _neutron_create_floating_ip , <EOL> server = dict ( id = '<STR_LIT>' ) ) </s>
