#NEWLINE# @ lockutils . synchronized ( 'need-external-net' ) #NEWLINE# def test_associate_floatingip( self ) : #NEWLINE# #INDENT# with self . _prepare_ext_net ( ) as external_network_id : #NEWLINE# #INDENT# router = self . store ( objects . RouterTestObj ( self . neutron , self . nb_api ) ) #NEWLINE# fip = self . store ( objects . FloatingipTestObj ( self . neutron , self . nb_api ) ) #NEWLINE# router_para = { #NEWLINE# #INDENT# 'name' : 'myrouter1' , #NEWLINE# 'admin_state_up' : True , #NEWLINE# 'external_gateway_info' : { #NEWLINE# #INDENT# 'network_id' : external_network_id , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# router . create ( router = router_para ) #NEWLINE# self . assertTrue ( router . exists ( ) ) #NEWLINE# private_network = self . store ( objects . NetworkTestObj ( self . neutron , self . nb_api ) ) #NEWLINE# private_network_id = private_network . create ( network = { #NEWLINE# #INDENT# 'name' : 'private' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertTrue ( private_network . exists ( ) ) #NEWLINE# priv_subnet = self . store ( objects . SubnetTestObj ( self . neutron , self . nb_api , private_network_id ) ) #NEWLINE# private_subnet_para = { #NEWLINE# #INDENT# 'cidr' : '10.0.0.0/24' , #NEWLINE# 'ip_version' : 4 , #NEWLINE# 'network_id' : private_network_id , #NEWLINE# #UNINDENT# } #NEWLINE# priv_subnet_id = priv_subnet . create ( private_subnet_para ) #NEWLINE# self . assertTrue ( priv_subnet . exists ( ) ) #NEWLINE# router_interface = router . add_interface ( subnet_id = priv_subnet_id ) #NEWLINE# router_lport = self . nb_api . get_logical_port ( router_interface [ 'port_id' ] ) #NEWLINE# self . assertIsNotNone ( router_lport ) #NEWLINE# port = self . store ( objects . PortTestObj ( self . neutron , self . nb_api , private_network_id ) ) #NEWLINE# port_id = port . create ( ) #NEWLINE# self . assertIsNotNone ( port . get_logical_port ( ) ) #NEWLINE# fip_para = { #NEWLINE# #INDENT# 'floating_network_id' : external_network_id , #NEWLINE# #UNINDENT# } #NEWLINE# fip . create ( fip_para ) #NEWLINE# self . assertTrue ( fip . exists ( ) ) #NEWLINE# fip . update ( { #NEWLINE# #INDENT# 'port_id' : router_lport , #NEWLINE# #UNINDENT# } ) #NEWLINE# fip_obj = fip . get_floatingip ( ) #NEWLINE# self . assertEqual ( fip_obj . lport_id , port_id ) #NEWLINE# fip . close ( ) #NEWLINE# self . assertFalse ( fip . exists ( ) ) #NEWLINE# port . close ( ) #NEWLINE# self . assertFalse ( port . exists ( ) ) #NEWLINE# router . close ( ) #NEWLINE# self . assertFalse ( router . exists ( ) ) #NEWLINE# priv_subnet . close ( ) #NEWLINE# self . assertFalse ( priv_subnet . exists ( ) )