From: Ihar Hrachyshka Date: Wed, 29 Jul 2015 08:52:59 +0000 (+0200) Subject: Initialize ancillary_port_info dict as blank in OVS agent X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3b18aa3e1f4bb6d4d2f1264b37f8d784d57c4a28;p=openstack-build%2Fneutron-build.git Initialize ancillary_port_info dict as blank in OVS agent The first assignment of ancillary_port_info was from the scan_ancillary_ports function which could result in an exception and result in ancillary_port_info being unbound for the port stats scan below. This patch just initializes ancillary_port_info as an empty dict so the port stats will always have an input. Closes-Bug: #1479265 Change-Id: I37084bf27d4c328a7b78ca71cf26813207697361 --- 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 c830f0005..97cca3648 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -1520,6 +1520,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, ovs_restarted = False while self._check_and_handle_signal(): port_info = {} + ancillary_port_info = {} start = time.time() LOG.debug("Agent rpc_loop - iteration:%d started", self.iter_num) @@ -1628,8 +1629,6 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, # Put the ports back in self.updated_port self.updated_ports |= updated_ports_copy sync = True - ancillary_port_info = (ancillary_port_info if self.ancillary_brs - else {}) port_stats = self.get_port_stats(port_info, ancillary_port_info) self.loop_count_and_wait(start, port_stats) 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 26a9a30b8..e157ee235 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 @@ -2135,11 +2135,11 @@ class TestOvsDvrNeutronAgent(object): pass self.assertTrue(all([x.called for x in reset_mocks])) - def test_scan_ports_failure(self): + def _test_scan_ports_failure(self, scan_method_name): with mock.patch.object(self.agent, 'check_ovs_status', return_value=constants.OVS_RESTARTED),\ - mock.patch.object(self.agent, 'scan_ports', + mock.patch.object(self.agent, scan_method_name, side_effect=TypeError('broken')),\ mock.patch.object(self.agent, '_agent_has_updates', return_value=True),\ @@ -2152,6 +2152,15 @@ class TestOvsDvrNeutronAgent(object): self.agent.state_rpc = mock.Mock() self.agent.rpc_loop(polling_manager=mock.Mock()) + def test_scan_ports_failure(self): + self._test_scan_ports_failure('scan_ports') + + def test_scan_ancillary_ports_failure(self): + with mock.patch.object(self.agent, 'scan_ports'): + with mock.patch.object(self.agent, 'update_stale_ofport_rules'): + self.agent.ancillary_brs = mock.Mock() + self._test_scan_ports_failure('scan_ancillary_ports') + class TestOvsDvrNeutronAgentOFCtl(TestOvsDvrNeutronAgent, ovs_test_base.OVSOFCtlTestBase):