diff --git a/neutron/plugins/ml2/drivers/arista/mechanism_arista.py b/neutron/plugins/ml2/drivers/arista/mechanism_arista.py index 9d746bfb657..4bcf0e7e82c 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 e4d6175e712..cb4df15c9f4 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 @@ -320,6 +320,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), @@ -336,7 +337,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):