Re-home ovsdb event classes
Placing in a separate file allows the agent code to no longer import any driver code. Change-Id: Ibccf64cb77902d39f286f00a35875a50b41bab3e
This commit is contained in:
parent
b1a457f35f
commit
90cd9ba1e6
@ -15,7 +15,7 @@
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from ovn_octavia_provider.common import config as ovn_conf
|
from ovn_octavia_provider.common import config as ovn_conf
|
||||||
from ovn_octavia_provider import driver
|
from ovn_octavia_provider import event as ovn_event
|
||||||
from ovn_octavia_provider import helper as ovn_helper
|
from ovn_octavia_provider import helper as ovn_helper
|
||||||
from ovn_octavia_provider.ovsdb import impl_idl_ovn
|
from ovn_octavia_provider.ovsdb import impl_idl_ovn
|
||||||
|
|
||||||
@ -29,8 +29,8 @@ OVN_EVENT_LOCK_NAME = "neutron_ovn_octavia_event_lock"
|
|||||||
def OvnProviderAgent(exit_event):
|
def OvnProviderAgent(exit_event):
|
||||||
|
|
||||||
helper = ovn_helper.OvnProviderHelper()
|
helper = ovn_helper.OvnProviderHelper()
|
||||||
events = [driver.LogicalRouterPortEvent(helper),
|
events = [ovn_event.LogicalRouterPortEvent(helper),
|
||||||
driver.LogicalSwitchPortUpdateEvent(helper)]
|
ovn_event.LogicalSwitchPortUpdateEvent(helper)]
|
||||||
|
|
||||||
# NOTE(mjozefcz): This API is only for handling OVSDB events!
|
# NOTE(mjozefcz): This API is only for handling OVSDB events!
|
||||||
ovn_nb_idl_for_events = impl_idl_ovn.OvnNbIdlForLb(
|
ovn_nb_idl_for_events = impl_idl_ovn.OvnNbIdlForLb(
|
||||||
|
@ -21,7 +21,6 @@ from octavia_lib.api.drivers import exceptions as driver_exceptions
|
|||||||
from octavia_lib.api.drivers import provider_base as driver_base
|
from octavia_lib.api.drivers import provider_base as driver_base
|
||||||
from octavia_lib.common import constants
|
from octavia_lib.common import constants
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from ovsdbapp.backend.ovs_idl import event as row_event
|
|
||||||
|
|
||||||
from ovn_octavia_provider.common import config as ovn_conf
|
from ovn_octavia_provider.common import config as ovn_conf
|
||||||
# TODO(mjozefcz): Start consuming const and utils
|
# TODO(mjozefcz): Start consuming const and utils
|
||||||
@ -36,54 +35,6 @@ ovn_conf.register_opts()
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LogicalRouterPortEvent(row_event.RowEvent):
|
|
||||||
|
|
||||||
def __init__(self, driver):
|
|
||||||
table = 'Logical_Router_Port'
|
|
||||||
events = (self.ROW_CREATE, self.ROW_DELETE)
|
|
||||||
super(LogicalRouterPortEvent, self).__init__(
|
|
||||||
events, table, None)
|
|
||||||
self.event_name = 'LogicalRouterPortEvent'
|
|
||||||
self.driver = driver
|
|
||||||
|
|
||||||
def run(self, event, row, old):
|
|
||||||
LOG.debug('LogicalRouterPortEvent logged, '
|
|
||||||
'%(event)s, %(row)s',
|
|
||||||
{'event': event,
|
|
||||||
'row': row})
|
|
||||||
if row.gateway_chassis:
|
|
||||||
return
|
|
||||||
if event == self.ROW_CREATE:
|
|
||||||
self.driver.lb_create_lrp_assoc_handler(row)
|
|
||||||
elif event == self.ROW_DELETE:
|
|
||||||
self.driver.lb_delete_lrp_assoc_handler(row)
|
|
||||||
|
|
||||||
|
|
||||||
class LogicalSwitchPortUpdateEvent(row_event.RowEvent):
|
|
||||||
|
|
||||||
def __init__(self, driver):
|
|
||||||
table = 'Logical_Switch_Port'
|
|
||||||
events = (self.ROW_UPDATE,)
|
|
||||||
super(LogicalSwitchPortUpdateEvent, self).__init__(
|
|
||||||
events, table, None)
|
|
||||||
self.event_name = 'LogicalSwitchPortUpdateEvent'
|
|
||||||
self.driver = driver
|
|
||||||
|
|
||||||
def run(self, event, row, old):
|
|
||||||
LOG.debug('LogicalSwitchPortUpdateEvent logged, '
|
|
||||||
'%(event)s, %(row)s',
|
|
||||||
{'event': event,
|
|
||||||
'row': row})
|
|
||||||
# Get the neutron:port_name from external_ids and check if
|
|
||||||
# it's a vip port or not.
|
|
||||||
port_name = row.external_ids.get(
|
|
||||||
ovn_const.OVN_PORT_NAME_EXT_ID_KEY, '')
|
|
||||||
if port_name.startswith(ovn_const.LB_VIP_PORT_PREFIX):
|
|
||||||
# Handle port update only for vip ports created by
|
|
||||||
# this driver.
|
|
||||||
self.driver.vip_port_update_handler(row)
|
|
||||||
|
|
||||||
|
|
||||||
class OvnProviderDriver(driver_base.ProviderDriver):
|
class OvnProviderDriver(driver_base.ProviderDriver):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
70
ovn_octavia_provider/event.py
Normal file
70
ovn_octavia_provider/event.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# Copyright 2020 Red Hat, Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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 oslo_log import log as logging
|
||||||
|
from ovsdbapp.backend.ovs_idl import event as row_event
|
||||||
|
|
||||||
|
# TODO(mjozefcz): Start consuming const and utils
|
||||||
|
# from neutron-lib once released.
|
||||||
|
from ovn_octavia_provider.common import constants as ovn_const
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class LogicalRouterPortEvent(row_event.RowEvent):
|
||||||
|
|
||||||
|
def __init__(self, driver):
|
||||||
|
table = 'Logical_Router_Port'
|
||||||
|
events = (self.ROW_CREATE, self.ROW_DELETE)
|
||||||
|
super(LogicalRouterPortEvent, self).__init__(
|
||||||
|
events, table, None)
|
||||||
|
self.event_name = 'LogicalRouterPortEvent'
|
||||||
|
self.driver = driver
|
||||||
|
|
||||||
|
def run(self, event, row, old):
|
||||||
|
LOG.debug('LogicalRouterPortEvent logged, '
|
||||||
|
'%(event)s, %(row)s',
|
||||||
|
{'event': event,
|
||||||
|
'row': row})
|
||||||
|
if row.gateway_chassis:
|
||||||
|
return
|
||||||
|
if event == self.ROW_CREATE:
|
||||||
|
self.driver.lb_create_lrp_assoc_handler(row)
|
||||||
|
elif event == self.ROW_DELETE:
|
||||||
|
self.driver.lb_delete_lrp_assoc_handler(row)
|
||||||
|
|
||||||
|
|
||||||
|
class LogicalSwitchPortUpdateEvent(row_event.RowEvent):
|
||||||
|
|
||||||
|
def __init__(self, driver):
|
||||||
|
table = 'Logical_Switch_Port'
|
||||||
|
events = (self.ROW_UPDATE,)
|
||||||
|
super(LogicalSwitchPortUpdateEvent, self).__init__(
|
||||||
|
events, table, None)
|
||||||
|
self.event_name = 'LogicalSwitchPortUpdateEvent'
|
||||||
|
self.driver = driver
|
||||||
|
|
||||||
|
def run(self, event, row, old):
|
||||||
|
LOG.debug('LogicalSwitchPortUpdateEvent logged, '
|
||||||
|
'%(event)s, %(row)s',
|
||||||
|
{'event': event,
|
||||||
|
'row': row})
|
||||||
|
# Get the neutron:port_name from external_ids and check if
|
||||||
|
# it's a vip port or not.
|
||||||
|
port_name = row.external_ids.get(
|
||||||
|
ovn_const.OVN_PORT_NAME_EXT_ID_KEY, '')
|
||||||
|
if port_name.startswith(ovn_const.LB_VIP_PORT_PREFIX):
|
||||||
|
# Handle port update only for vip ports created by
|
||||||
|
# this driver.
|
||||||
|
self.driver.vip_port_update_handler(row)
|
@ -35,6 +35,7 @@ from ovn_octavia_provider import agent as ovn_agent
|
|||||||
from ovn_octavia_provider.common import clients
|
from ovn_octavia_provider.common import clients
|
||||||
from ovn_octavia_provider.common import constants as ovn_const
|
from ovn_octavia_provider.common import constants as ovn_const
|
||||||
from ovn_octavia_provider import driver as ovn_driver
|
from ovn_octavia_provider import driver as ovn_driver
|
||||||
|
from ovn_octavia_provider import event as ovn_event
|
||||||
from ovn_octavia_provider import helper as ovn_helper
|
from ovn_octavia_provider import helper as ovn_helper
|
||||||
from ovn_octavia_provider.ovsdb import impl_idl_ovn
|
from ovn_octavia_provider.ovsdb import impl_idl_ovn
|
||||||
|
|
||||||
@ -1181,8 +1182,8 @@ class TestOvnOctaviaProviderAgent(TestOvnOctaviaBase):
|
|||||||
# we can initialize this IDL here instead spawning
|
# we can initialize this IDL here instead spawning
|
||||||
# another process.
|
# another process.
|
||||||
da_helper = ovn_helper.OvnProviderHelper()
|
da_helper = ovn_helper.OvnProviderHelper()
|
||||||
events = [ovn_driver.LogicalRouterPortEvent(da_helper),
|
events = [ovn_event.LogicalRouterPortEvent(da_helper),
|
||||||
ovn_driver.LogicalSwitchPortUpdateEvent(da_helper)]
|
ovn_event.LogicalSwitchPortUpdateEvent(da_helper)]
|
||||||
ovn_nb_idl_for_events = impl_idl_ovn.OvnNbIdlForLb(
|
ovn_nb_idl_for_events = impl_idl_ovn.OvnNbIdlForLb(
|
||||||
event_lock_name='func_test')
|
event_lock_name='func_test')
|
||||||
ovn_nb_idl_for_events.notify_handler.watch_events(events)
|
ovn_nb_idl_for_events.notify_handler.watch_events(events)
|
||||||
|
@ -22,7 +22,7 @@ from ovsdbapp.backend.ovs_idl import idlutils
|
|||||||
|
|
||||||
from ovn_octavia_provider.common import clients
|
from ovn_octavia_provider.common import clients
|
||||||
from ovn_octavia_provider.common import constants as ovn_const
|
from ovn_octavia_provider.common import constants as ovn_const
|
||||||
from ovn_octavia_provider import driver as ovn_driver
|
from ovn_octavia_provider import event as ovn_event
|
||||||
from ovn_octavia_provider import helper as ovn_helper
|
from ovn_octavia_provider import helper as ovn_helper
|
||||||
from ovn_octavia_provider.tests.unit import base as ovn_base
|
from ovn_octavia_provider.tests.unit import base as ovn_base
|
||||||
from ovn_octavia_provider.tests.unit import fakes
|
from ovn_octavia_provider.tests.unit import fakes
|
||||||
@ -1299,7 +1299,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
|
|
||||||
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
|
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
|
||||||
def test_logical_router_port_event_create(self, net_cli):
|
def test_logical_router_port_event_create(self, net_cli):
|
||||||
self.router_port_event = ovn_driver.LogicalRouterPortEvent(
|
self.router_port_event = ovn_event.LogicalRouterPortEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
||||||
attrs={'gateway_chassis': []})
|
attrs={'gateway_chassis': []})
|
||||||
@ -1313,7 +1313,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
|
|
||||||
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
|
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
|
||||||
def test_logical_router_port_event_delete(self, net_cli):
|
def test_logical_router_port_event_delete(self, net_cli):
|
||||||
self.router_port_event = ovn_driver.LogicalRouterPortEvent(
|
self.router_port_event = ovn_event.LogicalRouterPortEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
||||||
attrs={'gateway_chassis': []})
|
attrs={'gateway_chassis': []})
|
||||||
@ -1327,7 +1327,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
|
|
||||||
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
|
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
|
||||||
def test_logical_router_port_event_gw_port(self, net_cli):
|
def test_logical_router_port_event_gw_port(self, net_cli):
|
||||||
self.router_port_event = ovn_driver.LogicalRouterPortEvent(
|
self.router_port_event = ovn_event.LogicalRouterPortEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
||||||
attrs={'gateway_chassis': ['temp-gateway-chassis']})
|
attrs={'gateway_chassis': ['temp-gateway-chassis']})
|
||||||
@ -1848,7 +1848,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
'Load_Balancer', self.ref_lb1.uuid, ('external_ids', exp_ls_refs))
|
'Load_Balancer', self.ref_lb1.uuid, ('external_ids', exp_ls_refs))
|
||||||
|
|
||||||
def test_logical_switch_port_update_event_vip_port(self):
|
def test_logical_switch_port_update_event_vip_port(self):
|
||||||
self.switch_port_event = ovn_driver.LogicalSwitchPortUpdateEvent(
|
self.switch_port_event = ovn_event.LogicalSwitchPortUpdateEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
||||||
attrs = {
|
attrs = {
|
||||||
@ -1867,7 +1867,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
self.mock_add_request.assert_called_once_with(expected_call)
|
self.mock_add_request.assert_called_once_with(expected_call)
|
||||||
|
|
||||||
def test_logical_switch_port_update_event_missing_port_name(self):
|
def test_logical_switch_port_update_event_missing_port_name(self):
|
||||||
self.switch_port_event = ovn_driver.LogicalSwitchPortUpdateEvent(
|
self.switch_port_event = ovn_event.LogicalSwitchPortUpdateEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
attrs = {'external_ids': {}}
|
attrs = {'external_ids': {}}
|
||||||
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
||||||
@ -1876,7 +1876,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
self.mock_add_request.assert_not_called()
|
self.mock_add_request.assert_not_called()
|
||||||
|
|
||||||
def test_logical_switch_port_update_event_empty_fip(self):
|
def test_logical_switch_port_update_event_empty_fip(self):
|
||||||
self.switch_port_event = ovn_driver.LogicalSwitchPortUpdateEvent(
|
self.switch_port_event = ovn_event.LogicalSwitchPortUpdateEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
||||||
attrs = {'external_ids':
|
attrs = {'external_ids':
|
||||||
@ -1893,7 +1893,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
self.mock_add_request.assert_called_once_with(expected_call)
|
self.mock_add_request.assert_called_once_with(expected_call)
|
||||||
|
|
||||||
def test_logical_switch_port_update_event_not_vip_port(self):
|
def test_logical_switch_port_update_event_not_vip_port(self):
|
||||||
self.switch_port_event = ovn_driver.LogicalSwitchPortUpdateEvent(
|
self.switch_port_event = ovn_event.LogicalSwitchPortUpdateEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
port_name = 'foo'
|
port_name = 'foo'
|
||||||
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
|
||||||
@ -1906,7 +1906,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
'_find_ovn_lbs')
|
'_find_ovn_lbs')
|
||||||
def test_vip_port_update_handler_lb_not_found(self, lb):
|
def test_vip_port_update_handler_lb_not_found(self, lb):
|
||||||
lb.side_effect = [idlutils.RowNotFound for _ in range(5)]
|
lb.side_effect = [idlutils.RowNotFound for _ in range(5)]
|
||||||
self.switch_port_event = ovn_driver.LogicalSwitchPortUpdateEvent(
|
self.switch_port_event = ovn_event.LogicalSwitchPortUpdateEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
||||||
attrs = {'external_ids':
|
attrs = {'external_ids':
|
||||||
@ -1922,7 +1922,7 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
|
|||||||
lb1 = mock.MagicMock()
|
lb1 = mock.MagicMock()
|
||||||
lb2 = mock.MagicMock()
|
lb2 = mock.MagicMock()
|
||||||
lb.return_value = [lb1, lb2]
|
lb.return_value = [lb1, lb2]
|
||||||
self.switch_port_event = ovn_driver.LogicalSwitchPortUpdateEvent(
|
self.switch_port_event = ovn_event.LogicalSwitchPortUpdateEvent(
|
||||||
self.helper)
|
self.helper)
|
||||||
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
port_name = '%s%s' % (ovn_const.LB_VIP_PORT_PREFIX, 'foo')
|
||||||
attrs = {'external_ids':
|
attrs = {'external_ids':
|
||||||
|
Loading…
Reference in New Issue
Block a user