Skip to content

Commit 442249a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Spread OVN metadata agent heartbeat response in time" into stable/zed
2 parents 66a55a2 + a7e91a8 commit 442249a

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

neutron/agent/ovn/metadata/agent.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
import collections
1616
import functools
17+
from random import randint
1718
import re
1819
import threading
1920
import uuid
2021

2122
import netaddr
2223
from neutron_lib import constants as n_const
2324
from oslo_concurrency import lockutils
25+
from oslo_config import cfg
2426
from oslo_log import log
2527
from oslo_utils import netutils
2628
from ovsdbapp.backend.ovs_idl import event as row_event
@@ -35,10 +37,12 @@
3537
from neutron.common.ovn import constants as ovn_const
3638
from neutron.common.ovn import utils as ovn_utils
3739
from neutron.common import utils
40+
from neutron.conf.agent.database import agents_db
3841
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config
3942

4043

4144
LOG = log.getLogger(__name__)
45+
agents_db.register_db_agents_opts()
4246
_SYNC_STATE_LOCK = lockutils.ReaderWriterLock()
4347
CHASSIS_METADATA_LOCK = 'chassis_metadata_lock'
4448

@@ -186,14 +190,27 @@ def __init__(self, metadata_agent):
186190
events = (self.ROW_UPDATE,)
187191
super(SbGlobalUpdateEvent, self).__init__(events, table, None)
188192
self.event_name = self.__class__.__name__
193+
self.first_run = True
189194

190195
def run(self, event, row, old):
191-
table = ('Chassis_Private' if self.agent.has_chassis_private
192-
else 'Chassis')
193-
self.agent.sb_idl.db_set(
194-
table, self.agent.chassis, ('external_ids', {
195-
ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY:
196-
str(row.nb_cfg)})).execute()
196+
197+
def _update_chassis(self, row):
198+
table = ('Chassis_Private' if self.agent.has_chassis_private
199+
else 'Chassis')
200+
self.agent.sb_idl.db_set(
201+
table, self.agent.chassis, ('external_ids', {
202+
ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY:
203+
str(row.nb_cfg)})).execute()
204+
205+
if self.first_run:
206+
interval = 0
207+
self.first_run = False
208+
else:
209+
interval = randint(0, cfg.CONF.agent_down_time // 2)
210+
211+
LOG.debug("Delaying updating chassis table for %s seconds", interval)
212+
timer = threading.Timer(interval, _update_chassis, [self, row])
213+
timer.start()
197214

198215

199216
class MetadataAgent(object):

0 commit comments

Comments
 (0)