vmware-nsx/neutron/tests/unit/ml2/drivers/test_mech_mlnx.py
Irena Berezovsky 4a3a1bd2a2 Add update binding:profile with physical_network
Add temporary solution in order to support multiple physical networks
by mlnx ML2 MechanismDriver.
Due to non merged patches in nova that should support propagating
physical_network retrieved from port binding:profile attribute
to VIF/Network object.
The code will be removed once relevant nova patches are merged.
The code is disabled by default and should be enabled via
ml2_conf_mlnx.ini config file.

Change-Id: I815f9e28774efd47bccd1c57481e6ba89075792b
Closes-bug: #1291209
2014-03-19 10:08:09 +02:00

119 lines
4.5 KiB
Python

# Copyright (c) 2014 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo.config import cfg
from neutron.common import constants
from neutron.extensions import portbindings
from neutron.plugins.ml2 import driver_api as api
from neutron.plugins.ml2.drivers.mlnx import mech_mlnx
from neutron.tests.unit.ml2 import _test_mech_agent as base
class MlnxMechanismBaseTestCase(base.AgentMechanismBaseTestCase):
VIF_TYPE = portbindings.VIF_TYPE_MLNX_DIRECT
CAP_PORT_FILTER = False
AGENT_TYPE = constants.AGENT_TYPE_MLNX
GOOD_MAPPINGS = {'fake_physical_network': 'fake_bridge'}
GOOD_CONFIGS = {'interface_mappings': GOOD_MAPPINGS}
BAD_MAPPINGS = {'wrong_physical_network': 'wrong_bridge'}
BAD_CONFIGS = {'interface_mappings': BAD_MAPPINGS}
AGENTS = [{'alive': True,
'configurations': GOOD_CONFIGS}]
AGENTS_DEAD = [{'alive': False,
'configurations': GOOD_CONFIGS}]
AGENTS_BAD = [{'alive': False,
'configurations': GOOD_CONFIGS},
{'alive': True,
'configurations': BAD_CONFIGS}]
def setUp(self):
super(MlnxMechanismBaseTestCase, self).setUp()
self.driver = mech_mlnx.MlnxMechanismDriver()
self.driver.initialize()
class MlnxMechanismGenericTestCase(MlnxMechanismBaseTestCase,
base.AgentMechanismGenericTestCase):
pass
class MlnxMechanismLocalTestCase(MlnxMechanismBaseTestCase,
base.AgentMechanismLocalTestCase):
pass
class MlnxMechanismFlatTestCase(MlnxMechanismBaseTestCase,
base.AgentMechanismFlatTestCase):
pass
class MlnxMechanismVlanTestCase(MlnxMechanismBaseTestCase,
base.AgentMechanismVlanTestCase):
pass
class MlnxMechanismVnicTypeTestCase(MlnxMechanismBaseTestCase,
base.AgentMechanismVlanTestCase):
def _check_vif_type_for_vnic_type(self, vnic_type,
expected_vif_type):
context = base.FakePortContext(self.AGENT_TYPE,
self.AGENTS,
self.VLAN_SEGMENTS,
vnic_type)
self.driver.bind_port(context)
self.assertEqual(expected_vif_type, context._bound_vif_type)
def test_vnic_type_direct(self):
self._check_vif_type_for_vnic_type(portbindings.VNIC_DIRECT,
portbindings.VIF_TYPE_MLNX_HOSTDEV)
def test_vnic_type_macvtap(self):
self._check_vif_type_for_vnic_type(portbindings.VNIC_MACVTAP,
portbindings.VIF_TYPE_MLNX_DIRECT)
def test_vnic_type_normal(self):
self._check_vif_type_for_vnic_type(portbindings.VNIC_NORMAL,
self.VIF_TYPE)
class MlnxMechanismProfileTestCase(MlnxMechanismBaseTestCase):
def setUp(self):
cfg.CONF.set_override('apply_profile_patch', True, 'ESWITCH')
super(MlnxMechanismProfileTestCase, self).setUp()
def test_profile_contains_physical_net(self):
VLAN_SEGMENTS = [{api.ID: 'vlan_segment_id',
api.NETWORK_TYPE: 'vlan',
api.PHYSICAL_NETWORK: 'fake_physical_network',
api.SEGMENTATION_ID: 1234}]
context = base.FakePortContext(self.AGENT_TYPE,
self.AGENTS,
VLAN_SEGMENTS,
portbindings.VNIC_DIRECT)
context._binding = mock.Mock()
context._binding.profile = {}
segment = VLAN_SEGMENTS[0]
agent = self.AGENTS[0]
self.driver.try_to_bind_segment_for_agent(context, segment, agent)
self.assertEqual('{"physical_network": "fake_physical_network"}',
context._binding.profile)