]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Change function call order in ovs_neutron_agent.
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Tue, 3 Nov 2015 09:55:49 +0000 (09:55 +0000)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 4 Nov 2015 10:05:31 +0000 (10:05 +0000)
Change function call order in ovs_neutron_agent during the
creation or modification of a port, in order to fulfill the
VLAN OVS tag information in the "port" register before calling
the SG agent. This information is needed in some SG agent
implementations.

Closes-Bug: #1512636
Change-Id: I9813aca6443ac402b10b4cebf8be42416628b050

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

index 4ff2d23677991419bcbb9424ead68b931b6b1199..230fbb20dfa3543fd11ed275c0684c6c188f3409 100644 (file)
@@ -1509,6 +1509,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                                   "from server"), self.iter_num)
                 resync_a = True
 
+        # Ports are bound before calling the sg_agent setup. This function
+        # fulfill the information needed by the sg_agent setup.
+        self._bind_devices(need_binding_devices)
         # TODO(salv-orlando): Optimize avoiding applying filters
         # unnecessarily, (eg: when there are no IP address changes)
         added_ports = port_info.get('added', set())
@@ -1516,7 +1519,6 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
             added_ports -= set(security_disabled_ports)
         self.sg_agent.setup_port_filters(added_ports,
                                          port_info.get('updated', set()))
-        self._bind_devices(need_binding_devices)
 
         if 'removed' in port_info and port_info['removed']:
             start = time.time()
index 7838be8a88c09bff9ce7f8ac098628e5791c731b..322e4b921af4f31f74c47a1abda1f4476885d7fe 100644 (file)
@@ -425,6 +425,7 @@ class TestOvsNeutronAgent(object):
         devices_up = ['tap1']
         devices_down = ['tap2']
         self.agent.local_vlan_map["net1"] = mock.Mock()
+        self.agent.local_vlan_map["net1"].vlan = "1"
         ovs_db_list = [{'name': 'tap1', 'tag': []},
                        {'name': 'tap2', 'tag': []}]
         vif_port1 = mock.Mock()
@@ -451,6 +452,10 @@ class TestOvsNeutronAgent(object):
             update_devices.assert_called_once_with(mock.ANY, devices_up,
                                                    devices_down,
                                                    mock.ANY, mock.ANY)
+            set_db_attribute_calls = \
+                [mock.call.set_db_attribute("Port", "tap1", "tag", "1"),
+                 mock.call.set_db_attribute("Port", "tap2", "tag", "1")]
+            int_br.assert_has_calls(set_db_attribute_calls, any_order=True)
 
     def _test_arp_spoofing(self, enable_prevent_arp_spoofing):
         self.agent.prevent_arp_spoofing = enable_prevent_arp_spoofing
@@ -701,6 +706,32 @@ class TestOvsNeutronAgent(object):
             setup_port_filters.assert_called_once_with(
                 set(), port_info.get('updated', set()))
 
+    def test_process_network_ports_call_order(self):
+        port_info = {'current': set(['tap0', 'tap1']),
+                     'updated': set(['tap1']),
+                     'removed': set([]),
+                     'added': set(['eth1'])}
+        with mock.patch.object(self.agent, "treat_devices_added_or_updated",
+                return_value=([], ['tap1'], ['eth1'])) \
+                as treat_devices_added_or_updated, \
+                mock.patch.object(self.agent, "_bind_devices") \
+                as _bind_devices, \
+                mock.patch.object(self.agent.sg_agent, "setup_port_filters") \
+                as setup_port_filters:
+            parent = mock.MagicMock()
+            parent.attach_mock(treat_devices_added_or_updated,
+                               'treat_devices_added_or_updated')
+            parent.attach_mock(_bind_devices, '_bind_devices')
+            parent.attach_mock(setup_port_filters, 'setup_port_filters')
+            self.assertFalse(self.agent.process_network_ports(port_info,
+                                                              False))
+            expected_calls = [
+                mock.call.treat_devices_added_or_updated(
+                    set(['tap1', 'eth1']), False),
+                mock.call._bind_devices(['tap1']),
+                mock.call.setup_port_filters(set([]), set(['tap1']))]
+            parent.assert_has_calls(expected_calls, any_order=False)
+
     def test_report_state(self):
         with mock.patch.object(self.agent.state_rpc,
                                "report_state") as report_st: