Cisco plugin should check for switch - vlan bindings
This commit fixes the issue where the Cisco plugin tries to create a vlan twice on a switch if the first create is not bound to a port. Also fixes an issue where the plugin tried to untrunk vlans from a port for SVI interfaces. Change-Id: Ifb13eb65d667367cffe120e1761d34f09b6d356d Fixes: Bug #1233300
This commit is contained in:
parent
cb7fee0813
commit
26290eae23
@ -103,6 +103,17 @@ class NexusPlugin(L2DevicePluginBase):
|
|||||||
vlan_created = False
|
vlan_created = False
|
||||||
vlan_trunked = False
|
vlan_trunked = False
|
||||||
eport_id = '%s:%s' % (etype, port_id)
|
eport_id = '%s:%s' % (etype, port_id)
|
||||||
|
# Check for switch vlan bindings
|
||||||
|
try:
|
||||||
|
# This vlan has already been created on this switch
|
||||||
|
# via another operation, like SVI bindings.
|
||||||
|
nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
|
||||||
|
vlan_created = True
|
||||||
|
auto_create = False
|
||||||
|
except cisco_exc.NexusPortBindingNotFound:
|
||||||
|
# No changes, proceed as normal
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nxos_db.get_port_vlan_switch_binding(eport_id, vlan_id,
|
nxos_db.get_port_vlan_switch_binding(eport_id, vlan_id,
|
||||||
switch_ip)
|
switch_ip)
|
||||||
@ -282,6 +293,7 @@ class NexusPlugin(L2DevicePluginBase):
|
|||||||
etype, nexus_port = '', ''
|
etype, nexus_port = '', ''
|
||||||
if row['port_id'] == 'router':
|
if row['port_id'] == 'router':
|
||||||
etype, nexus_port = 'vlan', row['port_id']
|
etype, nexus_port = 'vlan', row['port_id']
|
||||||
|
auto_untrunk = False
|
||||||
else:
|
else:
|
||||||
etype, nexus_port = row['port_id'].split(':')
|
etype, nexus_port = row['port_id'].split(':')
|
||||||
|
|
||||||
|
@ -141,9 +141,9 @@ class TestCiscoNexusPlugin(base.BaseTestCase):
|
|||||||
db.configure_db()
|
db.configure_db()
|
||||||
|
|
||||||
# Use a mock netconf client
|
# Use a mock netconf client
|
||||||
mock_ncclient = mock.Mock()
|
self.mock_ncclient = mock.Mock()
|
||||||
self.patch_obj = mock.patch.dict('sys.modules',
|
self.patch_obj = mock.patch.dict('sys.modules',
|
||||||
{'ncclient': mock_ncclient})
|
{'ncclient': self.mock_ncclient})
|
||||||
self.patch_obj.start()
|
self.patch_obj.start()
|
||||||
|
|
||||||
with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin,
|
with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin,
|
||||||
@ -261,8 +261,45 @@ class TestCiscoNexusPlugin(base.BaseTestCase):
|
|||||||
subnet_id,
|
subnet_id,
|
||||||
gateway_ip,
|
gateway_ip,
|
||||||
router_id)
|
router_id)
|
||||||
|
try:
|
||||||
|
self.assertRaises(
|
||||||
|
cisco_exc.SubnetInterfacePresent,
|
||||||
|
self._cisco_nexus_plugin.add_router_interface,
|
||||||
|
vlan_name, vlan_id, subnet_id, gateway_ip, router_id)
|
||||||
|
finally:
|
||||||
|
self._cisco_nexus_plugin.remove_router_interface(vlan_id,
|
||||||
|
router_id)
|
||||||
|
|
||||||
self.assertRaises(
|
def test_nexus_add_port_after_router_interface(self):
|
||||||
cisco_exc.SubnetInterfacePresent,
|
"""Tests creating a port after a router interface.
|
||||||
self._cisco_nexus_plugin.add_router_interface,
|
|
||||||
vlan_name, vlan_id, subnet_id, gateway_ip, router_id)
|
Test creating a port after an SVI router interface has
|
||||||
|
been created. Only a trunk call should be invoked and the
|
||||||
|
plugin should not attempt to recreate the vlan.
|
||||||
|
"""
|
||||||
|
vlan_name = self.vlan_name
|
||||||
|
vlan_id = self.vlan_id
|
||||||
|
gateway_ip = '10.0.0.1/24'
|
||||||
|
router_id = '00000R1'
|
||||||
|
subnet_id = '00001'
|
||||||
|
|
||||||
|
self._cisco_nexus_plugin.add_router_interface(vlan_name,
|
||||||
|
vlan_id,
|
||||||
|
subnet_id,
|
||||||
|
gateway_ip,
|
||||||
|
router_id)
|
||||||
|
# Create a network on the switch
|
||||||
|
self._cisco_nexus_plugin.create_network(
|
||||||
|
self.network1, self.attachment1)
|
||||||
|
|
||||||
|
# Grab a list of all mock calls from ncclient
|
||||||
|
last_cfgs = (self.mock_ncclient.manager.connect().
|
||||||
|
edit_config.mock_calls)
|
||||||
|
|
||||||
|
# The last ncclient call should be for trunking and the second
|
||||||
|
# to last call should be creating the SVI interface
|
||||||
|
last_cfg = last_cfgs[-1][2]['config']
|
||||||
|
self.assertIn('allowed', last_cfg)
|
||||||
|
|
||||||
|
slast_cfg = last_cfgs[-2][2]['config']
|
||||||
|
self.assertIn('10.0.0.1/24', slast_cfg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user