Skip to content

Commit 0889dda

Browse files
committed
Disable in-band management for bridges before setting up controllers
Disabling in-band management for bridge will effectively disable it for all controllers which are or will be set for the bridge. This will prevent us from having short time between configuring controller and setting connection_mode of the controller to "out-of-band" when controller works in the default "in-band" connection mode and adds some hidden flows to the bridge. Closes-Bug: #1992953 Change-Id: Ibca81eb59fbfad71f223832228f408fb248c5dfa (cherry picked from commit 8fcf00a)
1 parent dd7fc47 commit 0889dda

File tree

4 files changed

+45
-52
lines changed

4 files changed

+45
-52
lines changed

neutron/agent/common/ovs_lib.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ def default_cookie(self):
260260
def set_agent_uuid_stamp(self, val):
261261
self._default_cookie = val
262262

263+
def disable_in_band(self):
264+
"""Disable in-band remote management for the bridge.
265+
266+
That configuration will apply to all controllers configured for the
267+
bridge.
268+
"""
269+
other_config = {
270+
'disable-in-band': 'true'}
271+
self.ovsdb.db_set(
272+
'Bridge', self.br_name,
273+
('other_config', other_config)).execute(check_error=True)
274+
263275
def set_controller(self, controllers):
264276
self.ovsdb.set_controller(self.br_name,
265277
controllers).execute(check_error=True)
@@ -754,13 +766,6 @@ def get_local_port_mac(self):
754766
msg = _('Unable to determine mac address for %s') % self.br_name
755767
raise Exception(msg)
756768

757-
def set_controllers_connection_mode(self, connection_mode):
758-
"""Set bridge controllers connection mode.
759-
760-
:param connection_mode: "out-of-band" or "in-band"
761-
"""
762-
self.set_controller_field('connection_mode', connection_mode)
763-
764769
def set_controllers_inactivity_probe(self, interval):
765770
"""Set bridge controllers inactivity probe interval.
766771

neutron/plugins/ml2/drivers/openvswitch/agent/openflow/native/ovs_bridge.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,8 @@ def _get_dp(self):
7373
self._cached_dpid = new_dpid
7474

7575
def setup_controllers(self, conf):
76-
url = ipv6_utils.valid_ipv6_url(conf.OVS.of_listen_address,
77-
conf.OVS.of_listen_port)
78-
controller = "tcp:" + url
79-
existing_controllers = self.get_controller()
80-
if controller not in existing_controllers:
81-
LOG.debug("Setting controller %s for bridge %s.",
82-
controller, self.br_name)
83-
self.set_controller([controller])
84-
85-
self.add_protocols(ovs_consts.OPENFLOW10, ovs_consts.OPENFLOW13)
86-
# NOTE(ivc): Force "out-of-band" controller connection mode (see
87-
# "In-Band Control" [1]).
76+
# NOTE(slaweq): Disable remote in-band management for all controllers
77+
# in the bridge
8878
#
8979
# By default openvswitch uses "in-band" controller connection mode
9080
# which adds hidden OpenFlow rules (only visible by issuing ovs-appctl
@@ -96,8 +86,26 @@ def setup_controllers(self, conf):
9686
# br-int and br-tun must be configured with the "out-of-band"
9787
# controller connection mode.
9888
#
89+
# Setting connection_mode for controllers should be done in single
90+
# transaction together with controllers setup but it will be easier to
91+
# disable in-band remote management for bridge which
92+
# effectively means that this configurations will applied to all
93+
# controllers in the bridge
94+
#
9995
# [1] https://github.com/openvswitch/ovs/blob/master/DESIGN.md
100-
self.set_controllers_connection_mode("out-of-band")
96+
# [2] https://bugzilla.redhat.com/show_bug.cgi?id=2134772
97+
self.disable_in_band()
98+
99+
url = ipv6_utils.valid_ipv6_url(conf.OVS.of_listen_address,
100+
conf.OVS.of_listen_port)
101+
controller = "tcp:" + url
102+
existing_controllers = self.get_controller()
103+
if controller not in existing_controllers:
104+
LOG.debug("Setting controller %s for bridge %s.",
105+
controller, self.br_name)
106+
self.set_controller([controller])
107+
108+
self.add_protocols(ovs_consts.OPENFLOW10, ovs_consts.OPENFLOW13)
101109
self.set_controllers_inactivity_probe(conf.OVS.of_inactivity_probe)
102110

103111
def drop_port(self, in_port):

neutron/tests/functional/agent/test_ovs_lib.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import collections
1717
from unittest import mock
18-
import uuid
1918

2019
from neutron_lib import constants as const
2120
from oslo_config import cfg
@@ -139,6 +138,15 @@ def test_controller_lifecycle(self):
139138
self.br.del_controller()
140139
self.assertEqual([], self.br.get_controller())
141140

141+
def test_disable_in_band(self):
142+
self.br.disable_in_band()
143+
br_other_config = self.ovs.ovsdb.db_find(
144+
'Bridge', ('name', '=', self.br.br_name), columns=['other_config']
145+
).execute()[0]['other_config']
146+
self.assertEqual(
147+
'true',
148+
br_other_config.get('disable-in-band', '').lower())
149+
142150
def test_non_index_queries(self):
143151
controllers = ['tcp:127.0.0.1:6633']
144152
self.br.set_controller(controllers)
@@ -394,33 +402,6 @@ def test_delete_ports(self):
394402
self.br.delete_ports(all_ports=True)
395403
self.assertEqual(len(self.br.get_port_name_list()), 0)
396404

397-
def test_set_controller_connection_mode(self):
398-
controllers = ['tcp:192.0.2.0:6633']
399-
self._set_controllers_connection_mode(controllers)
400-
401-
def test_set_multi_controllers_connection_mode(self):
402-
controllers = ['tcp:192.0.2.0:6633', 'tcp:192.0.2.1:55']
403-
self._set_controllers_connection_mode(controllers)
404-
405-
def _set_controllers_connection_mode(self, controllers):
406-
self.br.set_controller(controllers)
407-
self.assertEqual(sorted(controllers), sorted(self.br.get_controller()))
408-
self.br.set_controllers_connection_mode('out-of-band')
409-
self._assert_controllers_connection_mode('out-of-band')
410-
self.br.del_controller()
411-
self.assertEqual([], self.br.get_controller())
412-
413-
def _assert_controllers_connection_mode(self, connection_mode):
414-
controllers = self.br.db_get_val('Bridge', self.br.br_name,
415-
'controller')
416-
controllers = [controllers] if isinstance(
417-
controllers, uuid.UUID) else controllers
418-
for controller in controllers:
419-
self.assertEqual(connection_mode,
420-
self.br.db_get_val('Controller',
421-
controller,
422-
'connection_mode'))
423-
424405
def test_db_create_references(self):
425406
with self.ovs.ovsdb.transaction(check_error=True) as txn:
426407
queue = txn.add(self.ovs.ovsdb.db_create("Queue",

neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/native/ovs_bridge_test_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ def _test_setup_controllers(self, existing_controllers):
147147
m_set_controller = mock.patch.object(self.br, 'set_controller')
148148
m_set_probe = mock.patch.object(self.br,
149149
'set_controllers_inactivity_probe')
150-
m_set_ccm = mock.patch.object(self.br,
151-
'set_controllers_connection_mode')
150+
m_disable_in_band = mock.patch.object(self.br, 'disable_in_band')
152151

153-
with m_set_ccm as set_ccm, \
152+
with m_disable_in_band as disable_in_band, \
154153
m_add_protocols as add_protocols, \
155154
m_set_controller as set_controller, \
156155
m_get_controller as get_controller, \
@@ -163,7 +162,7 @@ def _test_setup_controllers(self, existing_controllers):
163162
set_controller.assert_not_called()
164163
else:
165164
set_controller.assert_called_once_with(["tcp:127.0.0.1:6633"])
166-
set_ccm.assert_called_once_with("out-of-band")
165+
disable_in_band.assert_called_once_with()
167166
add_protocols.assert_called_once_with(
168167
constants.OPENFLOW10, constants.OPENFLOW13)
169168

0 commit comments

Comments
 (0)