]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Initialize port_info dict as blank in OVS agent
authorKevin Benton <blak111@gmail.com>
Tue, 28 Jul 2015 23:15:34 +0000 (16:15 -0700)
committerKevin Benton <blak111@gmail.com>
Fri, 31 Jul 2015 10:02:28 +0000 (04:02 -0600)
The first assignment of port_info was from the scan_ports function
which could result in an exception and result in port_info being
unbound for the port stats scan below.

This patch just initializes port_info as an empty dict so the port
stats will always have an input.

Closes-Bug: #1479105
Change-Id: I017a6dd334e2673072c977cc13b73e8cceb16712

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py

index fe9f8a15b4108b147b3dc9488257b035f613bf76..7eaa7a3ebca3eb4350c6baa9bab23284686dd1ac 100644 (file)
@@ -1516,6 +1516,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         tunnel_sync = True
         ovs_restarted = False
         while self._check_and_handle_signal():
+            port_info = {}
             start = time.time()
             LOG.debug("Agent rpc_loop - iteration:%d started",
                       self.iter_num)
index 9aaa3132f190a314344eabe77899ee5216bc4b7f..5a07d0d2625a040bea0ac2f03f9529f7990488b6 100644 (file)
@@ -2104,6 +2104,23 @@ class TestOvsDvrNeutronAgent(object):
                 pass
         self.assertTrue(all([x.called for x in reset_mocks]))
 
+    def test_scan_ports_failure(self):
+        with mock.patch.object(self.agent,
+                               'check_ovs_status',
+                               return_value=constants.OVS_RESTARTED),\
+                mock.patch.object(self.agent, 'scan_ports',
+                               side_effect=TypeError('broken')),\
+                mock.patch.object(self.agent, '_agent_has_updates',
+                                  return_value=True),\
+                mock.patch.object(self.agent, '_check_and_handle_signal',
+                                  side_effect=[True, False]):
+            # block RPC calls and bridge calls
+            self.agent.setup_physical_bridges = mock.Mock()
+            self.agent.setup_integration_br = mock.Mock()
+            self.agent.reset_tunnel_br = mock.Mock()
+            self.agent.state_rpc = mock.Mock()
+            self.agent.rpc_loop(polling_manager=mock.Mock())
+
 
 class TestOvsDvrNeutronAgentOFCtl(TestOvsDvrNeutronAgent,
                                   ovs_test_base.OVSOFCtlTestBase):