Merge "Support ovsdb-client monitor with remote connection"
This commit is contained in:
@@ -33,14 +33,20 @@ class OvsdbMonitor(async_process.AsyncProcess):
|
|||||||
"""Manages an invocation of 'ovsdb-client monitor'."""
|
"""Manages an invocation of 'ovsdb-client monitor'."""
|
||||||
|
|
||||||
def __init__(self, table_name, columns=None, format=None,
|
def __init__(self, table_name, columns=None, format=None,
|
||||||
respawn_interval=None):
|
respawn_interval=None, ovsdb_connection=None):
|
||||||
|
if ovsdb_connection:
|
||||||
cmd = ['ovsdb-client', 'monitor', table_name]
|
# 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:
|
if columns:
|
||||||
cmd.append(','.join(columns))
|
cmd.append(','.join(columns))
|
||||||
if format:
|
if format:
|
||||||
cmd.append('--format=%s' % 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,
|
respawn_interval=respawn_interval,
|
||||||
log_output=True,
|
log_output=True,
|
||||||
die_on_error=True)
|
die_on_error=True)
|
||||||
@@ -54,12 +60,13 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
|
|||||||
since the previous access.
|
since the previous access.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, respawn_interval=None):
|
def __init__(self, respawn_interval=None, ovsdb_connection=None):
|
||||||
super(SimpleInterfaceMonitor, self).__init__(
|
super(SimpleInterfaceMonitor, self).__init__(
|
||||||
'Interface',
|
'Interface',
|
||||||
columns=['name', 'ofport', 'external_ids'],
|
columns=['name', 'ofport', 'external_ids'],
|
||||||
format='json',
|
format='json',
|
||||||
respawn_interval=respawn_interval,
|
respawn_interval=respawn_interval,
|
||||||
|
ovsdb_connection=ovsdb_connection
|
||||||
)
|
)
|
||||||
self.new_events = {'added': [], 'removed': []}
|
self.new_events = {'added': [], 'removed': []}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from neutron.agent.common import base_polling
|
from neutron.agent.common import base_polling
|
||||||
@@ -51,7 +52,8 @@ class InterfacePollingMinimizer(base_polling.BasePollingManager):
|
|||||||
|
|
||||||
super(InterfacePollingMinimizer, self).__init__()
|
super(InterfacePollingMinimizer, self).__init__()
|
||||||
self._monitor = ovsdb_monitor.SimpleInterfaceMonitor(
|
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):
|
def start(self):
|
||||||
self._monitor.start(block=True)
|
self._monitor.start(block=True)
|
||||||
|
|||||||
@@ -34,8 +34,11 @@ OPTS = [
|
|||||||
help=_('The interface for interacting with the OVSDB')),
|
help=_('The interface for interacting with the OVSDB')),
|
||||||
cfg.StrOpt('ovsdb_connection',
|
cfg.StrOpt('ovsdb_connection',
|
||||||
default='tcp:127.0.0.1:6640',
|
default='tcp:127.0.0.1:6640',
|
||||||
help=_('The connection string for the native OVSDB backend. '
|
help=_('The connection string for the OVSDB backend. '
|
||||||
'Requires the native ovsdb_interface to be enabled.'))
|
'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')
|
cfg.CONF.register_opts(OPTS, 'OVS')
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,18 @@ class TestOvsdbMonitor(base.BaseTestCase):
|
|||||||
cmd = init.call_args_list[0][0][0]
|
cmd = init.call_args_list[0][0][0]
|
||||||
self.assertEqual('--format=blob', cmd[-1])
|
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):
|
class TestSimpleInterfaceMonitor(base.BaseTestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user