Adding the Nexus support to the Persistence Framwork

Modification of the Nexus Unit Case to be running with Persistence Framework
pep8 passed
pylint 8.81/10
This commit is contained in:
Edgar Magana 2011-08-19 10:13:53 -07:00
parent 84d0f0a4f7
commit ea89f12338
6 changed files with 33 additions and 16 deletions

View File

@ -118,9 +118,10 @@ nexus_plugin=quantum.plugins.cisco.nexus.cisco_nexus_plugin.NexusPlugin
# This will be the address at which Quantum sends and receives configuration
# information via SSHv2.
nexus_ip_address=10.0.0.1
# Port number on the Nexus switch to which the UCSM 6120 is connected
# Use shortened interface syntax, e.g. "3/23" not "Ethernet3/23".
nexus_port=3/23
# Port numbers on the Nexus switch to each one of the UCSM 6120s is connected
# Use shortened interface syntax, e.g. "1/10" not "Ethernet1/10".
nexus_first_port=1/10
nexus_second_port=1/11
#Port number where the SSH will be running at Nexus Switch, e.g.: 22 (Default)
nexus_ssh_port=22

View File

@ -1,8 +1,9 @@
[SWITCH]
# Change the following to reflect the Nexus switch details
nexus_ip_address=<put_nexus_switch_ip_address_here>
#Port number of the Interface connected from the Nexus 7K Switch to UCSM 6120, e.g.: 3/23
nexus_port=<put_interface_name_here>
#Interfaces connected from the Nexus 7K Switch to the two UCSM 6120s, e.g.: 1/10 and 1/11
nexus_first_port=<put_interface_name_here>
nexus_second_port=<put_interface_name_here>
#Port number where the SSH will be running at the Nexus Switch, e.g.: 22 (Default)
nexus_ssh_port=22

View File

@ -33,7 +33,8 @@ CP = confp.CiscoConfigParser(os.path.dirname(os.path.realpath(__file__)) \
SECTION = CP['SWITCH']
NEXUS_IP_ADDRESS = SECTION['nexus_ip_address']
NEXUS_PORT = SECTION['nexus_port']
NEXUS_FIRST_PORT = SECTION['nexus_first_port']
NEXUS_SECOND_PORT = SECTION['nexus_second_port']
NEXUS_SSH_PORT = SECTION['nexus_ssh_port']
SECTION = CP['DRIVER']

View File

@ -103,7 +103,8 @@ class CiscoNEXUSDriver():
mgr.edit_config(target='running', config=confstr)
def create_vlan(self, vlan_name, vlan_id, nexus_host, nexus_user,
nexus_password, nexus_interface, nexus_ssh_port):
nexus_password, nexus_first_interface,
nexus_second_interface, nexus_ssh_port):
"""
Creates a VLAN and Enable on trunk mode an interface on Nexus Switch
given the VLAN ID and Name and Interface Number
@ -111,10 +112,12 @@ class CiscoNEXUSDriver():
with self.nxos_connect(nexus_host, int(nexus_ssh_port), nexus_user,
nexus_password) as man:
self.enable_vlan(man, vlan_id, vlan_name)
self.enable_vlan_on_trunk_int(man, nexus_interface, vlan_id)
self.enable_vlan_on_trunk_int(man, nexus_first_interface, vlan_id)
self.enable_vlan_on_trunk_int(man, nexus_second_interface, vlan_id)
def delete_vlan(self, vlan_id, nexus_host, nexus_user,
nexus_password, nexus_interface, nexus_ssh_port):
def delete_vlan(self, vlan_id, nexus_host, nexus_user, nexus_password,
nexus_first_interface, nexus_second_interface,
nexus_ssh_port):
"""
Delete a VLAN and Disables trunk mode an interface on Nexus Switch
given the VLAN ID and Interface Number
@ -122,4 +125,5 @@ class CiscoNEXUSDriver():
with self.nxos_connect(nexus_host, int(nexus_ssh_port), nexus_user,
nexus_password) as man:
self.disable_vlan(man, vlan_id)
self.disable_switch_port(man, nexus_interface)
self.disable_switch_port(man, nexus_first_interface)
self.disable_switch_port(man, nexus_second_interface)

View File

@ -28,6 +28,7 @@ from quantum.plugins.cisco.common import cisco_constants as const
from quantum.plugins.cisco.common import cisco_credentials as cred
from quantum.plugins.cisco.l2device_plugin_base import L2DevicePluginBase
from quantum.plugins.cisco.nexus import cisco_nexus_configuration as conf
from quantum.plugins.cisco.db import nexus_db as nxos_db
LOG.basicConfig(level=LOG.WARN)
LOG.getLogger(const.LOGGER_COMPONENT_NAME)
@ -48,7 +49,8 @@ class NexusPlugin(L2DevicePluginBase):
self._nexus_ip = conf.NEXUS_IP_ADDRESS
self._nexus_username = cred.Store.getUsername(conf.NEXUS_IP_ADDRESS)
self._nexus_password = cred.Store.getPassword(conf.NEXUS_IP_ADDRESS)
self._nexus_port = conf.NEXUS_PORT
self._nexus_first_port = conf.NEXUS_FIRST_PORT
self._nexus_second_port = conf.NEXUS_SECOND_PORT
self._nexus_ssh_port = conf.NEXUS_SSH_PORT
def get_all_networks(self, tenant_id):
@ -68,8 +70,11 @@ class NexusPlugin(L2DevicePluginBase):
"""
LOG.debug("NexusPlugin:create_network() called\n")
self._client.create_vlan(vlan_name, str(vlan_id), self._nexus_ip,
self._nexus_username, self._nexus_password, self._nexus_port,
self._nexus_username, self._nexus_password,
self._nexus_first_port, self._nexus_second_port,
self._nexus_ssh_port)
nxos_db.add_nexusport_binding(self._nexus_first_port, str(vlan_id))
nxos_db.add_nexusport_binding(self._nexus_second_port, str(vlan_id))
new_net_dict = {const.NET_ID: net_id,
const.NET_NAME: net_name,
@ -85,11 +90,15 @@ class NexusPlugin(L2DevicePluginBase):
from the relevant interfaces
"""
LOG.debug("NexusPlugin:delete_network() called\n")
net = self._networks.get(net_id)
vlan_id = self._get_vlan_id_for_network(tenant_id, net_id)
ports_id = nxos_db.get_nexusport_binding(vlan_id)
LOG.debug("NexusPlugin: Interfaces to be disassociated: %s" % ports_id)
nxos_db.remove_nexusport_binding(vlan_id)
net = self._networks.get(net_id)
if net:
self._client.delete_vlan(str(vlan_id), self._nexus_ip,
self._nexus_username, self._nexus_password, self._nexus_port,
self._nexus_username, self._nexus_password,
self._nexus_first_port, self._nexus_second_port,
self._nexus_ssh_port)
self._networks.pop(net_id)
return net

View File

@ -19,6 +19,7 @@ import logging
from quantum.common import exceptions as exc
from quantum.plugins.cisco.common import cisco_constants as const
from quantum.plugins.cisco.nexus import cisco_nexus_plugin
from quantum.plugins.cisco.db import l2network_db as cdb
LOG = logging.getLogger('quantum.tests.test_nexus')
@ -34,6 +35,7 @@ class TestNexusPlugin(unittest.TestCase):
self.vlan_id = 267
self.port_id = "9"
self._cisco_nexus_plugin = cisco_nexus_plugin.NexusPlugin()
cdb.initialize()
def test_create_network(self, net_tenant_id=None, network_name=None,
network_id=None, net_vlan_name=None,
@ -66,7 +68,6 @@ class TestNexusPlugin(unittest.TestCase):
new_net_dict = self._cisco_nexus_plugin.create_network(
tenant_id, net_name, net_id, vlan_name, vlan_id)
self.assertEqual(new_net_dict[const.NET_ID], self.net_id)
self.assertEqual(new_net_dict[const.NET_NAME], self.net_name)
self.assertEqual(new_net_dict[const.NET_VLAN_NAME], self.vlan_name)