Skip to content

Commit 46ed9fe

Browse files
authored
Merge pull request #185 from stackhpc/upstream/2023.1-2024-10-21
Synchronise 2023.1 with upstream
2 parents 0962bce + a75051c commit 46ed9fe

File tree

11 files changed

+56
-93
lines changed

11 files changed

+56
-93
lines changed

neutron/agent/linux/openvswitch_firewall/firewall.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,22 @@ def get_ofport(self, port):
703703
port_id = port['device']
704704
return self.sg_port_map.ports.get(port_id)
705705

706+
def _create_of_port(self, port, ovs_port):
707+
# Should always try to get the local vlan tag from
708+
# the OVSDB Port other_config, since the ovs-agent's
709+
# LocalVlanManager always allocated/updated it and then
710+
# set_db_attribute to Port other_config before this.
711+
port_vlan_id = self._get_port_vlan_tag(ovs_port.port_name)
712+
segment_id = self._get_port_segmentation_id(
713+
ovs_port.port_name)
714+
network_type = self._get_port_network_type(
715+
ovs_port.port_name)
716+
physical_network = self._get_port_physical_network(
717+
ovs_port.port_name)
718+
return OFPort(port, ovs_port, port_vlan_id,
719+
segment_id,
720+
network_type, physical_network)
721+
706722
def get_or_create_ofport(self, port):
707723
"""Get ofport specified by port['device'], checking and reflecting
708724
ofport changes.
@@ -713,22 +729,12 @@ def get_or_create_ofport(self, port):
713729
try:
714730
of_port = self.sg_port_map.ports[port_id]
715731
except KeyError:
716-
port_vlan_id = self._get_port_vlan_tag(ovs_port.port_name)
717-
segment_id = self._get_port_segmentation_id(
718-
ovs_port.port_name)
719-
network_type = self._get_port_network_type(
720-
ovs_port.port_name)
721-
physical_network = self._get_port_physical_network(
722-
ovs_port.port_name)
723-
of_port = OFPort(port, ovs_port, port_vlan_id,
724-
segment_id,
725-
network_type, physical_network)
732+
of_port = self._create_of_port(port, ovs_port)
726733
self.sg_port_map.create_port(of_port, port)
727734
else:
728735
if of_port.ofport != ovs_port.ofport:
729736
self.sg_port_map.remove_port(of_port)
730-
of_port = OFPort(port, ovs_port, of_port.vlan_tag,
731-
of_port.segment_id)
737+
of_port = self._create_of_port(port, ovs_port)
732738
self.sg_port_map.create_port(of_port, port)
733739
else:
734740
self.sg_port_map.update_port(of_port, port)

neutron/common/utils.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@
3737
from eventlet.green import subprocess
3838
import netaddr
3939
from neutron_lib.api.definitions import availability_zone as az_def
40-
from neutron_lib.api.definitions import portbindings
41-
from neutron_lib.api.definitions import portbindings_extended
4240
from neutron_lib import constants as n_const
4341
from neutron_lib import context as n_context
4442
from neutron_lib.db import api as db_api
45-
from neutron_lib.plugins import utils as plugin_utils
4643
from neutron_lib.services.qos import constants as qos_consts
4744
from neutron_lib.services.trunk import constants as trunk_constants
4845
from neutron_lib.utils import helpers
@@ -1091,16 +1088,3 @@ def sign_instance_id(conf, instance_id):
10911088
secret = encodeutils.to_utf8(secret)
10921089
instance_id = encodeutils.to_utf8(instance_id)
10931090
return hmac.new(secret, instance_id, hashlib.sha256).hexdigest()
1094-
1095-
1096-
# TODO(slaweq): this should be moved to neutron_lib.plugins.utils module
1097-
def is_port_bound(port, log_message=True):
1098-
active_binding = plugin_utils.get_port_binding_by_status_and_host(
1099-
port.get('port_bindings', []), n_const.ACTIVE)
1100-
if not active_binding:
1101-
if log_message:
1102-
LOG.warning('Binding for port %s was not found.', port)
1103-
return False
1104-
return active_binding[portbindings_extended.VIF_TYPE] not in (
1105-
portbindings.VIF_TYPE_UNBOUND,
1106-
portbindings.VIF_TYPE_BINDING_FAILED)

neutron/db/l3_dvr_db.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from neutron_lib.api.definitions import external_net as extnet_apidef
1818
from neutron_lib.api.definitions import l3 as l3_apidef
1919
from neutron_lib.api.definitions import portbindings
20+
from neutron_lib.api.definitions import portbindings_extended
2021
from neutron_lib.api.definitions import router_admin_state_down_before_update
2122
from neutron_lib.api import validators
2223
from neutron_lib.callbacks import events
@@ -70,6 +71,18 @@ def is_admin_state_down_necessary():
7071
return _IS_ADMIN_STATE_DOWN_NECESSARY
7172

7273

74+
# TODO(slaweq): this should be moved to neutron_lib.plugins.utils module
75+
def is_port_bound(port):
76+
active_binding = plugin_utils.get_port_binding_by_status_and_host(
77+
port.get("port_bindings", []), const.ACTIVE)
78+
if not active_binding:
79+
LOG.warning("Binding for port %s was not found.", port)
80+
return False
81+
return active_binding[portbindings_extended.VIF_TYPE] not in [
82+
portbindings.VIF_TYPE_UNBOUND,
83+
portbindings.VIF_TYPE_BINDING_FAILED]
84+
85+
7386
@registry.has_registry_receivers
7487
class DVRResourceOperationHandler(object):
7588
"""Contains callbacks for DVR operations.
@@ -1422,7 +1435,7 @@ def is_router_distributed(self, context, router_id):
14221435

14231436
def get_ports_under_dvr_connected_subnet(self, context, subnet_id):
14241437
ports = dvr_mac_db.get_ports_query_by_subnet_and_ip(context, subnet_id)
1425-
ports = [p for p in ports if n_utils.is_port_bound(p)]
1438+
ports = [p for p in ports if is_port_bound(p)]
14261439
# TODO(slaweq): if there would be way to pass to neutron-lib only
14271440
# list of extensions which actually should be processed, than setting
14281441
# process_extensions=True below could avoid that second loop and

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
from oslo_log import log
2323

2424
from neutron.common.ovn import constants as ovn_const
25-
from neutron.common import utils as n_utils
2625
from neutron.db import db_base_plugin_common
2726
from neutron.db import ovn_revision_numbers_db as db_rev
2827
from neutron.objects import ports as port_obj
2928
from neutron.services.trunk.drivers import base as trunk_base
30-
from neutron.services.trunk import exceptions as trunk_exc
3129

3230

3331
SUPPORTED_INTERFACES = (
@@ -157,10 +155,6 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
157155
LOG.debug("Done unsetting parent for subport %s", subport.port_id)
158156
return db_port
159157

160-
@staticmethod
161-
def _is_port_bound(port):
162-
return n_utils.is_port_bound(port, log_message=False)
163-
164158
def trunk_created(self, trunk):
165159
# Check if parent port is handled by OVN.
166160
if not self.plugin_driver.nb_ovn.lookup('Logical_Switch_Port',
@@ -197,16 +191,6 @@ def trunk_event(self, resource, event, trunk_plugin, payload):
197191
self.trunk_created(payload.states[0])
198192
elif event == events.AFTER_DELETE:
199193
self.trunk_deleted(payload.states[0])
200-
elif event == events.PRECOMMIT_CREATE:
201-
trunk = payload.desired_state
202-
parent_port = trunk.db_obj.port
203-
if self._is_port_bound(parent_port):
204-
raise trunk_exc.ParentPortInUse(port_id=parent_port.id)
205-
elif event == events.PRECOMMIT_DELETE:
206-
trunk = payload.states[0]
207-
parent_port = payload.states[1]
208-
if self._is_port_bound(parent_port):
209-
raise trunk_exc.TrunkInUse(trunk_id=trunk.id)
210194

211195
def subport_event(self, resource, event, trunk_plugin, payload):
212196
if event == events.AFTER_CREATE:
@@ -231,8 +215,7 @@ def register(self, resource, event, trigger, payload=None):
231215
super(OVNTrunkDriver, self).register(
232216
resource, event, trigger, payload=payload)
233217
self._handler = OVNTrunkHandler(self.plugin_driver)
234-
for _event in (events.AFTER_CREATE, events.AFTER_DELETE,
235-
events.PRECOMMIT_CREATE, events.PRECOMMIT_DELETE):
218+
for _event in (events.AFTER_CREATE, events.AFTER_DELETE):
236219
registry.subscribe(self._handler.trunk_event,
237220
resources.TRUNK,
238221
_event)

neutron/services/trunk/plugin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ def delete_trunk(self, context, trunk_id):
294294
trunk = self._get_trunk(context, trunk_id)
295295
rules.trunk_can_be_managed(context, trunk)
296296
trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
297-
parent_port = trunk.db_obj.port
298297
if trunk_port_validator.can_be_trunked_or_untrunked(context):
299298
# NOTE(status_police): when a trunk is deleted, the logical
300299
# object disappears from the datastore, therefore there is no
@@ -308,7 +307,7 @@ def delete_trunk(self, context, trunk_id):
308307
'deleting trunk port %s: %s', trunk_id,
309308
str(e))
310309
payload = events.DBEventPayload(context, resource_id=trunk_id,
311-
states=(trunk, parent_port))
310+
states=(trunk,))
312311
registry.publish(resources.TRUNK, events.PRECOMMIT_DELETE,
313312
self, payload=payload)
314313
else:
@@ -318,7 +317,7 @@ def delete_trunk(self, context, trunk_id):
318317
registry.publish(resources.TRUNK, events.AFTER_DELETE, self,
319318
payload=events.DBEventPayload(
320319
context, resource_id=trunk_id,
321-
states=(trunk, parent_port)))
320+
states=(trunk,)))
322321

323322
@db_base_plugin_common.convert_result_to_dict
324323
def add_subports(self, context, trunk_id, subports):

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414

1515
import contextlib
1616

17-
from neutron_lib.api.definitions import portbindings
18-
from neutron_lib.callbacks import exceptions as n_exc
1917
from neutron_lib import constants as n_consts
2018
from neutron_lib.objects import registry as obj_reg
2119
from neutron_lib.plugins import utils
2220
from neutron_lib.services.trunk import constants as trunk_consts
2321
from oslo_utils import uuidutils
2422

2523
from neutron.common.ovn import constants as ovn_const
26-
from neutron.objects import ports as port_obj
2724
from neutron.services.trunk import plugin as trunk_plugin
2825
from neutron.tests.functional import base
2926

@@ -108,25 +105,6 @@ def test_trunk_create_with_subports(self):
108105
with self.trunk([subport]) as trunk:
109106
self._verify_trunk_info(trunk, has_items=True)
110107

111-
def test_trunk_create_parent_port_bound(self):
112-
with self.network() as network:
113-
with self.subnet(network=network) as subnet:
114-
with self.port(subnet=subnet) as parent_port:
115-
pb = port_obj.PortBinding.get_objects(
116-
self.context, port_id=parent_port['port']['id'])
117-
port_obj.PortBinding.update_object(
118-
self.context, {'vif_type': portbindings.VIF_TYPE_OVS},
119-
port_id=pb[0].port_id, host=pb[0].host)
120-
tenant_id = uuidutils.generate_uuid()
121-
trunk = {'trunk': {
122-
'port_id': parent_port['port']['id'],
123-
'tenant_id': tenant_id, 'project_id': tenant_id,
124-
'admin_state_up': True,
125-
'name': 'trunk', 'sub_ports': []}}
126-
self.assertRaises(n_exc.CallbackFailure,
127-
self.trunk_plugin.create_trunk,
128-
self.context, trunk)
129-
130108
def test_subport_add(self):
131109
with self.subport() as subport:
132110
with self.trunk() as trunk:
@@ -149,14 +127,3 @@ def test_trunk_delete(self):
149127
with self.trunk() as trunk:
150128
self.trunk_plugin.delete_trunk(self.context, trunk['id'])
151129
self._verify_trunk_info({}, has_items=False)
152-
153-
def test_trunk_delete_parent_port_bound(self):
154-
with self.trunk() as trunk:
155-
bp = port_obj.PortBinding.get_objects(
156-
self.context, port_id=trunk['port_id'])
157-
port_obj.PortBinding.update_object(
158-
self.context, {'vif_type': portbindings.VIF_TYPE_OVS},
159-
port_id=bp[0].port_id, host=bp[0].host)
160-
self.assertRaises(n_exc.CallbackFailure,
161-
self.trunk_plugin.delete_trunk,
162-
self.context, trunk['id'])

neutron/tests/unit/agent/linux/openvswitch_firewall/test_firewall.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,21 @@ def test_get_or_create_ofport_changed(self):
658658
self.assertIn(of_port.id, self.firewall.sg_port_map.ports.keys())
659659
self.assertEqual(port.ofport, 2)
660660

661+
def test_get_or_create_ofport_changed_and_local_vlan_changed(self):
662+
port_dict = {
663+
'device': 'port-id',
664+
'security_groups': [123, 456]}
665+
of_port = create_ofport(port_dict)
666+
self.firewall.sg_port_map.ports[of_port.id] = of_port
667+
fake_ovs_port = FakeOVSPort('port', 2, '00:00:00:00:00:00')
668+
self.mock_bridge.br.get_vif_port_by_id.return_value = \
669+
fake_ovs_port
670+
self.mock_bridge.br.db_get_val.return_value = {"tag": 10}
671+
port = self.firewall.get_or_create_ofport(port_dict)
672+
self.assertIn(of_port.id, self.firewall.sg_port_map.ports.keys())
673+
self.assertEqual(port.ofport, 2)
674+
self.assertEqual(port.vlan_tag, 10)
675+
661676
def test_get_or_create_ofport_missing(self):
662677
port_dict = {
663678
'device': 'port-id',

neutron/tests/unit/db/test_l3_dvr_db.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from neutron_lib.plugins import utils as plugin_utils
3131
from oslo_utils import uuidutils
3232

33-
from neutron.common import utils as n_utils
3433
from neutron.db import agents_db
3534
from neutron.db import l3_dvr_db
3635
from neutron.db import l3_dvrscheduler_db
@@ -1522,7 +1521,7 @@ def test_is_router_distributed(self):
15221521
self.assertTrue(
15231522
self.mixin.is_router_distributed(self.ctx, router_id))
15241523

1525-
@mock.patch.object(n_utils, 'is_port_bound')
1524+
@mock.patch.object(l3_dvr_db, "is_port_bound")
15261525
def test_get_ports_under_dvr_connected_subnet(self, is_port_bound_mock):
15271526
router_dict = {'name': 'test_router', 'admin_state_up': True,
15281527
'distributed': True}

neutron/tests/unit/services/trunk/test_plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ def _test_trunk_delete_notify(self, event):
162162
resources.TRUNK, event, self.trunk_plugin, payload=mock.ANY)
163163
payload = callback.mock_calls[0][2]['payload']
164164
self.assertEqual(self.context, payload.context)
165-
self.assertEqual(trunk_obj, payload.states[0])
166-
self.assertEqual(parent_port['port']['id'], payload.states[1].id)
165+
self.assertEqual(trunk_obj, payload.latest_state)
167166
self.assertEqual(trunk['id'], payload.resource_id)
168167

169168
def test_delete_trunk_notify_after_delete(self):

releasenotes/notes/ovn-trunk-check-parent-port-eeca2eceaca9d158.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)