Treat MLAG pairs as a single physical network

With this change HPB is compatible with MLAG pairs by listing
them as peer1_peer2 in the physical network's name.

Change-Id: Idd86162b9d315c174c583f41be98b4e1a163eff5
Mitchell Jameson 6 years ago
parent eebed64795
commit 72ab612b49

@ -27,6 +27,9 @@ from oslo_utils import excutils
import requests
from six import add_metaclass
from neutron.db import api as db_api
from neutron.db.models.plugins.ml2 import vlanallocation
from networking_arista._i18n import _, _LI, _LW, _LE
from networking_arista.common import db_lib
from networking_arista.common import exceptions as arista_exc
@ -84,6 +87,21 @@ class AristaRPCWrapperBase(object):
self.security_group_driver = arista_sec_gp.AristaSecGroupSwitchDriver(
# We denote mlag_pair physnets as peer1_peer2 in the physnet name, the
# following builds a mapping of peer name to physnet name for use
# during port binding
self.mlag_pairs = {}
session = db_api.get_reader_session()
with session.begin():
physnets = session.query(
for (physnet,) in physnets:
if '_' in physnet:
peers = physnet.split('_')
self.mlag_pairs[peers[0]] = physnet
self.mlag_pairs[peers[1]] = physnet
# Indication of CVX availabililty in the driver.
self._cvx_available = True
@ -1989,6 +2007,10 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
if hostname:
switch_id = response[1]['hosts'][hostname]['name']
# Check if the switch is part of an MLAG pair, and lookup the
# pair's physnet name if so
physnet = self.mlag_pairs.get(physnet, physnet)
for k in response[1]['hosts']:
mac_to_hostname[response[1]['hosts'][k]['name']] = k

@ -273,7 +273,8 @@ class AristaDriver(driver_api.MechanismDriver):
mac_to_hostname = physnet_info.get('mac_to_hostname', {})
for link in link_info:
if link.get('switch_id') in mac_to_hostname:
return mac_to_hostname.get(link.get('switch_id'))
physnet = mac_to_hostname.get(link.get('switch_id'))
return self.rpc.mlag_pairs.get(physnet, physnet)
def _bind_port_to_baremetal(self, context, segment, physnet_info):

@ -1559,7 +1559,7 @@ class AristaRPCWrapperInvalidConfigTestCase(base.BaseTestCase):
arista_ml2.AristaRPCWrapperEapi, ndb)
class NegativeRPCWrapperTestCase(base.BaseTestCase):
class NegativeRPCWrapperTestCase(testlib_api.SqlTestCase):
"""Negative test cases to test the RPC between Arista Driver and EOS."""
def setUp(self):

@ -21,7 +21,6 @@ from oslo_config import cfg
from neutron.db import api as db_api
from neutron.db.models.plugins.ml2 import vlanallocation
from neutron.tests import base
from neutron.tests.unit import testlib_api
from networking_arista.ml2.drivers.driver_helpers import VlanSyncService
@ -33,7 +32,7 @@ EAPI_SEND_FUNC = ('networking_arista.ml2.arista_ml2.AristaRPCWrapperEapi'
class AristaTypeDriverTest(base.BaseTestCase):
class AristaTypeDriverTest(testlib_api.SqlTestCase):
def setUp(self):
super(AristaTypeDriverTest, self).setUp()