From 581438a5b6dde5f161e1c129314a7bcaaae8da20 Mon Sep 17 00:00:00 2001 From: Sukhdev Kapur Date: Tue, 7 Jul 2015 19:39:15 -0700 Subject: [PATCH] Arista ML2 driver should ignore non-vlan networks Arista ML2 Mech driver for VLANs presently does not filter out non-vlan type networks (e.g vxlan). This fix will simply ignore the request if a non-vlan based network request is seen. Change-Id: I99ec5c5772a9f1f63cf871a98be50bdd2ba5db62 Closes-Bug: 1472458 --- .../plugins/ml2/drivers/arista/mechanism_arista.py | 14 ++++++++++++++ .../ml2/drivers/arista/test_mechanism_arista.py | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/drivers/arista/mechanism_arista.py b/neutron/plugins/ml2/drivers/arista/mechanism_arista.py index 9d746bfb6..4bcf0e7e8 100644 --- a/neutron/plugins/ml2/drivers/arista/mechanism_arista.py +++ b/neutron/plugins/ml2/drivers/arista/mechanism_arista.py @@ -22,6 +22,7 @@ from oslo_log import log as logging from neutron.common import constants as n_const from neutron.i18n import _LI +from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.common import exceptions as ml2_exc from neutron.plugins.ml2 import driver_api from neutron.plugins.ml2.drivers.arista import config # noqa @@ -69,6 +70,9 @@ class AristaDriver(driver_api.MechanismDriver): network = context.current segments = context.network_segments + if segments[0][driver_api.NETWORK_TYPE] != p_const.TYPE_VLAN: + # If network type is not VLAN, do nothing + return network_id = network['id'] tenant_id = network['tenant_id'] if not tenant_id: @@ -165,6 +169,10 @@ class AristaDriver(driver_api.MechanismDriver): def delete_network_postcommit(self, context): """Send network delete request to Arista HW.""" network = context.current + segments = context.network_segments + if segments[0][driver_api.NETWORK_TYPE] != p_const.TYPE_VLAN: + # If networtk type is not VLAN, do nothing + return network_id = network['id'] tenant_id = network['tenant_id'] if not tenant_id: @@ -202,6 +210,9 @@ class AristaDriver(driver_api.MechanismDriver): if not tenant_id: tenant_id = context._plugin_context.tenant_id with self.eos_sync_lock: + if not db_lib.is_network_provisioned(tenant_id, network_id): + # Ignore this request if network is not provisioned + return db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id) @@ -390,6 +401,9 @@ class AristaDriver(driver_api.MechanismDriver): device_owner = port['device_owner'] try: + if not db_lib.is_network_provisioned(tenant_id, network_id): + # If we do not have network associated with this, ignore it + return hostname = self._host_name(host) if device_owner == n_const.DEVICE_OWNER_DHCP: self.rpc.unplug_dhcp_port_from_network(device_id, diff --git a/neutron/tests/unit/plugins/ml2/drivers/arista/test_mechanism_arista.py b/neutron/tests/unit/plugins/ml2/drivers/arista/test_mechanism_arista.py index 57d507121..5fb194105 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/arista/test_mechanism_arista.py +++ b/neutron/tests/unit/plugins/ml2/drivers/arista/test_mechanism_arista.py @@ -321,6 +321,7 @@ class AristaDriverTestCase(testlib_api.SqlTestCase): network_id, tenant_id), mock.call.is_network_provisioned(tenant_id, network_id, segmentation_id), + mock.call.is_network_provisioned(tenant_id, network_id), mock.call.unplug_host_from_network(device_id, orig_host_id, port_id, network_id, tenant_id), mock.call.num_nets_provisioned(tenant_id), @@ -337,7 +338,8 @@ class AristaDriverTestCase(testlib_api.SqlTestCase): 'tenant_id': tenant_id, 'name': 'test-net', 'shared': shared} - network_segments = [{'segmentation_id': seg_id}] + network_segments = [{'segmentation_id': seg_id, + 'network_type': 'vlan'}] return FakeNetworkContext(network, network_segments, network) def _get_port_context(self, tenant_id, net_id, vm_id, network): -- 2.45.2