Browse Source

Merge "[OVN] Add an interval between agents health checks"

changes/52/705452/4
Zuul 1 week ago
parent
commit
9aa9a097e6
3 changed files with 43 additions and 0 deletions
  1. +9
    -0
      neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py
  2. +2
    -0
      neutron/tests/unit/fake_resources.py
  3. +32
    -0
      neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py

+ 9
- 0
neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py View File

@@ -14,6 +14,7 @@

import atexit
import copy
import datetime
import functools
import operator
import signal
@@ -1065,6 +1066,14 @@ class OVNMechanismDriver(api.MechanismDriver):

def ping_chassis(self):
"""Update NB_Global.nb_cfg so that Chassis.nb_cfg will increment"""
last_ping = self._nb_ovn.nb_global.external_ids.get(
ovn_const.OVN_LIVENESS_CHECK_EXT_ID_KEY)
if last_ping:
interval = max(cfg.CONF.agent_down_time // 2, 1)
next_ping = (timeutils.parse_isotime(last_ping) +
datetime.timedelta(seconds=interval))
if timeutils.utcnow(with_timezone=True) < next_ping:
return

with self._nb_ovn.create_transaction(check_error=True,
bump_nb_cfg=True) as txn:

+ 2
- 0
neutron/tests/unit/fake_resources.py View File

@@ -50,6 +50,7 @@ class FakeOvsdbNbOvnIdl(object):
self._tables['NAT'] = self.nat_table
self._tables['Port_Group'] = self.port_group_table
self.transaction = mock.MagicMock()
self.create_transaction = mock.MagicMock()
self.ls_add = mock.Mock()
self.set_lswitch_ext_ids = mock.Mock()
self.ls_del = mock.Mock()
@@ -144,6 +145,7 @@ class FakeOvsdbNbOvnIdl(object):
self.set_lswitch_port_to_virtual_type = mock.Mock()
self.unset_lswitch_port_to_virtual_type = mock.Mock()
self.ls_get = mock.Mock()
self.check_liveness = mock.Mock()


class FakeOvsdbSbOvnIdl(object):

+ 32
- 0
neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py View File

@@ -1638,6 +1638,38 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
expected_opts = {}
self._test_update_network_fragmentation(new_mtu, expected_opts)

def test_ping_chassis(self):
self.nb_ovn.nb_global.external_ids = {}
self.mech_driver.ping_chassis()
self.nb_ovn.check_liveness.assert_called_once_with()

def test_ping_chassis_interval_expired(self):
timeout = 10
ovn_conf.cfg.CONF.set_override('agent_down_time', timeout)

# Pretend the interval is already expired
time = (timeutils.utcnow(with_timezone=True) -
datetime.timedelta(seconds=timeout))
self.nb_ovn.nb_global.external_ids = {
ovn_const.OVN_LIVENESS_CHECK_EXT_ID_KEY: str(time)}

# Since the interval has expired, assert that the "check_liveness"
# command has been invoked
self.mech_driver.ping_chassis()
self.nb_ovn.check_liveness.assert_called_once_with()

def test_ping_chassis_interval_not_expired(self):
ovn_conf.cfg.CONF.set_override('agent_down_time', 10)

# Pretend the interval has NOT yet expired
time = timeutils.utcnow(with_timezone=True)
self.nb_ovn.nb_global.external_ids = {
ovn_const.OVN_LIVENESS_CHECK_EXT_ID_KEY: str(time)}

# Assert that "check_liveness" wasn't invoked
self.mech_driver.ping_chassis()
self.assertFalse(self.nb_ovn.check_liveness.called)


class OVNMechanismDriverTestCase(test_plugin.Ml2PluginV2TestCase):
_mechanism_drivers = ['logger', 'ovn']

Loading…
Cancel
Save