]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Initialize ancillary_port_info dict as blank in OVS agent
authorIhar Hrachyshka <ihrachys@redhat.com>
Wed, 29 Jul 2015 08:52:59 +0000 (10:52 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Wed, 5 Aug 2015 18:51:09 +0000 (18:51 +0000)
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

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

index c830f0005186da9fd7182f93f069803baac3e43a..97cca36485e7a5ae38ccba8b57c2d70c921d3b9d 100644 (file)
@@ -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)
 
index 26a9a30b8f8333272d0962de7e58da5ee727acbf..e157ee235032a6f3fd4231d4171b3918c057ea8d 100644 (file)
@@ -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):