diff --git a/neutron/agent/linux/ovsdb_monitor.py b/neutron/agent/linux/ovsdb_monitor.py index a3c16bec3ec..07bde4c4c62 100644 --- a/neutron/agent/linux/ovsdb_monitor.py +++ b/neutron/agent/linux/ovsdb_monitor.py @@ -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': []} diff --git a/neutron/agent/linux/polling.py b/neutron/agent/linux/polling.py index 0faeb95f144..695fd4bc02d 100644 --- a/neutron/agent/linux/polling.py +++ b/neutron/agent/linux/polling.py @@ -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) diff --git a/neutron/agent/ovsdb/api.py b/neutron/agent/ovsdb/api.py index 04dae36073b..553d87e04eb 100644 --- a/neutron/agent/ovsdb/api.py +++ b/neutron/agent/ovsdb/api.py @@ -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') diff --git a/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py b/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py index 73a3a08702c..a6e009dcdc2 100644 --- a/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py +++ b/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py @@ -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):