Skip to content

Commit 04d0ac5

Browse files
authored
Merge pull request #22 from stackhpc/upstream/yoga-2023-01-23
Synchronise yoga with upstream
2 parents b4b4ac5 + 2f6d531 commit 04d0ac5

File tree

3 files changed

+75
-15
lines changed

3 files changed

+75
-15
lines changed

neutron/db/l3_db.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ def check_agent_ts():
470470
nb_cfg_timestamp = timestamp * 1000
471471
self.sb_api.db_set('Chassis_Private', self.chassis_name, (
472472
'nb_cfg_timestamp', nb_cfg_timestamp)).execute(check_error=True)
473+
# Also increment nb_cfg by 1 to trigger ChassisAgentWriteEvent which
474+
# is responsible to update AgentCache
475+
old_nb_cfg = self.sb_api.db_get('Chassis_Private', self.chassis_name,
476+
'nb_cfg').execute(check_error=True)
477+
self.sb_api.db_set('Chassis_Private', self.chassis_name, (
478+
'nb_cfg', old_nb_cfg + 1)).execute(check_error=True)
473479
try:
474480
n_utils.wait_until_true(check_agent_ts, timeout=5)
475481
except n_utils.WaitTimeout:

neutron/tests/unit/db/test_l3_db.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,53 @@ def test__validate_one_router_ipv6_port_per_network_mix_ipv4_ipv6(self):
577577
self.db._validate_one_router_ipv6_port_per_network(
578578
router, new_port)
579579

580+
def test__validate_one_router_ipv6_port_per_network_distributed_port(self):
581+
port = models_v2.Port(
582+
id=uuidutils.generate_uuid(),
583+
network_id='foo_network',
584+
device_owner=n_const.DEVICE_OWNER_DVR_INTERFACE,
585+
fixed_ips=[models_v2.IPAllocation(
586+
ip_address=str(netaddr.IPNetwork(
587+
'2001:db8::/32').ip + 1),
588+
subnet_id='foo_subnet')])
589+
rports = [l3_models.RouterPort(router_id='foo_router', port=port)]
590+
router = l3_models.Router(
591+
id='foo_router', attached_ports=rports, route_list=[],
592+
gw_port_id=None)
593+
new_port = models_v2.Port(
594+
id=uuidutils.generate_uuid(),
595+
network_id='foo_network',
596+
device_owner=n_const.DEVICE_OWNER_ROUTER_SNAT,
597+
fixed_ips=[models_v2.IPAllocation(
598+
ip_address=str(netaddr.IPNetwork(
599+
'2001:db8::/32').ip + 2),
600+
subnet_id='foo_subnet')])
601+
self.db._validate_one_router_ipv6_port_per_network(router, new_port)
602+
603+
def test__validate_one_router_ipv6_port_per_network_centralized_snat_port(
604+
self):
605+
port = models_v2.Port(
606+
id=uuidutils.generate_uuid(),
607+
network_id='foo_network',
608+
device_owner=n_const.DEVICE_OWNER_ROUTER_SNAT,
609+
fixed_ips=[models_v2.IPAllocation(
610+
ip_address=str(netaddr.IPNetwork(
611+
'2001:db8::/32').ip + 1),
612+
subnet_id='foo_subnet')])
613+
rports = [l3_models.RouterPort(router_id='foo_router', port=port)]
614+
router = l3_models.Router(
615+
id='foo_router', attached_ports=rports, route_list=[],
616+
gw_port_id=None)
617+
new_port = models_v2.Port(
618+
id=uuidutils.generate_uuid(),
619+
network_id='foo_network',
620+
device_owner=n_const.DEVICE_OWNER_DVR_INTERFACE,
621+
fixed_ips=[models_v2.IPAllocation(
622+
ip_address=str(netaddr.IPNetwork(
623+
'2001:db8::/32').ip + 2),
624+
subnet_id='foo_subnet')])
625+
self.db._validate_one_router_ipv6_port_per_network(router, new_port)
626+
580627
def test__validate_one_router_ipv6_port_per_network_failed(self):
581628
port = models_v2.Port(
582629
id=uuidutils.generate_uuid(),

0 commit comments

Comments
 (0)