From 9c72bac0ea37971b2d5430246295c5e8b859b4ed Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Tue, 3 Nov 2015 09:55:49 +0000 Subject: [PATCH] Change function call order in ovs_neutron_agent. 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 --- .../openvswitch/agent/ovs_neutron_agent.py | 4 ++- .../agent/test_ovs_neutron_agent.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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 4ff2d2367..230fbb20d 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -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() 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 7838be8a8..322e4b921 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 @@ -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: -- 2.45.2