get_standard_device_mappings for mechdriver

get_mappings for machanism drivers return back different dicts for
different mechanism drivers. By adding get_standard_device_mappings
method SRIOV and OVS mechanism drivers can return a mapping dict in a
form like this one:
{'physnet_name': ['device_or_bridge_1', 'device_or_bridge_2']}

Change-Id: Ieddd9b3a4f3d7269aafc373f040c55b025f5c201
Related-Bug: #1578989
This commit is contained in:
Lajos Katona 2018-09-20 16:54:19 +02:00
parent 462b510c50
commit 97c9c4656d
5 changed files with 75 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from oslo_config import cfg
from oslo_log import log
from neutron._i18n import _
from neutron.conf.plugins.ml2.drivers.mech_sriov import mech_sriov_conf
from neutron.plugins.ml2.drivers import mech_agent
from neutron.plugins.ml2.drivers.mech_sriov.mech_driver \
@ -89,6 +90,23 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
def get_mappings(self, agent):
return agent['configurations'].get('device_mappings', {})
def get_standard_device_mappings(self, agent):
"""Return the agent's device mappings in a standard way.
The common format for OVS and SRIOv mechanism drivers:
{'physnet_name': ['device_or_bridge_1', 'device_or_bridge_2']}
:param agent: The agent
:returns A dict in the format: {'physnet_name': ['bridge_or_device']}
:raises ValueError: if there is no device_mappings key in
agent['configurations']
"""
if 'device_mappings' in agent['configurations']:
return agent['configurations']['device_mappings']
else:
raise ValueError(_('Cannot standardize device mappings of agent '
'type: %s'), agent['agent_type'])
def bind_port(self, context):
LOG.debug("Attempting to bind port %(port)s on "
"network %(network)s",

View File

@ -23,6 +23,7 @@ from neutron_lib import constants
from oslo_config import cfg
from oslo_log import log
from neutron._i18n import _
from neutron.agent import securitygroups_rpc
from neutron.conf.plugins.ml2.drivers.openvswitch import mech_ovs_conf
from neutron.plugins.ml2.drivers import mech_agent
@ -90,6 +91,24 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
def get_mappings(self, agent):
return agent['configurations'].get('bridge_mappings', {})
def get_standard_device_mappings(self, agent):
"""Return the agent's bridge mappings in a standard way.
The common format for OVS and SRIOv mechanism drivers:
{'physnet_name': ['device_or_bridge_1', 'device_or_bridge_2']}
:param agent: The agent
:returns A dict in the format: {'physnet_name': ['bridge_or_device']}
:raises ValueError: if there is no bridge_mappings key in
agent['configurations']
"""
if 'bridge_mappings' in agent['configurations']:
return {k: [v] for k, v in
agent['configurations']['bridge_mappings'].items()}
else:
raise ValueError(_('Cannot standardize bridge mappings of agent '
'type: %s'), agent['agent_type'])
def check_vlan_transparency(self, context):
"""Currently Openvswitch driver doesn't support vlan transparency."""
return False

View File

@ -270,3 +270,16 @@ class SriovSwitchMechVnicTypesTestCase(SriovNicSwitchMechanismBaseTestCase):
self.assertRaises(ValueError,
mech_driver.SriovNicSwitchMechanismDriver)
class SriovSwitchDeviceMappingsTestCase(SriovNicSwitchMechanismBaseTestCase):
def test_standard_device_mappings(self):
mappings = self.driver.get_standard_device_mappings(self.AGENTS[0])
self.assertDictEqual(self.GOOD_CONFIGS['device_mappings'], mappings)
def test_standard_device_mappings_negative(self):
fake_agent = {'agent_type': constants.AGENT_TYPE_NIC_SWITCH,
'configurations': {}}
self.assertRaises(ValueError, self.driver.get_standard_device_mappings,
fake_agent)

View File

@ -355,3 +355,21 @@ class OpenvswitchMechVnicTypesTestCase(OpenvswitchMechanismBaseTestCase):
self.assertRaises(ValueError,
mech_openvswitch.OpenvswitchMechanismDriver)
class OpenvswitchMechDeviceMappingsTestCase(OpenvswitchMechanismBaseTestCase):
def test_standard_device_mappings(self):
mappings = self.driver.get_standard_device_mappings(self.AGENTS[0])
self.assertEqual(
len(self.GOOD_CONFIGS['bridge_mappings']),
len(mappings))
for ph_orig, br_orig in self.GOOD_CONFIGS['bridge_mappings'].items():
self.assertIn(ph_orig, mappings)
self.assertEqual([br_orig], mappings[ph_orig])
def test_standard_device_mappings_negative(self):
fake_agent = {'agent_type': constants.AGENT_TYPE_OVS,
'configurations': {}}
self.assertRaises(ValueError, self.driver.get_standard_device_mappings,
fake_agent)

View File

@ -0,0 +1,7 @@
---
features:
- |
Add get_standard_device_mappings to SriovNicSwitchMechanismDriver and
OpenvswitchMechanismDriver so they can return the interface or bridge
mappings in a standard way. The common format is a dict like:
{'physnet_name': ['device_or_bridge_1', 'device_or_bridge_2']}.