]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix ovs agent restore local_vlan_map failed
authorshihanzhang <shihanzhang@huawei.com>
Tue, 26 May 2015 01:29:58 +0000 (09:29 +0800)
committershihanzhang <shihanzhang@huawei.com>
Fri, 29 May 2015 04:11:51 +0000 (12:11 +0800)
when ovs agent restart, it will restore the local_vlan_map, but in
some condition, if a device does not be set tag in ovsdb, the function
'db_get_val("Port", port.port_name, "tag")' will return a empty list,
it does not need 'provision_local_vlan' for this device.

Change-Id: I70ed30e6ea5d13e6f14bb41c957320cc21dbca1b
Closes-bug: #1458709

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

index cb3d44827c1c290350f5eb84a6362d31f50f30fc..003cbdf06d34dbb626be0f2f64bdd749e9eee4e7 100644 (file)
@@ -300,6 +300,8 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
             local_vlan_map = self.int_br.db_get_val("Port", port.port_name,
                                                     "other_config")
             local_vlan = self.int_br.db_get_val("Port", port.port_name, "tag")
+            if not local_vlan:
+                continue
             net_uuid = local_vlan_map.get('net_uuid')
             if (net_uuid and net_uuid not in self.local_vlan_map
                 and local_vlan != DEAD_VLAN_TAG):
index fb068790c3578b614ea5ff037b8f1e2725031375..af4c5496b58c0cb71b78b2619019ab3fdf2cf56e 100644 (file)
@@ -159,6 +159,30 @@ class TestOvsNeutronAgent(object):
         int_br.set_db_attribute.assert_called_once_with(
             "Port", mock.ANY, "other_config", vlan_mapping)
 
+    def _test_restore_local_vlan_maps(self, tag):
+        port = mock.Mock()
+        port.port_name = 'fake_port'
+        local_vlan_map = {'net_uuid': 'fake_network_id',
+                          'network_type': 'vlan',
+                          'physical_network': 'fake_network',
+                          'segmentation_id': 1}
+        with mock.patch.object(self.agent, 'int_br') as int_br, \
+            mock.patch.object(self.agent, 'provision_local_vlan') as \
+                provision_local_vlan:
+            int_br.get_vif_ports.return_value = [port]
+            int_br.db_get_val.side_effect = [local_vlan_map, tag]
+            self.agent._restore_local_vlan_map()
+            if tag:
+                self.assertTrue(provision_local_vlan.called)
+            else:
+                self.assertFalse(provision_local_vlan.called)
+
+    def test_restore_local_vlan_map_with_device_has_tag(self):
+        self._test_restore_local_vlan_maps(2)
+
+    def test_restore_local_vlan_map_with_device_no_tag(self):
+        self._test_restore_local_vlan_maps([])
+
     def test_check_agent_configurations_for_dvr_raises(self):
         self.agent.enable_distributed_routing = True
         self.agent.enable_tunneling = True