Skip to content

Commit 3289eb3

Browse files
authored
Merge pull request #28 from stackhpc/upstream/yoga-2023-02-27
Synchronise yoga with upstream
2 parents 3e53816 + 43f8e59 commit 3289eb3

File tree

11 files changed

+112
-36
lines changed

11 files changed

+112
-36
lines changed

neutron/agent/common/async_process.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def __init__(self, cmd, run_as_root=False, respawn_interval=None,
9595
def cmd(self):
9696
return ' '.join(self._cmd)
9797

98+
@property
99+
def is_running(self):
100+
return self._is_running
101+
98102
def _reset_queues(self):
99103
self._stdout_lines = eventlet.queue.LightQueue()
100104
self._stderr_lines = eventlet.queue.LightQueue()

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,23 @@ def create_lswitch_port(self, lport_name, lswitch_name, may_exist=True,
4040
"""
4141

4242
@abc.abstractmethod
43-
def set_lswitch_port(self, lport_name, if_exists=True, **columns):
43+
def set_lswitch_port(self, lport_name, external_ids_update=None,
44+
if_exists=True, **columns):
4445
"""Create a command to set OVN logical switch port fields
4546
4647
:param lport_name: The name of the lport
4748
:type lport_name: string
49+
:param external_ids_update: Dictionary of keys to be updated
50+
individually in the external IDs dictionary.
51+
If "external_ids" is defined in "columns",
52+
"external_ids" will override any
53+
"external_ids_update" value.
54+
:type external_ids_update: dictionary
55+
:param if_exists: Do not fail if lport does not exist
56+
:type if_exists: bool
4857
:param columns: Dictionary of port columns
4958
Supported columns: macs, external_ids,
5059
parent_name, tag, enabled
51-
:param if_exists: Do not fail if lport does not exist
52-
:type if_exists: bool
5360
:type columns: dictionary
5461
:returns: :class:`Command` with no result
5562
"""

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ def post_commit(self, txn):
148148

149149

150150
class SetLSwitchPortCommand(command.BaseCommand):
151-
def __init__(self, api, lport, if_exists, **columns):
151+
def __init__(self, api, lport, external_ids_update, if_exists, **columns):
152152
super(SetLSwitchPortCommand, self).__init__(api)
153153
self.lport = lport
154+
self.external_ids_update = external_ids_update
154155
self.columns = columns
155156
self.if_exists = if_exists
156157

@@ -195,6 +196,12 @@ def run_idl(self, txn):
195196
for uuid in cur_port_dhcp_opts - new_port_dhcp_opts:
196197
self.api._tables['DHCP_Options'].rows[uuid].delete()
197198

199+
external_ids_update = self.external_ids_update or {}
200+
external_ids = getattr(port, 'external_ids', {})
201+
for k, v in external_ids_update.items():
202+
external_ids[k] = v
203+
port.external_ids = external_ids
204+
198205
for col, val in self.columns.items():
199206
setattr(port, col, val)
200207

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ def create_lswitch_port(self, lport_name, lswitch_name, may_exist=True,
283283
return cmd.AddLSwitchPortCommand(self, lport_name, lswitch_name,
284284
may_exist, **columns)
285285

286-
def set_lswitch_port(self, lport_name, if_exists=True, **columns):
287-
return cmd.SetLSwitchPortCommand(self, lport_name,
286+
def set_lswitch_port(self, lport_name, external_ids_update=None,
287+
if_exists=True, **columns):
288+
return cmd.SetLSwitchPortCommand(self, lport_name, external_ids_update,
288289
if_exists, **columns)
289290

290291
def delete_lswitch_port(self, lport_name=None, lswitch_name=None,

neutron/services/trunk/drivers/ovn/trunk_driver.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
from oslo_config import cfg
2222
from oslo_log import log
2323

24-
from neutron.common.ovn.constants import OVN_ML2_MECH_DRIVER_NAME
24+
from neutron.common.ovn import constants as ovn_const
25+
from neutron.db import db_base_plugin_common
26+
from neutron.db import ovn_revision_numbers_db as db_rev
2527
from neutron.objects import ports as port_obj
2628
from neutron.services.trunk.drivers import base as trunk_base
2729

@@ -47,20 +49,23 @@ def _set_sub_ports(self, parent_port, subports):
4749
context = n_context.get_admin_context()
4850
db_parent_port = port_obj.Port.get_object(context, id=parent_port)
4951
parent_port_status = db_parent_port.status
50-
for port in subports:
52+
for subport in subports:
5153
with db_api.CONTEXT_WRITER.using(context), (
5254
txn(check_error=True)) as ovn_txn:
53-
self._set_binding_profile(context, port, parent_port,
54-
parent_port_status, ovn_txn)
55+
port = self._set_binding_profile(context, subport, parent_port,
56+
parent_port_status, ovn_txn)
57+
db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS)
5558

5659
def _unset_sub_ports(self, subports):
5760
txn = self.plugin_driver.nb_ovn.transaction
5861
context = n_context.get_admin_context()
59-
for port in subports:
62+
for subport in subports:
6063
with db_api.CONTEXT_WRITER.using(context), (
6164
txn(check_error=True)) as ovn_txn:
62-
self._unset_binding_profile(context, port, ovn_txn)
65+
port = self._unset_binding_profile(context, subport, ovn_txn)
66+
db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS)
6367

68+
@db_base_plugin_common.convert_result_to_dict
6469
def _set_binding_profile(self, context, subport, parent_port,
6570
parent_port_status, ovn_txn):
6671
LOG.debug("Setting parent %s for subport %s",
@@ -71,6 +76,9 @@ def _set_binding_profile(self, context, subport, parent_port,
7176
"binding_profile: %s",
7277
subport.port_id)
7378
return
79+
check_rev_cmd = self.plugin_driver.nb_ovn.check_revision_number(
80+
db_port.id, db_port, ovn_const.TYPE_PORTS)
81+
ovn_txn.add(check_rev_cmd)
7482
try:
7583
# NOTE(flaviof): We expect binding's host to be set. Otherwise,
7684
# sub-port will not transition from DOWN to ACTIVE.
@@ -94,13 +102,18 @@ def _set_binding_profile(self, context, subport, parent_port,
94102
LOG.debug("Port not found while trying to set "
95103
"binding_profile: %s", subport.port_id)
96104
return
105+
ext_ids = {ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY: db_port.device_owner}
97106
ovn_txn.add(self.plugin_driver.nb_ovn.set_lswitch_port(
98107
lport_name=subport.port_id,
99108
parent_name=parent_port,
100-
tag=subport.segmentation_id))
109+
tag=subport.segmentation_id,
110+
external_ids_update=ext_ids,
111+
))
101112
LOG.debug("Done setting parent %s for subport %s",
102113
parent_port, subport.port_id)
114+
return db_port
103115

116+
@db_base_plugin_common.convert_result_to_dict
104117
def _unset_binding_profile(self, context, subport, ovn_txn):
105118
LOG.debug("Unsetting parent for subport %s", subport.port_id)
106119
db_port = port_obj.Port.get_object(context, id=subport.port_id)
@@ -109,6 +122,9 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
109122
"binding_profile: %s",
110123
subport.port_id)
111124
return
125+
check_rev_cmd = self.plugin_driver.nb_ovn.check_revision_number(
126+
db_port.id, db_port, ovn_const.TYPE_PORTS)
127+
ovn_txn.add(check_rev_cmd)
112128
try:
113129
db_port.device_owner = ''
114130
for binding in db_port.bindings:
@@ -128,12 +144,16 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
128144
LOG.debug("Port not found while trying to unset "
129145
"binding_profile: %s", subport.port_id)
130146
return
147+
ext_ids = {ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY: db_port.device_owner}
131148
ovn_txn.add(self.plugin_driver.nb_ovn.set_lswitch_port(
132149
lport_name=subport.port_id,
133150
parent_name=[],
134151
up=False,
135-
tag=[]))
152+
tag=[],
153+
external_ids_update=ext_ids,
154+
))
136155
LOG.debug("Done unsetting parent for subport %s", subport.port_id)
156+
return db_port
137157

138158
def trunk_created(self, trunk):
139159
# Check if parent port is handled by OVN.
@@ -185,7 +205,8 @@ class OVNTrunkDriver(trunk_base.DriverBase):
185205
@property
186206
def is_loaded(self):
187207
try:
188-
return OVN_ML2_MECH_DRIVER_NAME in cfg.CONF.ml2.mechanism_drivers
208+
return (ovn_const.OVN_ML2_MECH_DRIVER_NAME in
209+
cfg.CONF.ml2.mechanism_drivers)
189210
except cfg.NoSuchOptError:
190211
return False
191212

@@ -205,7 +226,7 @@ def register(self, resource, event, trigger, payload=None):
205226
@classmethod
206227
def create(cls, plugin_driver):
207228
cls.plugin_driver = plugin_driver
208-
return cls(OVN_ML2_MECH_DRIVER_NAME,
229+
return cls(ovn_const.OVN_ML2_MECH_DRIVER_NAME,
209230
SUPPORTED_INTERFACES,
210231
SUPPORTED_SEGMENTATION_TYPES,
211232
None,

neutron/tests/fullstack/resources/process.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ def _restart():
9898
else:
9999
return executor.submit(_restart)
100100

101+
def process_is_running(self):
102+
return self.process.is_running
103+
104+
def process_is_not_running(self):
105+
return not self.process_is_running()
106+
101107

102108
class RabbitmqEnvironmentFixture(fixtures.Fixture):
103109

neutron/tests/fullstack/test_agent_bandwidth_report.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ def test_configurations_are_synced_towards_placement(self):
237237
sleep=1)
238238

239239
self.environment.placement.process_fixture.stop()
240+
241+
placement_fixture = self.environment.placement.process_fixture
242+
utils.wait_until_true(
243+
predicate=functools.partial(
244+
placement_fixture.process_is_not_running),
245+
timeout=report_interval, sleep=1
246+
)
247+
240248
_add_new_bridge_and_restart_agent(self.environment.hosts[0])
241249

242250
check_agent_not_synced = functools.partial(

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,12 @@ def _modify_resources_in_nb_db(self):
832832
txn.add(self.nb_api.pg_del(pg))
833833

834834
for lport_name in self.reset_lport_dhcpv4_options:
835-
txn.add(self.nb_api.set_lswitch_port(lport_name, True,
836-
dhcpv4_options=[]))
835+
txn.add(self.nb_api.set_lswitch_port(
836+
lport_name, if_exists=True, dhcpv4_options=[]))
837837

838838
for lport_name in self.reset_lport_dhcpv6_options:
839-
txn.add(self.nb_api.set_lswitch_port(lport_name, True,
840-
dhcpv6_options=[]))
839+
txn.add(self.nb_api.set_lswitch_port(
840+
lport_name, if_exists=True, dhcpv6_options=[]))
841841

842842
for dhcp_opts in self.stale_lport_dhcpv4_options:
843843
dhcpv4_opts = txn.add(self.nb_api.add_dhcp_options(
@@ -850,7 +850,7 @@ def _modify_resources_in_nb_db(self):
850850
if dhcp_opts['port_id'] in self.orphaned_lport_dhcp_options:
851851
continue
852852
txn.add(self.nb_api.set_lswitch_port(
853-
lport_name, True, dhcpv4_options=dhcpv4_opts))
853+
lport_name, if_exists=True, dhcpv4_options=dhcpv4_opts))
854854

855855
for dhcp_opts in self.stale_lport_dhcpv6_options:
856856
dhcpv6_opts = txn.add(self.nb_api.add_dhcp_options(
@@ -863,7 +863,7 @@ def _modify_resources_in_nb_db(self):
863863
if dhcp_opts['port_id'] in self.orphaned_lport_dhcp_options:
864864
continue
865865
txn.add(self.nb_api.set_lswitch_port(
866-
lport_name, True, dhcpv6_options=dhcpv6_opts))
866+
lport_name, if_exists=True, dhcpv6_options=dhcpv6_opts))
867867

868868
for row_uuid in self.missed_dhcp_options:
869869
txn.add(self.nb_api.delete_dhcp_options(row_uuid))
@@ -880,12 +880,12 @@ def _modify_resources_in_nb_db(self):
880880

881881
for port_id in self.lport_dhcpv4_disabled:
882882
txn.add(self.nb_api.set_lswitch_port(
883-
port_id, True,
883+
port_id, if_exists=True,
884884
dhcpv4_options=[self.lport_dhcpv4_disabled[port_id]]))
885885

886886
for port_id in self.lport_dhcpv6_disabled:
887887
txn.add(self.nb_api.set_lswitch_port(
888-
port_id, True,
888+
port_id, if_exists=True,
889889
dhcpv6_options=[self.lport_dhcpv6_disabled[port_id]]))
890890

891891
# Delete the first DNS record and clear the second row records

neutron/tests/functional/services/trunk/drivers/ovn/test_trunk_driver.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from neutron_lib.services.trunk import constants as trunk_consts
2323
from oslo_utils import uuidutils
2424

25+
from neutron.common.ovn import constants as ovn_const
26+
2527

2628
class TestOVNTrunkDriver(base.TestOVNFunctionalBase):
2729

@@ -60,18 +62,29 @@ def _get_ovn_trunk_info(self):
6062
for row in self.nb_api.tables[
6163
'Logical_Switch_Port'].rows.values():
6264
if row.parent_name and row.tag:
65+
device_owner = row.external_ids[
66+
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY]
67+
revision_number = row.external_ids[
68+
ovn_const.OVN_REV_NUM_EXT_ID_KEY]
6369
ovn_trunk_info.append({'port_id': row.name,
6470
'parent_port_id': row.parent_name,
65-
'tag': row.tag})
71+
'tag': row.tag,
72+
'device_owner': device_owner,
73+
'revision_number': revision_number,
74+
})
6675
return ovn_trunk_info
6776

6877
def _verify_trunk_info(self, trunk, has_items):
6978
ovn_subports_info = self._get_ovn_trunk_info()
7079
neutron_subports_info = []
7180
for subport in trunk.get('sub_ports', []):
72-
neutron_subports_info.append({'port_id': subport['port_id'],
73-
'parent_port_id': [trunk['port_id']],
74-
'tag': [subport['segmentation_id']]})
81+
neutron_subports_info.append(
82+
{'port_id': subport['port_id'],
83+
'parent_port_id': [trunk['port_id']],
84+
'tag': [subport['segmentation_id']],
85+
'device_owner': trunk_consts.TRUNK_SUBPORT_OWNER,
86+
'revision_number': '2',
87+
})
7588
# Check that the subport has the binding is active.
7689
binding = obj_reg.load_class('PortBinding').get_object(
7790
self.context, port_id=subport['port_id'], host='')

neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_commands.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def _test_lswitch_port_update_no_exist(self, if_exists=True):
200200
with mock.patch.object(idlutils, 'row_by_value',
201201
side_effect=idlutils.RowNotFound):
202202
cmd = commands.SetLSwitchPortCommand(
203-
self.ovn_api, 'fake-lsp', if_exists=if_exists)
203+
self.ovn_api, 'fake-lsp', external_ids_update=None,
204+
if_exists=if_exists)
204205
if if_exists:
205206
cmd.run_idl(self.transaction)
206207
else:
@@ -220,8 +221,8 @@ def test_lswitch_port_update(self):
220221
with mock.patch.object(idlutils, 'row_by_value',
221222
return_value=fake_lsp):
222223
cmd = commands.SetLSwitchPortCommand(
223-
self.ovn_api, fake_lsp.name, if_exists=True,
224-
external_ids=new_ext_ids)
224+
self.ovn_api, fake_lsp.name, external_ids_update=new_ext_ids,
225+
if_exists=True, external_ids=new_ext_ids)
225226
cmd.run_idl(self.transaction)
226227
self.assertEqual(new_ext_ids, fake_lsp.external_ids)
227228

@@ -255,7 +256,8 @@ def _test_lswitch_port_update_del_dhcp(self, clear_v4_opts,
255256
with mock.patch.object(idlutils, 'row_by_value',
256257
return_value=fake_lsp):
257258
cmd = commands.SetLSwitchPortCommand(
258-
self.ovn_api, fake_lsp.name, if_exists=True, **columns)
259+
self.ovn_api, fake_lsp.name, external_ids_update=None,
260+
if_exists=True, **columns)
259261
cmd.run_idl(self.transaction)
260262

261263
if clear_v4_opts and clear_v6_opts:
@@ -307,7 +309,8 @@ def _test_lswitch_port_update_with_dhcp(self, dhcpv4_opts, dhcpv6_opts):
307309
with mock.patch.object(idlutils, 'row_by_value',
308310
return_value=fake_lsp):
309311
cmd = commands.SetLSwitchPortCommand(
310-
self.ovn_api, fake_lsp.name, if_exists=True,
312+
self.ovn_api, fake_lsp.name, external_ids_update=ext_ids,
313+
if_exists=True,
311314
external_ids=ext_ids, dhcpv4_options=dhcpv4_opts,
312315
dhcpv6_options=dhcpv6_opts)
313316
if not isinstance(dhcpv4_opts, list):

0 commit comments

Comments
 (0)