From: Kevin Benton Date: Tue, 28 Jul 2015 23:15:34 +0000 (-0700) Subject: Initialize port_info dict as blank in OVS agent X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4021fe30a915c5478d1053b08e693c7f5c6270f4;p=openstack-build%2Fneutron-build.git Initialize port_info dict as blank in OVS agent 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 --- diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index fe9f8a15b..7eaa7a3eb 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -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) diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 9aaa3132f..5a07d0d26 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -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):