Without that fix flows applied to br-tun through
DeferredOVSBridge are created without cookie.
That results in l2pop flows being deleted in the process of
cleanup of stale flows.
Solution is to add cookie to all add/mod-flows of OVSBrigde
class in the method do_action_flows.
Also, agent_uuid_stamp moved to a proper place - into the
base OVSBridge class as storing attributes in Mixing was
just a wrong code design.
Change-Id: Ic09a0dbc04fc5da38d30e1392cf2ea27d576040c
Closes-Bug: #
1489372
super(OVSBridge, self).__init__()
self.br_name = br_name
self.datapath_type = datapath_type
+ self.agent_uuid_stamp = '0x0'
+
+ def set_agent_uuid_stamp(self, val):
+ self.agent_uuid_stamp = val
def set_controller(self, controllers):
self.ovsdb.set_controller(self.br_name,
self.br_name, 'datapath_id')
def do_action_flows(self, action, kwargs_list):
+ if action != 'del':
+ for kw in kwargs_list:
+ if 'cookie' not in kw:
+ kw['cookie'] = self.agent_uuid_stamp
flow_strs = [_build_flow_expr_str(kw, action) for kw in kwargs_list]
self.run_ofctl('%s-flows' % action, ['-'], '\n'.join(flow_strs))
class OpenFlowSwitchMixin(object):
"""Mixin to provide common convenient routines for an openflow switch."""
- agent_uuid_stamp = '0x0'
-
- def set_agent_uuid_stamp(self, val):
- self.agent_uuid_stamp = val
@staticmethod
def _conv_args(kwargs):
else:
super(OpenFlowSwitchMixin, self).remove_all_flows()
- def add_flow(self, **kwargs):
- kwargs['cookie'] = self.agent_uuid_stamp
- super(OpenFlowSwitchMixin, self).add_flow(**self._conv_args(kwargs))
-
- def mod_flow(self, **kwargs):
- kwargs['cookie'] = self.agent_uuid_stamp
- super(OpenFlowSwitchMixin, self).mod_flow(**self._conv_args(kwargs))
-
def _filter_flows(self, flows):
LOG.debug("Agent uuid stamp used to filter flows: %s",
self.agent_uuid_stamp)
def test_getattr_unallowed_attr_failure(self):
with ovs_lib.DeferredOVSBridge(self.br) as deferred_br:
self.assertRaises(AttributeError, getattr, deferred_br, 'failure')
+
+ def test_cookie_passed_to_addmod(self):
+ self.br = ovs_lib.OVSBridge("br-tun")
+ self.br.set_agent_uuid_stamp(1234)
+ expected_calls = [
+ mock.call('add-flows', ['-'],
+ 'hard_timeout=0,idle_timeout=0,priority=1,'
+ 'cookie=1234,actions=drop'),
+ mock.call('mod-flows', ['-'],
+ 'cookie=1234,actions=drop')
+ ]
+ with mock.patch.object(self.br, 'run_ofctl') as f:
+ with ovs_lib.DeferredOVSBridge(self.br) as deferred_br:
+ deferred_br.add_flow(actions='drop')
+ deferred_br.mod_flow(actions='drop')
+ f.assert_has_calls(expected_calls)