Support ovsdb-client monitor with remote connection
When using XenServer as hypervisor, we found we cannot set ovs agent which runs in compute node with "minimize_polling=True". Because once set it True, the ovs agent will monitor the local ovsdb, but we want it monitor ovsdb in Dom0. This patch is to add support for ovsdb-client to monitor remote connection. Change-Id: Idf2a564e96626dab3c4421a1f9139ed9ffcbcab1 Closes-bug: 1647914
This commit is contained in:
parent
eb27f0be52
commit
71edbb0d7d
|
@ -33,14 +33,20 @@ class OvsdbMonitor(async_process.AsyncProcess):
|
|||
"""Manages an invocation of 'ovsdb-client monitor'."""
|
||||
|
||||
def __init__(self, table_name, columns=None, format=None,
|
||||
respawn_interval=None):
|
||||
|
||||
cmd = ['ovsdb-client', 'monitor', table_name]
|
||||
respawn_interval=None, ovsdb_connection=None):
|
||||
if ovsdb_connection:
|
||||
# if ovsdb connection is configured (e.g. tcp:ip:port), use it,
|
||||
# and there is no need to run as root
|
||||
cmd = ['ovsdb-client', 'monitor', ovsdb_connection, table_name]
|
||||
run_as_root = False
|
||||
else:
|
||||
cmd = ['ovsdb-client', 'monitor', table_name]
|
||||
run_as_root = True
|
||||
if columns:
|
||||
cmd.append(','.join(columns))
|
||||
if format:
|
||||
cmd.append('--format=%s' % format)
|
||||
super(OvsdbMonitor, self).__init__(cmd, run_as_root=True,
|
||||
super(OvsdbMonitor, self).__init__(cmd, run_as_root=run_as_root,
|
||||
respawn_interval=respawn_interval,
|
||||
log_output=True,
|
||||
die_on_error=True)
|
||||
|
@ -54,12 +60,13 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
|
|||
since the previous access.
|
||||
"""
|
||||
|
||||
def __init__(self, respawn_interval=None):
|
||||
def __init__(self, respawn_interval=None, ovsdb_connection=None):
|
||||
super(SimpleInterfaceMonitor, self).__init__(
|
||||
'Interface',
|
||||
columns=['name', 'ofport', 'external_ids'],
|
||||
format='json',
|
||||
respawn_interval=respawn_interval,
|
||||
ovsdb_connection=ovsdb_connection
|
||||
)
|
||||
self.new_events = {'added': [], 'removed': []}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import contextlib
|
||||
|
||||
import eventlet
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron.agent.common import base_polling
|
||||
|
@ -51,7 +52,8 @@ class InterfacePollingMinimizer(base_polling.BasePollingManager):
|
|||
|
||||
super(InterfacePollingMinimizer, self).__init__()
|
||||
self._monitor = ovsdb_monitor.SimpleInterfaceMonitor(
|
||||
respawn_interval=ovsdb_monitor_respawn_interval)
|
||||
respawn_interval=ovsdb_monitor_respawn_interval,
|
||||
ovsdb_connection=cfg.CONF.OVS.ovsdb_connection)
|
||||
|
||||
def start(self):
|
||||
self._monitor.start(block=True)
|
||||
|
|
|
@ -34,8 +34,11 @@ OPTS = [
|
|||
help=_('The interface for interacting with the OVSDB')),
|
||||
cfg.StrOpt('ovsdb_connection',
|
||||
default='tcp:127.0.0.1:6640',
|
||||
help=_('The connection string for the native OVSDB backend. '
|
||||
'Requires the native ovsdb_interface to be enabled.'))
|
||||
help=_('The connection string for the OVSDB backend. '
|
||||
'Will be used by ovsdb-client when monitoring and '
|
||||
'used for the all ovsdb commands when native '
|
||||
'ovsdb_interface is enabled'
|
||||
))
|
||||
]
|
||||
cfg.CONF.register_opts(OPTS, 'OVS')
|
||||
|
||||
|
|
|
@ -39,6 +39,18 @@ class TestOvsdbMonitor(base.BaseTestCase):
|
|||
cmd = init.call_args_list[0][0][0]
|
||||
self.assertEqual('--format=blob', cmd[-1])
|
||||
|
||||
def test__init__with_connection_columns(self):
|
||||
conn_info = 'tcp:10.10.10.10:6640'
|
||||
columns = ['col1', 'col2']
|
||||
with mock.patch(
|
||||
'neutron.agent.linux.async_process.AsyncProcess.__init__') as init:
|
||||
ovsdb_monitor.OvsdbMonitor('Interface', columns=columns,
|
||||
ovsdb_connection=conn_info)
|
||||
cmd_all = init.call_args_list[0][0][0]
|
||||
cmd_expect = ['ovsdb-client', 'monitor', 'tcp:10.10.10.10:6640',
|
||||
'Interface', 'col1,col2']
|
||||
self.assertEqual(cmd_expect, cmd_all)
|
||||
|
||||
|
||||
class TestSimpleInterfaceMonitor(base.BaseTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue