Merge "[OVN] Provide the extension name to `OVNExtensionEvent` classes"

This commit is contained in:
Zuul
2025-08-01 19:44:12 +00:00
committed by Gerrit Code Review
5 changed files with 45 additions and 5 deletions

View File

@@ -34,6 +34,11 @@ class ConfigException(exceptions.NeutronException):
message = _('Error configuring the OVN Neutron Agent: %(description)s.')
class OVNExtensionEventEmptyExtensionName(exceptions.NeutronException):
"""OVNExtensionEvent class without a mandatory extension name defined"""
message = _('The class %(class_name)s has no extension name defined.')
class OVNExtensionEvent(metaclass=abc.ABCMeta):
"""Implements a method to retrieve the correct caller agent
@@ -43,10 +48,14 @@ class OVNExtensionEvent(metaclass=abc.ABCMeta):
by the OVN agent (with the "metadata" extension) and this class removed,
keeping only the compatibility with the OVN agent (to be removed in C+2).
"""
def __init__(self, *args, **kwargs):
def __init__(self, *args, extension_name=None, **kwargs):
if extension_name is None:
raise OVNExtensionEventEmptyExtensionName(
class_name=self.__class__.__name__)
super().__init__(*args, **kwargs)
self._agent_or_extension = None
self._agent = None
self._extension_name = extension_name
@property
def agent(self):
@@ -57,7 +66,7 @@ class OVNExtensionEvent(metaclass=abc.ABCMeta):
"""
if not self._agent_or_extension:
if isinstance(self._agent, service.Service):
self._agent_or_extension = self._agent['metadata']
self._agent_or_extension = self._agent[self._extension_name]
else:
self._agent_or_extension = self._agent
return self._agent_or_extension

View File

@@ -66,14 +66,14 @@ def _sync_lock(f):
return wrapped
class ChassisPrivateCreateEvent(extension_manager.OVNExtensionEvent,
row_event.RowEvent):
"""Row create event - Chassis name == our_chassis."""
def __init__(self, ovn_agent):
self._first_time = True
events = (self.ROW_CREATE,)
super().__init__(events, 'Chassis_Private', None)
super().__init__(events, 'Chassis_Private', None,
extension_name='metadata')
self._agent = ovn_agent
self.conditions = (('name', '=', self._agent.chassis),)
self.event_name = self.__class__.__name__

View File

@@ -90,7 +90,8 @@ class PortBindingEvent(extension_manager.OVNExtensionEvent,
row_event.RowEvent):
def __init__(self, agent):
table = 'Port_Binding'
super().__init__((self.__class__.EVENT,), table, None)
super().__init__((self.__class__.EVENT,), table, None,
extension_name='metadata')
self._agent = agent
self.event_name = self.__class__.__name__
self._log_msg = (

View File

@@ -0,0 +1,30 @@
# Copyright 2025 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from neutron.agent.ovn.extensions import extension_manager
from neutron.tests import base
class OVNExtensionEventNoExtensionName(extension_manager.OVNExtensionEvent):
pass
class TestOVNExtensionEvent(base.BaseTestCase):
def test_class_with_no_extension_name(self):
try:
OVNExtensionEventNoExtensionName()
except Exception as exc:
msg = ('The class OVNExtensionEventNoExtensionName has no '
'extension name defined.')
self.assertEqual(msg, str(exc))