Merge "Support ovsdb-client monitor with remote connection"

This commit is contained in:
Jenkins
2017-01-19 14:55:22 +00:00
committed by Gerrit Code Review
4 changed files with 32 additions and 8 deletions

View File

@@ -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': []}

View File

@@ -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)

View File

@@ -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')

View File

@@ -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):