]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Handle errors from run_ofctl() when dumping flows
authorKyle Mestery <kmestery@cisco.com>
Thu, 29 May 2014 13:07:55 +0000 (13:07 +0000)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:55 +0000 (23:06 +0800)
The function dump_flows_for_table() calls run_ofctl(). If this occurs during an OVS
restart, run_ofctl() will return None. dump_flows_for_table() needs to realize this
and not try to call splitlines() on a None object.

Change-Id: Ide26028656e634113f955dfc89569149d4d5b306
Closes-Bug: #1324659
(cherry picked from commit b5d596877f538a84e8336b45026b552df8e53be6)

neutron/agent/linux/ovs_lib.py
neutron/tests/unit/openvswitch/test_ovs_lib.py

index a8bb12d250ec6c0bf883358ea592951cf91b3e7e..de0162cd1d217efcce81dfb0afa470dcb1cb68b6 100644 (file)
@@ -202,10 +202,12 @@ class OVSBridge(BaseOVS):
             self.run_ofctl("del-flows", [flow_expr_str])
 
     def dump_flows_for_table(self, table):
+        retval = None
         flow_str = "table=%s" % table
         flows = self.run_ofctl("dump-flows", [flow_str])
-        retval = '\n'.join(item for item in flows.splitlines()
-                           if 'NXST' not in item)
+        if flows:
+            retval = '\n'.join(item for item in flows.splitlines()
+                               if 'NXST' not in item)
         return retval
 
     def defer_apply_on(self):
index 7b7d9d167bce763b3cf4c8ceebcebdf51bec31e2..dbf155b7b35b41a4ba209de6dd62ef3f43f38fe1 100644 (file)
@@ -361,6 +361,34 @@ class OVS_Lib_Test(base.BaseTestCase):
                           self.br.delete_flows,
                           **params)
 
+    def test_dump_flows(self):
+        table = 23
+        nxst_flow = "NXST_FLOW reply (xid=0x4):"
+        flows = "\n".join([" cookie=0x0, duration=18042.514s, table=0, "
+                           "n_packets=6, n_bytes=468, "
+                           "priority=2,in_port=1 actions=drop",
+                           " cookie=0x0, duration=18027.562s, table=0, "
+                           "n_packets=0, n_bytes=0, "
+                           "priority=3,in_port=1,dl_vlan=100 "
+                           "actions=mod_vlan_vid:1,NORMAL",
+                           " cookie=0x0, duration=18044.351s, table=0, "
+                           "n_packets=9, n_bytes=594, priority=1 "
+                           "actions=NORMAL", " cookie=0x0, "
+                           "duration=18044.211s, table=23, n_packets=0, "
+                           "n_bytes=0, priority=0 actions=drop"])
+        flow_args = '\n'.join([nxst_flow, flows])
+        run_ofctl = mock.patch.object(self.br, 'run_ofctl').start()
+        run_ofctl.side_effect = [flow_args]
+        retflows = self.br.dump_flows_for_table(table)
+        self.assertEqual(flows, retflows)
+
+    def test_dump_flows_ovs_dead(self):
+        table = 23
+        run_ofctl = mock.patch.object(self.br, 'run_ofctl').start()
+        run_ofctl.side_effect = ['']
+        retflows = self.br.dump_flows_for_table(table)
+        self.assertEqual(None, retflows)
+
     def test_mod_flow_with_priority_set(self):
         params = {'in_port': '1',
                   'priority': '1'}