@@ -843,8 +843,11 @@ def _validate_one_router_ipv6_port_per_network(self, router, port):
843
843
if self ._port_has_ipv6_address (port ):
844
844
for existing_port in (rp .port for rp in router .attached_ports ):
845
845
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 ]):
848
851
msg = _ ("Router already contains IPv6 port %(p)s "
849
852
"belonging to network id %(nid)s. Only one IPv6 port "
850
853
"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):
971
974
port = port ,
972
975
interface_info = interface_info )
973
976
self ._add_router_port (
974
- context , port [ 'id' ] , router , device_owner )
977
+ context , port , router , device_owner )
975
978
976
979
gw_ips = []
977
980
gw_network_id = None
@@ -999,10 +1002,10 @@ def add_router_interface(self, context, router_id, interface_info=None):
999
1002
subnets [- 1 ]['id' ], [subnet ['id' ] for subnet in subnets ])
1000
1003
1001
1004
@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 ):
1003
1006
l3_obj .RouterPort (
1004
1007
context ,
1005
- port_id = port_id ,
1008
+ port_id = port [ 'id' ] ,
1006
1009
router_id = router .id ,
1007
1010
port_type = device_owner
1008
1011
).create ()
@@ -1019,15 +1022,19 @@ def _add_router_port(self, context, port_id, router, device_owner):
1019
1022
if len (router_ports ) > 1 :
1020
1023
subnets_id = []
1021
1024
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.
1025
1030
# 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" ]])
1031
1038
else :
1032
1039
# due to race conditions maybe the port under analysis is
1033
1040
# deleted, so instead returning a RouterInterfaceNotFound
@@ -1055,8 +1062,8 @@ def _add_router_port(self, context, port_id, router, device_owner):
1055
1062
# make sure the records in routerports table and ports
1056
1063
# table are consistent.
1057
1064
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 }})
1060
1067
1061
1068
def _check_router_interface_not_in_use (self , router_id , subnet ):
1062
1069
context = n_ctx .get_admin_context ()
0 commit comments