Merge "Treat MLAG pairs as a single physical network"

This commit is contained in:
Jenkins 2017-05-30 13:38:01 +00:00 committed by Gerrit Code Review
commit fc46b04ad7
4 changed files with 26 additions and 4 deletions

View File

@ -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(
self._ndb)
# 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(
vlanallocation.VlanAllocation.physical_network
).distinct().all()
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

View File

@ -271,7 +271,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):

View File

@ -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):

View File

@ -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'
'._send_eapi_req')
class AristaTypeDriverTest(base.BaseTestCase):
class AristaTypeDriverTest(testlib_api.SqlTestCase):
def setUp(self):
super(AristaTypeDriverTest, self).setUp()