diff --git a/networking_arista/tests/unit/ml2/mechanism_ha_simulator.py b/networking_arista/tests/unit/ml2/mechanism_ha_simulator.py index b0cd0b26..14fa765e 100644 --- a/networking_arista/tests/unit/ml2/mechanism_ha_simulator.py +++ b/networking_arista/tests/unit/ml2/mechanism_ha_simulator.py @@ -16,6 +16,14 @@ from multiprocessing import Queue import random +from neutron.agent import rpc as agent_rpc +from neutron_lib.agent import topics +from neutron_lib.api.definitions import portbindings +from neutron_lib.callbacks import events +from neutron_lib.callbacks import registry +from neutron_lib.callbacks import resources +from neutron_lib import context + from networking_arista.ml2 import arista_sync from networking_arista.ml2.mechanism_arista import AristaDriver @@ -58,3 +66,34 @@ class AristaHASimulationDriver(AristaDriver): def delete_port_postcommit(self, context): self.provision_queue = random.choice(self.provision_queues) super(AristaHASimulationDriver, self).delete_port_postcommit(context) + + +class AristaHAScaleSimulationDriver(AristaHASimulationDriver): + + def __init__(self): + super(AristaHAScaleSimulationDriver, self).__init__() + self.context = None + self.plugin_rpc = None + + def initialize(self): + super(AristaHAScaleSimulationDriver, self).initialize() + self.context = context.get_admin_context_without_session() + # Subscribe to port updates to force ports to active after binding + # since a fake virt driver is being used, so OVS will never see + # the libvirt interfaces come up, triggering the OVS provisioning + self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN) + registry.subscribe(self._port_update_callback, + resources.PORT, events.AFTER_UPDATE) + + def _port_update_callback(self, resource, event, trigger, **kwargs): + port = kwargs.get('port') + host = port.get(portbindings.HOST_ID) + vif_type = port.get(portbindings.VIF_TYPE) + device_dict = {'device': port['id'], + 'agent_id': 'ovs-agent-%s' % host, + 'host': host} + if vif_type == 'ovs': + self.plugin_rpc.update_device_up(self.context, **device_dict) + elif (port.get(portbindings.VNIC_TYPE) == 'normal' + and vif_type == 'unbound'): + self.plugin_rpc.update_device_down(self.context, **device_dict) diff --git a/setup.cfg b/setup.cfg index 8ef4dc14..0c656706 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,7 @@ neutron.ml2.mechanism_drivers = arista_ml2 = networking_arista.ml2.mechanism_arista:AristaDriver arista_test_fabric = networking_arista.tests.unit.ml2.mechanism_fabric:TestFabricDriver arista_ha_sim = networking_arista.tests.unit.ml2.mechanism_ha_simulator:AristaHASimulationDriver + arista_ha_scale_sim = networking_arista.tests.unit.ml2.mechanism_ha_simulator:AristaHAScaleSimulationDriver neutron.service_plugins = arista_l3 = networking_arista.l3Plugin.l3_arista:AristaL3ServicePlugin arista_security_group = networking_arista.ml2.security_groups.arista_security_groups:AristaSecurityGroupHandler