Skip to content

Commit c476919

Browse files
authored
Merge pull request #130 from stackhpc/upstream/zed-2024-03-11
Synchronise zed with upstream
2 parents 9f87ae0 + cf21a4d commit c476919

File tree

3 files changed

+58
-54
lines changed

3 files changed

+58
-54
lines changed

neutron/agent/ovn/metadata/agent.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def run(self, event, row, old):
9393
net_name = ovn_utils.get_network_name_from_datapath(
9494
row.datapath)
9595
LOG.info(self.LOG_MSG, row.logical_port, net_name)
96-
self.agent.provision_datapath(row.datapath)
96+
self.agent.provision_datapath(row)
9797
except ConfigException:
9898
# We're now in the reader lock mode, we need to exit the
9999
# context and then use writer lock
@@ -341,12 +341,12 @@ def _get_ovn_bridge(self):
341341
"br-int instead.")
342342
return 'br-int'
343343

344-
def get_networks_datapaths(self):
345-
"""Return a set of datapath objects of the VIF ports on the current
344+
def get_networks_port_bindings(self):
345+
"""Return a set of Port_Binding objects of the VIF ports on the current
346346
chassis.
347347
"""
348348
ports = self.sb_idl.get_ports_on_chassis(self.chassis)
349-
return set(p.datapath for p in self._vif_ports(ports))
349+
return list(self._vif_ports(ports))
350350

351351
@_sync_lock
352352
def sync(self):
@@ -361,12 +361,12 @@ def sync(self):
361361
system_namespaces = tuple(
362362
ns.decode('utf-8') if isinstance(ns, bytes) else ns
363363
for ns in ip_lib.list_network_namespaces())
364-
net_datapaths = self.get_networks_datapaths()
365-
metadata_namespaces = [
364+
net_port_bindings = self.get_networks_port_bindings()
365+
metadata_namespaces = set(
366366
self._get_namespace_name(
367367
ovn_utils.get_network_name_from_datapath(datapath))
368-
for datapath in net_datapaths
369-
]
368+
for datapath in (pb.datapath for pb in net_port_bindings)
369+
)
370370
unused_namespaces = [ns for ns in system_namespaces if
371371
ns.startswith(NS_PREFIX) and
372372
ns not in metadata_namespaces]
@@ -376,8 +376,8 @@ def sync(self):
376376
# resync all network namespaces based on the associated datapaths,
377377
# even those that are already running. This is to make sure
378378
# everything within each namespace is up to date.
379-
for datapath in net_datapaths:
380-
self.provision_datapath(datapath)
379+
for port_binding in net_port_bindings:
380+
self.provision_datapath(port_binding)
381381

382382
@staticmethod
383383
def _get_veth_name(datapath):
@@ -548,19 +548,21 @@ def _get_provision_params(self, datapath):
548548

549549
return net_name, datapath_ports_ips, metadata_port_info
550550

551-
def provision_datapath(self, datapath):
551+
def provision_datapath(self, port_binding):
552552
"""Provision the datapath so that it can serve metadata.
553553
554554
This function will create the namespace and VETH pair if needed
555555
and assign the IP addresses to the interface corresponding to the
556556
metadata port of the network. It will also remove existing IP from
557557
the namespace if they are no longer needed.
558558
559-
:param datapath: datapath object.
560-
:return: The metadata namespace name for the datapath or None
561-
if namespace was not provisioned
559+
:param port_binding: Port_Binding object.
560+
:return: The metadata namespace name for the Port_Binding.datapath or
561+
None if namespace was not provisioned
562562
"""
563-
563+
datapath = port_binding.datapath
564+
mtu = int(port_binding.external_ids.get(
565+
ovn_const.OVN_NETWORK_MTU_EXT_ID_KEY) or '0')
564566
provision_params = self._get_provision_params(datapath)
565567
if not provision_params:
566568
return
@@ -586,13 +588,18 @@ def provision_datapath(self, datapath):
586588
ip1, ip2 = ip_lib.IPWrapper().add_veth(
587589
veth_name[0], veth_name[1], namespace)
588590

591+
# Configure the MAC address.
592+
ip2.link.set_address(metadata_port_info.mac)
593+
594+
# Set VETH ports MTU.
595+
if mtu:
596+
ip1.link.set_mtu(mtu)
597+
ip2.link.set_mtu(mtu)
598+
589599
# Make sure both ends of the VETH are up
590600
ip1.link.set_up()
591601
ip2.link.set_up()
592602

593-
# Configure the MAC address.
594-
ip2.link.set_address(metadata_port_info.mac)
595-
596603
cidrs_to_add, cidrs_to_delete = self._process_cidrs(
597604
{dev['cidr'] for dev in ip2.addr.list()},
598605
datapath_ports_ips,

neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"security_group_ids",
7979
"address4_scope_id",
8080
"address6_scope_id",
81+
"mtu",
8182
],
8283
)
8384

@@ -366,6 +367,7 @@ def _get_port_options(self, port):
366367
address6_scope_id = ""
367368
dhcpv4_options = self._get_port_dhcp_options(port, const.IP_VERSION_4)
368369
dhcpv6_options = self._get_port_dhcp_options(port, const.IP_VERSION_6)
370+
mtu = ''
369371
if vtep_physical_switch:
370372
vtep_logical_switch = binding_prof.get('vtep-logical-switch')
371373
port_type = 'vtep'
@@ -482,10 +484,10 @@ def _get_port_options(self, port):
482484
ovn_const.VIF_DETAILS_PF_MAC_ADDRESS in binding_prof):
483485
port_net = self._plugin.get_network(
484486
context, port['network_id'])
487+
mtu = str(port_net['mtu'])
485488
options.update({
486489
ovn_const.LSP_OPTIONS_VIF_PLUG_TYPE_KEY: 'representor',
487-
ovn_const.LSP_OPTIONS_VIF_PLUG_MTU_REQUEST_KEY: str(
488-
port_net['mtu']),
490+
ovn_const.LSP_OPTIONS_VIF_PLUG_MTU_REQUEST_KEY: mtu,
489491
ovn_const.LSP_OPTIONS_VIF_PLUG_REPRESENTOR_PF_MAC_KEY: (
490492
binding_prof.get(
491493
ovn_const.VIF_DETAILS_PF_MAC_ADDRESS)),
@@ -525,7 +527,7 @@ def _get_port_options(self, port):
525527
return OvnPortInfo(port_type, options, addresses, port_security,
526528
parent_name, tag, dhcpv4_options, dhcpv6_options,
527529
cidrs.strip(), device_owner, sg_ids,
528-
address4_scope_id, address6_scope_id
530+
address4_scope_id, address6_scope_id, mtu
529531
)
530532

531533
def sync_ha_chassis_group(self, context, network_id, txn):
@@ -633,7 +635,8 @@ def get_external_ids_from_port(self, port):
633635
port_info.security_group_ids,
634636
ovn_const.OVN_REV_NUM_EXT_ID_KEY: str(
635637
utils.get_revision_number(
636-
port, ovn_const.TYPE_PORTS))}
638+
port, ovn_const.TYPE_PORTS)),
639+
ovn_const.OVN_NETWORK_MTU_EXT_ID_KEY: port_info.mtu}
637640
return port_info, external_ids
638641

639642
def create_port(self, context, port):

neutron/tests/unit/agent/ovn/metadata/test_agent.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from neutron.agent.linux.ip_lib import IPWrapper as ip_wrap
2929
from neutron.agent.ovn.metadata import agent
3030
from neutron.agent.ovn.metadata import driver
31+
from neutron.common.ovn import constants as ovn_const
3132
from neutron.conf.agent.metadata import config as meta_conf
3233
from neutron.conf.agent.ovn.metadata import config as ovn_meta_conf
3334
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
@@ -100,14 +101,8 @@ def test_sync(self):
100101

101102
self.agent.sync()
102103

103-
pdp.assert_has_calls(
104-
[
105-
mock.call(p.datapath)
106-
for p in self.ports
107-
],
108-
any_order=True
109-
)
110-
104+
pdp.assert_has_calls([mock.call(p) for p in self.ports],
105+
any_order=True)
111106
lnn.assert_called_once_with()
112107
tdp.assert_not_called()
113108

@@ -124,27 +119,23 @@ def test_sync_teardown_namespace(self):
124119

125120
self.agent.sync()
126121

127-
pdp.assert_has_calls(
128-
[
129-
mock.call(p.datapath)
130-
for p in self.ports
131-
],
132-
any_order=True
133-
)
122+
pdp.assert_has_calls([mock.call(p) for p in self.ports],
123+
any_order=True)
134124
lnn.assert_called_once_with()
135125
tdp.assert_called_once_with('3')
136126

137-
def test_get_networks_datapaths(self):
138-
"""Test get_networks_datapaths returns only datapath objects for the
139-
networks containing vif ports of type ''(blank) and 'external'.
127+
def test_get_networks_port_bindings(self):
128+
"""Test get_networks_port_bindings returns only the port binding
129+
objects for ports with VIF type empty ('') or 'external'.
140130
This test simulates that this chassis has the following ports:
141-
* datapath '1': 1 port type '' , 1 port 'external' and
142-
1 port 'unknown'
143-
* datapath '2': 1 port type ''
144-
* datapath '3': 1 port with type 'external'
145-
* datapath '4': 1 port with type 'unknown'
146-
147-
It is expected that only datapaths '1', '2' and '3' are returned
131+
* port0: datapath 1, type ''
132+
* port1: datapath 1, type 'external'
133+
* port2: datapath 1, type 'unknown'
134+
* port3: datapath 2, type ''
135+
* port4: datapath 3, type 'external'
136+
* port5: datapath 4, type 'unknown'
137+
138+
Only port bindings from ports 0, 1, 3, and 4 are expected.
148139
"""
149140

150141
datapath_1 = DatapathInfo(uuid='uuid1',
@@ -167,11 +158,8 @@ def test_get_networks_datapaths(self):
167158

168159
with mock.patch.object(self.agent.sb_idl, 'get_ports_on_chassis',
169160
return_value=ports):
170-
expected_datapaths = set([datapath_1, datapath_2, datapath_3])
171-
self.assertSetEqual(
172-
expected_datapaths,
173-
self.agent.get_networks_datapaths()
174-
)
161+
self.assertEqual([ports[0], ports[1], ports[3], ports[4]],
162+
self.agent.get_networks_port_bindings())
175163

176164
def test_teardown_datapath(self):
177165
"""Test teardown datapath.
@@ -399,7 +387,8 @@ def test_provision_datapath(self):
399387
mock.patch.object(agent.MetadataAgent, '_get_namespace_name',
400388
return_value=nemaspace_name),\
401389
mock.patch.object(ip_link, 'set_up') as link_set_up,\
402-
mock.patch.object(ip_link, 'set_address') as link_set_addr,\
390+
mock.patch.object(ip_link, 'set_address') as link_set_addr, \
391+
mock.patch.object(ip_link, 'set_mtu') as link_set_mtu, \
403392
mock.patch.object(ip_addr, 'list', return_value=[]),\
404393
mock.patch.object(ip_addr, 'add') as ip_addr_add,\
405394
mock.patch.object(
@@ -416,7 +405,11 @@ def test_provision_datapath(self):
416405
# We need to assert that it was deleted first.
417406
self.agent.ovs_idl.list_br.return_value.execute.return_value = (
418407
['br-int', 'br-fake'])
419-
self.agent.provision_datapath('fake_datapath')
408+
mtu = 1500
409+
port_binding = mock.Mock(
410+
datapath='fake_datapath',
411+
external_ids={ovn_const.OVN_NETWORK_MTU_EXT_ID_KEY: str(mtu)})
412+
self.agent.provision_datapath(port_binding)
420413

421414
# Check that the port was deleted from br-fake
422415
self.agent.ovs_idl.del_port.assert_called_once_with(
@@ -426,6 +419,7 @@ def test_provision_datapath(self):
426419
nemaspace_name)
427420
# Make sure that the two ends of the VETH pair have been set as up.
428421
self.assertEqual(2, link_set_up.call_count)
422+
link_set_mtu.assert_has_calls([mock.call(mtu), mock.call(mtu)])
429423
link_set_addr.assert_called_once_with('aa:bb:cc:dd:ee:ff')
430424
# Make sure that the port has been added to OVS.
431425
self.agent.ovs_idl.add_port.assert_called_once_with(

0 commit comments

Comments
 (0)