Skip to content

Commit

Permalink
Improve unit test coverage for Cisco plugin nexus code
Browse files Browse the repository at this point in the history
Closes-Bug: #1190622

This fix improves the unit test coverage for the Cisco Nexus plugin's
cisco_nexus_network_driver_v2.py and cisco_nexus_plugin_v2.py
source files from:
cisco_nexus_network_driver_v2: 72%
cisco_nexus_plugin_v2:         79%
To:
cisco_nexus_network_driver_v2: 99%
cisco_nexus_plugin_v2:         94%

Much of what the remaining "uncovered" code (coverage tool
reports as partially covered) can be attributed to the
coverage tool not being aware that execution does not
continue at the end of a save_and_reraise_exception()
context block (i.e. the exception will be reraised, but
the coverage tool isn't aware of this).

This fix and coverage results are dependent on the fix for #1246080.

Change-Id: Ie0e11fc0a12502739fb39bb4b30deb04dd31b7b0
  • Loading branch information
Dane LeBlanc committed Nov 25, 2013
1 parent a0a462f commit 26e9fad
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 246 deletions.
27 changes: 0 additions & 27 deletions neutron/plugins/cisco/l2device_plugin_base.py
Expand Up @@ -30,15 +30,6 @@ class L2DevicePluginBase(object):

__metaclass__ = ABCMeta

@abstractmethod
def get_all_networks(self, tenant_id, **kwargs):
"""Get newtorks.
:returns:
:raises:
"""
pass

@abstractmethod
def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
**kwargs):
Expand Down Expand Up @@ -67,15 +58,6 @@ def update_network(self, tenant_id, net_id, name, **kwargs):
"""
pass

@abstractmethod
def get_all_ports(self, tenant_id, net_id, **kwargs):
"""Get ports.
:returns:
:raises:
"""
pass

@abstractmethod
def create_port(self, tenant_id, net_id, port_state, port_id, **kwargs):
"""Create port.
Expand Down Expand Up @@ -103,15 +85,6 @@ def update_port(self, tenant_id, net_id, port_id, **kwargs):
"""
pass

@abstractmethod
def get_port_details(self, tenant_id, net_id, port_id, **kwargs):
"""Get port details.
:returns:
:raises:
"""
pass

@abstractmethod
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id,
**kwargs):
Expand Down
20 changes: 0 additions & 20 deletions neutron/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py
Expand Up @@ -84,12 +84,6 @@ def get_credential(self, nexus_ip):
}
return self.credentials[nexus_ip]

def get_switch_and_port_id(self, host_name):
for switch_ip, attr in self.nexus_switches:
if str(attr) == host_name:
return switch_ip, self.nexus_switches[switch_ip, attr]
return None, None

def nxos_connect(self, nexus_host):
"""Make SSH connection to the Nexus Switch."""
if getattr(self.connections.get(nexus_host), 'connected', None):
Expand Down Expand Up @@ -151,20 +145,6 @@ def delete_vlan(self, nexus_host, vlanid):
confstr = self.create_xml_snippet(confstr)
self._edit_config(nexus_host, target='running', config=confstr)

def enable_port_trunk(self, nexus_host, etype, interface):
"""Enable trunk mode an interface on Nexus Switch."""
confstr = snipp.CMD_PORT_TRUNK % (etype, interface, etype)
confstr = self.create_xml_snippet(confstr)
LOG.debug(_("NexusDriver: %s"), confstr)
self._edit_config(nexus_host, target='running', config=confstr)

def disable_switch_port(self, nexus_host, etype, interface):
"""Disable trunk mode an interface on Nexus Switch."""
confstr = snipp.CMD_NO_SWITCHPORT % (etype, interface, etype)
confstr = self.create_xml_snippet(confstr)
LOG.debug(_("NexusDriver: %s"), confstr)
self._edit_config(nexus_host, target='running', config=confstr)

def enable_vlan_on_trunk_int(self, nexus_host, vlanid, etype, interface):
"""Enable a VLAN on a trunk interface."""
# If one or more VLANs are already configured on this interface,
Expand Down
69 changes: 20 additions & 49 deletions neutron/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
Expand Up @@ -26,7 +26,6 @@

import logging

from neutron.common import exceptions as exc
from neutron.openstack.common import excutils
from neutron.openstack.common import importutils
from neutron.plugins.cisco.common import cisco_constants as const
Expand All @@ -50,15 +49,6 @@ def __init__(self):
LOG.debug(_("Loaded driver %s"), conf.CISCO.nexus_driver)
self._nexus_switches = conf.get_device_dictionary()

def get_all_networks(self, tenant_id):
"""Get all networks.
Returns a dictionary containing all <network_uuid, network_name> for
the specified tenant.
"""
LOG.debug(_("NexusPlugin:get_all_networks() called"))
return self._networks.values()

def create_network(self, network, attachment):
"""Create or update a network when an attachment is changed.
Expand Down Expand Up @@ -240,30 +230,26 @@ def _find_switch_for_svi(self):
def delete_network(self, tenant_id, net_id, **kwargs):
"""Delete network.
Deletes the VLAN in all switches, and removes the VLAN configuration
from the relevant interfaces.
Not applicable to Nexus plugin. Defined here to satisfy abstract
method requirements.
"""
LOG.debug(_("NexusPlugin:delete_network() called"))
LOG.debug(_("NexusPlugin:delete_network() called")) # pragma no cover

def update_network(self, tenant_id, net_id, **kwargs):
"""Update the properties of a particular Virtual Network."""
LOG.debug(_("NexusPlugin:update_network() called"))

def get_all_ports(self, tenant_id, net_id, **kwargs):
"""Get all ports.
"""Update the properties of a particular Virtual Network.
This is probably not applicable to the Nexus plugin.
Delete if not required.
Not applicable to Nexus plugin. Defined here to satisfy abstract
method requirements.
"""
LOG.debug(_("NexusPlugin:get_all_ports() called"))
LOG.debug(_("NexusPlugin:update_network() called")) # pragma no cover

def create_port(self, tenant_id, net_id, port_state, port_id, **kwargs):
"""Create port.
This is probably not applicable to the Nexus plugin.
Delete if not required.
Not applicable to Nexus plugin. Defined here to satisfy abstract
method requirements.
"""
LOG.debug(_("NexusPlugin:create_port() called"))
LOG.debug(_("NexusPlugin:create_port() called")) # pragma no cover

def delete_port(self, device_id, vlan_id):
"""Delete port.
Expand Down Expand Up @@ -337,40 +323,25 @@ def delete_port(self, device_id, vlan_id):
def update_port(self, tenant_id, net_id, port_id, port_state, **kwargs):
"""Update port.
This is probably not applicable to the Nexus plugin.
Delete if not required.
"""
LOG.debug(_("NexusPlugin:update_port() called"))

def get_port_details(self, tenant_id, net_id, port_id, **kwargs):
"""Get port details.
This is probably not applicable to the Nexus plugin.
Delete if not required.
Not applicable to Nexus plugin. Defined here to satisfy abstract
method requirements.
"""
LOG.debug(_("NexusPlugin:get_port_details() called"))
LOG.debug(_("NexusPlugin:update_port() called")) # pragma no cover

def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id,
**kwargs):
"""Plug interfaces.
This is probably not applicable to the Nexus plugin.
Delete if not required.
Not applicable to Nexus plugin. Defined here to satisfy abstract
method requirements.
"""
LOG.debug(_("NexusPlugin:plug_interface() called"))
LOG.debug(_("NexusPlugin:plug_interface() called")) # pragma no cover

def unplug_interface(self, tenant_id, net_id, port_id, **kwargs):
"""Unplug interface.
This is probably not applicable to the Nexus plugin.
Delete if not required.
Not applicable to Nexus plugin. Defined here to satisfy abstract
method requirements.
"""
LOG.debug(_("NexusPlugin:unplug_interface() called"))

def _get_network(self, tenant_id, network_id, context, base_plugin_ref):
"""Get the Network ID."""
network = base_plugin_ref._get_network(context, network_id)
if not network:
raise exc.NetworkNotFound(net_id=network_id)
return {const.NET_ID: network_id, const.NET_NAME: network.name,
const.NET_PORTS: network.ports}
LOG.debug(_("NexusPlugin:unplug_interface() called")
) # pragma no cover
35 changes: 0 additions & 35 deletions neutron/plugins/cisco/nexus/cisco_nexus_snippets.py
Expand Up @@ -37,7 +37,6 @@
</config>
"""


CMD_VLAN_CONF_SNIPPET = """
<vlan>
<vlan-id-create-delete>
Expand Down Expand Up @@ -122,38 +121,6 @@
CMD_VLAN_ADD_ID +
CMD_INT_VLAN_TRAILER)

CMD_PORT_TRUNK = """
<interface>
<%s>
<interface>%s</interface>
<__XML__MODE_if-ethernet-switch>
<switchport></switchport>
<switchport>
<mode>
<trunk>
</trunk>
</mode>
</switchport>
</__XML__MODE_if-ethernet-switch>
</%s>
</interface>
"""

CMD_NO_SWITCHPORT = """
<interface>
<%s>
<interface>%s</interface>
<__XML__MODE_if-ethernet-switch>
<no>
<switchport>
</switchport>
</no>
</__XML__MODE_if-ethernet-switch>
</%s>
</interface>
"""


CMD_NO_VLAN_INT_SNIPPET = """
<interface>
<%s>
Expand All @@ -176,7 +143,6 @@
</interface>
"""


FILTER_SHOW_VLAN_BRIEF_SNIPPET = """
<show xmlns="http://www.cisco.com/nxos:1.0:vlan_mgr_cli">
<vlan>
Expand All @@ -185,7 +151,6 @@
</show>
"""


CMD_VLAN_SVI_SNIPPET = """
<interface>
<vlan>
Expand Down
4 changes: 0 additions & 4 deletions neutron/plugins/cisco/test/nexus/fake_nexus_driver.py
Expand Up @@ -45,10 +45,6 @@ def disable_vlan(self, mgr, vlanid):
"""Delete a VLAN on Nexus Switch given the VLAN ID."""
pass

def enable_port_trunk(self, mgr, interface):
"""Enable trunk mode an interface on Nexus Switch."""
pass

def disable_switch_port(self, mgr, interface):
"""Disable trunk mode an interface on Nexus Switch."""
pass
Expand Down

0 comments on commit 26e9fad

Please sign in to comment.