|
14 | 14 |
|
15 | 15 | import collections
|
16 | 16 | import functools
|
| 17 | +from random import randint |
17 | 18 | import re
|
18 | 19 | import threading
|
19 | 20 | import uuid
|
20 | 21 |
|
21 | 22 | import netaddr
|
22 | 23 | from neutron_lib import constants as n_const
|
23 | 24 | from oslo_concurrency import lockutils
|
| 25 | +from oslo_config import cfg |
24 | 26 | from oslo_log import log
|
25 | 27 | from oslo_utils import netutils
|
26 | 28 | from ovsdbapp.backend.ovs_idl import event as row_event
|
|
35 | 37 | from neutron.common.ovn import constants as ovn_const
|
36 | 38 | from neutron.common.ovn import utils as ovn_utils
|
37 | 39 | from neutron.common import utils
|
| 40 | +from neutron.conf.agent.database import agents_db |
38 | 41 | from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config
|
39 | 42 |
|
40 | 43 |
|
41 | 44 | LOG = log.getLogger(__name__)
|
| 45 | +agents_db.register_db_agents_opts() |
42 | 46 | _SYNC_STATE_LOCK = lockutils.ReaderWriterLock()
|
43 | 47 | CHASSIS_METADATA_LOCK = 'chassis_metadata_lock'
|
44 | 48 |
|
@@ -186,14 +190,27 @@ def __init__(self, metadata_agent):
|
186 | 190 | events = (self.ROW_UPDATE,)
|
187 | 191 | super(SbGlobalUpdateEvent, self).__init__(events, table, None)
|
188 | 192 | self.event_name = self.__class__.__name__
|
| 193 | + self.first_run = True |
189 | 194 |
|
190 | 195 | 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() |
197 | 214 |
|
198 | 215 |
|
199 | 216 | class MetadataAgent(object):
|
|
0 commit comments