@@ -843,8 +843,11 @@ def _validate_one_router_ipv6_port_per_network(self, router, port):
843843 if self ._port_has_ipv6_address (port ):
844844 for existing_port in (rp .port for rp in router .attached_ports ):
845845 if (existing_port ["id" ] != port ["id" ] and
846- existing_port ["network_id" ] == port ["network_id" ] and
847- self ._port_has_ipv6_address (existing_port )):
846+ existing_port ["network_id" ] == port ["network_id" ] and
847+ self ._port_has_ipv6_address (existing_port ) and
848+ port ["device_owner" ] not in [
849+ constants .DEVICE_OWNER_ROUTER_SNAT ,
850+ constants .DEVICE_OWNER_DVR_INTERFACE ]):
848851 msg = _ ("Router already contains IPv6 port %(p)s "
849852 "belonging to network id %(nid)s. Only one IPv6 port "
850853 "from the same network subnet can be connected to a "
@@ -971,7 +974,7 @@ def add_router_interface(self, context, router_id, interface_info=None):
971974 port = port ,
972975 interface_info = interface_info )
973976 self ._add_router_port (
974- context , port [ 'id' ] , router , device_owner )
977+ context , port , router , device_owner )
975978
976979 gw_ips = []
977980 gw_network_id = None
@@ -999,10 +1002,10 @@ def add_router_interface(self, context, router_id, interface_info=None):
9991002 subnets [- 1 ]['id' ], [subnet ['id' ] for subnet in subnets ])
10001003
10011004 @db_api .retry_if_session_inactive ()
1002- def _add_router_port (self , context , port_id , router , device_owner ):
1005+ def _add_router_port (self , context , port , router , device_owner ):
10031006 l3_obj .RouterPort (
10041007 context ,
1005- port_id = port_id ,
1008+ port_id = port [ 'id' ] ,
10061009 router_id = router .id ,
10071010 port_type = device_owner
10081011 ).create ()
@@ -1019,15 +1022,19 @@ def _add_router_port(self, context, port_id, router, device_owner):
10191022 if len (router_ports ) > 1 :
10201023 subnets_id = []
10211024 for rp in router_ports :
1022- port = port_obj .Port .get_object (context .elevated (),
1023- id = rp .port_id )
1024- if port :
1025+ router_port = port_obj .Port .get_object (context .elevated (),
1026+ id = rp .port_id )
1027+ if router_port :
1028+ # NOTE(froyo): Just run the validation in case the new port
1029+ # added is on the same network than an existing one.
10251030 # Only allow one router port with IPv6 subnets per network
1026- # id
1027- self ._validate_one_router_ipv6_port_per_network (
1028- router , port )
1029- subnets_id .extend ([fixed_ip ['subnet_id' ]
1030- for fixed_ip in port ['fixed_ips' ]])
1031+ # id.
1032+ if router_port ['network_id' ] == port ['network_id' ]:
1033+ self ._validate_one_router_ipv6_port_per_network (
1034+ router , router_port )
1035+ subnets_id .extend (
1036+ [fixed_ip ["subnet_id" ]
1037+ for fixed_ip in router_port ["fixed_ips" ]])
10311038 else :
10321039 # due to race conditions maybe the port under analysis is
10331040 # deleted, so instead returning a RouterInterfaceNotFound
@@ -1055,8 +1062,8 @@ def _add_router_port(self, context, port_id, router, device_owner):
10551062 # make sure the records in routerports table and ports
10561063 # table are consistent.
10571064 self ._core_plugin .update_port (
1058- context , port_id , {'port' : {'device_id' : router .id ,
1059- 'device_owner' : device_owner }})
1065+ context , port [ 'id' ] , {'port' : {'device_id' : router .id ,
1066+ 'device_owner' : device_owner }})
10601067
10611068 def _check_router_interface_not_in_use (self , router_id , subnet ):
10621069 context = n_ctx .get_admin_context ()
0 commit comments