ML2 Nexus Add Host/interface mapping table

This code set adds new host to interface mapping table to
ML2 Nexus Driver.  It allows for VMs on baremetal host to
be spawned after learning baremetal node.  Additionally
static host to interface mapping learned from configuration
file also moved to this data base.

Change-Id: I5749176a381ac4b5140feb1f98c5b73aa1601025
Closes-bug:  #1691194
This commit is contained in:
Carol Bouchard 2017-05-16 15:42:09 -04:00
parent aef4474411
commit e27ec5a03b
17 changed files with 793 additions and 279 deletions

View File

@ -1 +1 @@
203b495958cf
681d19b7070e

View File

@ -0,0 +1,41 @@
# Copyright 2017 Cisco Systems, Inc.
#
# 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.
"""Add host/interface mapping table
Revision ID: 681d19b7070e
Revises: 203b495958cf
Create Date: 2017-05-16 13:47:24.649856
"""
# revision identifiers, used by Alembic.
revision = '681d19b7070e'
down_revision = '203b495958cf'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('cisco_ml2_nexus_host_interface_mapping',
sa.Column('host_id', sa.String(length=255), nullable=False,
index=True),
sa.Column('switch_ip', sa.String(length=64), nullable=False,
index=True),
sa.Column('if_id', sa.String(length=255), nullable=False),
sa.Column('ch_grp', sa.Integer(), nullable=False),
sa.Column('is_static', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('switch_ip', 'if_id')
)

View File

@ -16,6 +16,10 @@
from oslo_config import cfg
from networking_cisco._i18n import _
from networking_cisco.plugins.ml2.drivers.cisco.nexus import (
constants as const)
from networking_cisco.plugins.ml2.drivers.cisco.nexus import (
nexus_db_v2 as nxos_db)
ml2_cisco_opts = [
cfg.StrOpt('vlan_name_prefix', default='q-',
@ -77,16 +81,26 @@ class ML2MechCiscoConfig(object):
"""Create the ML2 device cisco dictionary.
Read data from the ml2_conf_cisco.ini device supported sections.
All reserved keywords are saved in the nexus_dict and all other
keys (host systems) are saved in the host mapping db.
"""
defined_attributes = [const.USERNAME, const.PASSWORD, const.SSHPORT,
const.PHYSNET, const.NVE_SRC_INTF]
multi_parser = cfg.MultiConfigParser()
read_ok = multi_parser.read(cfg.CONF.config_file)
if len(read_ok) != len(cfg.CONF.config_file):
raise cfg.Error(_("Some config files were not parsed properly"))
nxos_db.remove_all_static_host_mappings()
for parsed_file in multi_parser.parsed:
for parsed_item in parsed_file.keys():
dev_id, sep, dev_ip = parsed_item.partition(':')
if dev_id.lower() == 'ml2_mech_cisco_nexus':
for dev_key, value in parsed_file[parsed_item].items():
self.nexus_dict[dev_ip, dev_key] = value[0]
if dev_key in defined_attributes:
self.nexus_dict[dev_ip, dev_key] = value[0]
else:
for if_id in value[0].split(','):
nxos_db.add_host_mapping(
dev_key, dev_ip, if_id, 0, True)

View File

@ -15,12 +15,15 @@
#
RESERVED_PORT_HOST_ID = 'reserved_port'
CREDENTIAL_USERNAME = 'user_name'
CREDENTIAL_PASSWORD = 'password'
USERNAME = 'username'
PASSWORD = 'password'
SSHPORT = 'ssh_port'
PHYSNET = 'physnet'
NVE_SRC_INTF = 'nve_src_intf'
NETWORK_ADMIN = 'network_admin'
@ -49,7 +52,6 @@ FAIL_CONTACT = '_contact'
FAIL_CONFIG = '_config'
RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 = "RESERVED_NEXUS_SWITCH_DEVICE_ID_R1"
RESERVED_NEXUS_PORT_DEVICE_ID_R1 = "RESERVED_NEXUS_PORT_DEVICE_ID_R1"
NO_PORT_ID = "NONE"
NO_VLAN_OR_VNI_ID = '0'
SWITCH_ACTIVE = "ACTIVE"

View File

@ -56,6 +56,15 @@ class NexusPortBindingNotFound(exceptions.NeutronException):
super(NexusPortBindingNotFound, self).__init__(filters=filters)
class NexusHostMappingNotFound(exceptions.NeutronException):
"""NexusHost Mapping is not present."""
message = _("Nexus Host Mapping (%(filters)s) is not present")
def __init__(self, **kwargs):
filters = ','.join('%s=%s' % i for i in kwargs.items())
super(NexusHostMappingNotFound, self).__init__(filters=filters)
class NexusMissingRequiredFields(exceptions.NeutronException):
"""Missing required fields to configure nexus switch."""
message = _("Missing required field(s) to configure nexus switch: "

View File

@ -116,16 +116,20 @@ class CiscoNexusCfgMonitor(object):
# then change dependent port bindings.
for switch_ip, intf_type, port, is_native, ch_grp in switch_ifs:
try:
reserved = nxos_db.get_reserved_port_binding(
reserved = nxos_db.get_switch_if_host_mappings(
switch_ip,
self._mdriver.format_interface_name(
intf_type, port))
except excep.NexusPortBindingNotFound:
except excep.NexusHostMappingNotFound:
continue
if reserved[0].channel_group != ch_grp:
self._mdriver._change_baremetal_interfaces(
switch_ip, intf_type, port,
reserved[0].channel_group, ch_grp)
if reserved[0].ch_grp != ch_grp:
LOG.warning(_LW("port-channel mismatch. skip"))
#TODO(caboucha)Temporarily Skip the following until
#HN72 automated vPC is implemented
#self._mdriver._change_baremetal_interfaces(
# reserved[0].host_id,
# switch_ip, intf_type, port,
# reserved[0].ch_grp, ch_grp)
# When replay not enabled, this is call early during initialization.
# To prevent bogus ssh handles from being copied to child processes,
@ -526,7 +530,7 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
switch_connections = []
try:
bindings = nxos_db.get_reserved_switch_binding()
except excep.NexusPortBindingNotFound:
except excep.NexusHostMappingNotFound:
LOG.error(_LE("No switch bindings in the port data base"))
bindings = []
for switch in bindings:
@ -646,18 +650,6 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
return selected
def _gather_configured_ports(self, switch_ip, attr, host_list):
"""Get all interfaces originally from ml2_conf_cisco files."""
for port_id in (
self._nexus_switches[switch_ip, attr].split(',')):
intf_type, port = self.split_interface_name(port_id)
# is_native set to const.NOT_NATIVE for
# VNIC_TYPE of normal
host_list.append((switch_ip, intf_type, port,
const.NOT_NATIVE))
def _get_baremetal_switches(self, port):
"""Get switch ip addresses from baremetal transaction.
@ -737,21 +729,21 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
is_native = const.NOT_NATIVE
if not from_segment:
try:
reserved = nxos_db.get_reserved_port_binding(
reserved = nxos_db.get_switch_if_host_mappings(
switch_ip,
self.format_interface_name(
intf_type, port))
if reserved[0].channel_group > 0:
if reserved[0].ch_grp > 0:
intf_type, port = self.split_interface_name(
'', reserved[0].channel_group)
except excep.NexusPortBindingNotFound:
'', reserved[0].ch_grp)
except excep.NexusHostMappingNotFound:
pass
connections.append((switch_ip, intf_type, port, is_native))
return connections
def _change_baremetal_interfaces(self, switch_ip, intf_type,
def _change_baremetal_interfaces(self, host_id, switch_ip, intf_type,
port, old_ch_grp, ch_grp):
"""Restart detected port channel change. Update database.
@ -836,7 +828,8 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
continue
# Update the reserved port binding with new channel group
nxos_db.update_reserved_port_binding(
nxos_db.update_host_mapping(
host_id,
switch_ip,
reserved_port_id,
ch_grp)
@ -874,14 +867,14 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
port_seg, False, True)
for switch_ip, intf_type, port, is_native in connections:
try:
reserved = nxos_db.get_reserved_port_binding(
reserved = nxos_db.get_switch_if_host_mappings(
switch_ip,
self.format_interface_name(
intf_type, port))
reserved_exists.append(
(switch_ip, intf_type, port, is_native,
reserved[0].channel_group))
except excep.NexusPortBindingNotFound:
reserved[0].ch_grp))
except excep.NexusHostMappingNotFound:
if self.is_switch_active(switch_ip):
# channel-group added later
list_to_init.append(
@ -893,14 +886,19 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
# channel_group is appended to tuples in list_to_init
self.driver.initialize_all_switch_interfaces(list_to_init)
host_id = port_seg.get('dns_name')
if host_id is None:
host_id = const.RESERVED_PORT_HOST_ID
# Add inactive list to list_to_init to create RESERVED
# port data base entries
list_to_init += inactive_switch
for switch_ip, intf_type, port, is_native, ch_grp in list_to_init:
nxos_db.add_reserved_port_binding(
nxos_db.add_host_mapping(
host_id,
switch_ip,
self.format_interface_name(intf_type, port),
ch_grp)
ch_grp, False)
device_id = port_seg.get('device_id')
vlan_id = segment.get(api.SEGMENTATION_ID)
@ -937,11 +935,15 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
all_switches = set()
active_switches = set()
for switch_ip, attr in self._nexus_switches:
if str(attr) == str(host_id):
all_switches.add(switch_ip)
if self.is_switch_active(switch_ip):
active_switches.add(switch_ip)
try:
host_list = nxos_db.get_host_mappings(host_id)
for mapping in host_list:
all_switches.add(mapping.switch_ip)
if self.is_switch_active(mapping.switch_ip):
active_switches.add(mapping.switch_ip)
except excep.NexusHostMappingNotFound:
pass
return list(all_switches), list(active_switches)
@ -962,14 +964,22 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
host_found = False
host_connections = []
for switch_ip, attr in self._nexus_switches:
if str(attr) == str(host_id):
host_found = True
if (only_active_switch and
not self.is_switch_active(switch_ip)):
continue
self._gather_configured_ports(
switch_ip, attr, host_connections)
try:
host_ifs = nxos_db.get_host_mappings(host_id)
except excep.NexusHostMappingNotFound:
host_ifs = []
for ifs in host_ifs:
host_found = True
if (only_active_switch and
not self.is_switch_active(ifs.switch_ip)):
continue
intf_type, port = self.split_interface_name(
ifs.if_id)
# is_native set to const.NOT_NATIVE for
# VNIC_TYPE of normal
host_connections.append((
ifs.switch_ip, intf_type, port,
const.NOT_NATIVE))
if not host_found:
LOG.warning(HOST_NOT_FOUND, host_id)
@ -978,22 +988,23 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
def _get_port_connections(self, port, host_id,
only_active_switch=False):
if host_id:
return self._get_host_connections(
host_id, only_active_switch)
else:
if self._is_baremetal(port):
return self._get_baremetal_connections(
port, only_active_switch)
else:
return self._get_host_connections(
host_id, only_active_switch)
def _get_active_port_connections(self, port, host_id):
return self._get_port_connections(port, host_id, True)
def _get_known_baremetal_interfaces(self, requested_switch_ip):
"""Get known baremetal interfaces from reserved DB.
def _get_switch_interfaces(self, requested_switch_ip):
"""Get switch interfaces from host mapping DB.
For a given switch, this returns all known RESERVED port
interfaces. These have been learned from received
baremetal transactions.
For a given switch, this returns all known port
interfaces for a given switch. These have been
learned from received baremetal transactions and
from configuration file.
:param requested_switch_ip: switch_ip
:returns: list of switch_ip, intf_type, port_id, is_native
@ -1002,58 +1013,19 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
switch_ifs = []
try:
port_info = nxos_db.get_reserved_port_binding(
port_info = nxos_db.get_switch_host_mappings(
requested_switch_ip)
except excep.NexusPortBindingNotFound:
except excep.NexusHostMappingNotFound:
port_info = []
for binding in port_info:
intf_type, port = self.split_interface_name(
binding.port_id)
binding.if_id)
switch_ifs.append(
(requested_switch_ip, intf_type, port,
binding.is_native))
const.NOT_NATIVE))
return switch_ifs
def _get_config_switch_interfaces(self, requested_switch_ip):
"""Identify host entries to get interfaces.
For a given switch, this returns all known configured port
interfaces. These configured in the ml2_conf.ini file.
:param requested_switch_ip: switch_ip
:returns: list of switch_ip, intf_type, port_id, is_native
"""
switch_ifs = []
defined_attributes = [const.USERNAME, const.PASSWORD, const.SSHPORT,
'physnet', 'nve_src_intf']
for switch_ip, attr in self._nexus_switches:
# if not in clearly defined attribute, it must be a host
# with it's listed interfaces
if (switch_ip == requested_switch_ip and
str(attr) not in defined_attributes):
self._gather_configured_ports(
switch_ip, attr, switch_ifs)
return switch_ifs
def _get_switch_interfaces(self, requested_switch_ip):
"""Get known baremetal and config interfaces.
For a given switch, return known configured and baremetal
interfaces.
:param requested_switch_ip: switch_ip
:returns: list of switch_ip, intf_type, port_id, is_native
"""
all_switch_ifs = self._get_config_switch_interfaces(
requested_switch_ip)
all_switch_ifs += self._get_known_baremetal_interfaces(
requested_switch_ip)
return all_switch_ifs
def get_switch_ips(self):
switch_connections = []
for switch_ip, attr in self._nexus_switches:
@ -1063,15 +1035,19 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
return switch_connections
def _get_switch_nve_info(self, host_id):
host_nve_connections = []
for switch_ip, attr in self._nexus_switches:
if str(attr) == str(host_id):
host_nve_connections.append(switch_ip)
host_nve_connections = set()
try:
host_data = nxos_db.get_host_mappings(host_id)
except excep.NexusHostMappingNotFound:
host_data = []
for host in host_data:
if host.is_static:
host_nve_connections.add(host.switch_ip)
if not host_nve_connections:
LOG.warning(HOST_NOT_FOUND, host_id)
return host_nve_connections
return sorted(host_nve_connections)
def _configure_nve_db(self, vni, device_id, mcast_group, host_id):
"""Create the nexus NVE database entry.
@ -1087,7 +1063,7 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
def get_nve_loopback(self, switch_ip):
return self._nexus_switches.get(
(switch_ip, 'nve_src_intf'), '0')
(switch_ip, const.NVE_SRC_INTF), '0')
def _configure_nve_member(self, vni, device_id, mcast_group, host_id):
"""Add "member vni" configuration to the NVE interface.
@ -1545,6 +1521,7 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
Called during delete postcommit port event.
"""
connections = self._get_active_port_connections(port, host_id)
# (nexus_port,switch_ip) will be unique in each iteration.
@ -1585,6 +1562,25 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
if switch_ip not in vlan_already_removed:
self.driver.delete_vlan(switch_ip, vlan_id)
vlan_already_removed.append(switch_ip)
if self._is_baremetal(port):
connections = self._get_baremetal_connections(
port, False, True)
for switch_ip, intf_type, nexus_port, is_native in connections:
if_id = self.format_interface_name(
intf_type, nexus_port)
try:
mapping = nxos_db.get_switch_if_host_mappings(
switch_ip, if_id)
ch_grp = mapping[0].ch_grp
except excep.NexusHostMappingNotFound:
ch_grp = 0
bind_port_id = self.format_interface_name(
intf_type, nexus_port, ch_grp)
binding = nxos_db.get_port_switch_bindings(
bind_port_id,
switch_ip)
if not binding:
nxos_db.remove_host_mapping(if_id, switch_ip)
def _is_segment_nexus_vxlan(self, segment):
return segment[api.NETWORK_TYPE] == const.TYPE_NEXUS_VXLAN
@ -1632,10 +1628,8 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
return
device_id = port.get('device_id')
# No host_id is another indicator this is a baremetal
# transaction
if self._is_baremetal(port):
host_id = ''
host_id = port.get('dns_name')
else:
host_id = port.get(bc.portbindings.HOST_ID)
vlan_id = segment.get(api.SEGMENTATION_ID)
@ -1716,7 +1710,6 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
port = context.current
if self._is_supported_deviceowner(port):
if self._is_baremetal(context.current):
host_id = ''
all_switches, active_switches = (
self._get_baremetal_switches(context.current))
else:
@ -1805,7 +1798,6 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
# operation should not be done in precommit.
self._init_baremetal_trunk_interfaces(
context.current, vlan_segment, 0)
host_id = ''
all_switches, active_switches = (
self._get_baremetal_switches(context.current))
else:
@ -1876,7 +1868,8 @@ class CiscoNexusMechanismDriver(api.MechanismDriver):
return
for switch_ip, attr2, attr3, attr4 in host_connections:
physnet = self._nexus_switches.get((switch_ip, 'physnet'))
physnet = self._nexus_switches.get(
(switch_ip, const.PHYSNET))
if physnet:
break
else:

View File

@ -86,7 +86,6 @@ def update_reserved_binding(vlan_id, switch_ip, instance_id,
:param vlan_id: 0
:param switch_ip: ip address of the switch
:param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1
: or RESERVED_NEXUS_PORT_DEVICE_ID_R1
:param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE
: port-expected port_id
:param ch_grp: 0 if no port-channel else non-zero integer
@ -130,7 +129,6 @@ def remove_reserved_binding(vlan_id, switch_ip, instance_id,
:param vlan_id: 0
:param switch_ip: ip address of the switch
:param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1
: or RESERVED_NEXUS_PORT_DEVICE_ID_R1
:param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE
: port-expected port_id
"""
@ -182,43 +180,6 @@ def update_reserved_switch_binding(switch_ip, state):
state)
def get_reserved_port_binding(switch_ip, port_id=None):
"""Get a reserved port binding."""
return get_reserved_bindings(
const.NO_VLAN_OR_VNI_ID,
const.RESERVED_NEXUS_PORT_DEVICE_ID_R1,
switch_ip,
port_id)
def add_reserved_port_binding(switch_ip, port_id, ch_grp):
"""Add a reserved port binding."""
add_nexusport_binding(
port_id,
const.NO_VLAN_OR_VNI_ID,
const.NO_VLAN_OR_VNI_ID,
switch_ip,
const.RESERVED_NEXUS_PORT_DEVICE_ID_R1,
False,
const.NOT_NATIVE,
ch_grp)
def update_reserved_port_binding(switch_ip, port_id, ch_grp):
"""Update a reserved port binding."""
update_reserved_binding(
const.NO_VLAN_OR_VNI_ID,
switch_ip,
const.RESERVED_NEXUS_PORT_DEVICE_ID_R1,
port_id,
False,
const.NOT_NATIVE,
ch_grp)
def is_reserved_binding(binding):
"""Identifies switch & port operational bindings.
@ -235,8 +196,7 @@ def is_reserved_binding(binding):
"""
return (binding.instance_id in
[const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1,
const.RESERVED_NEXUS_PORT_DEVICE_ID_R1])
[const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1])
def get_nexusport_switch_bindings(switch_ip):
@ -449,3 +409,126 @@ def get_nve_vni_deviceid_bindings(vni, device_id):
filter_by(vni=vni, device_id=device_id).all())
except sa_exc.NoResultFound:
return None
def _lookup_host_mappings(query_type, session=None, **bfilter):
"""Look up 'query_type' Nexus mappings matching the filter.
:param query_type: 'all', 'one' or 'first'
:param session: db session
:param bfilter: filter for mappings query
:return: mappings if query gave a result, else
raise NexusHostMappingNotFound.
"""
if session is None:
session = db.get_session()
query_method = getattr(session.query(
nexus_models_v2.NexusHostMapping).filter_by(**bfilter), query_type)
try:
mappings = query_method()
if mappings:
return mappings
except sa_exc.NoResultFound:
pass
raise c_exc.NexusHostMappingNotFound(**bfilter)
def _lookup_all_host_mappings(session=None, **bfilter):
return _lookup_host_mappings('all', session, **bfilter)
def _lookup_one_host_mapping(session=None, **bfilter):
return _lookup_host_mappings('one', session, **bfilter)
def get_all_host_mappings():
return(_lookup_all_host_mappings())
def get_host_mappings(host_id):
return(_lookup_all_host_mappings(host_id=host_id))
def get_switch_host_mappings(switch_ip):
return(_lookup_all_host_mappings(switch_ip=switch_ip))
def get_switch_and_host_mappings(host_id, switch_ip):
return(_lookup_all_host_mappings(
host_id=host_id, switch_ip=switch_ip))
def get_switch_if_host_mappings(switch_ip, if_id):
return(_lookup_all_host_mappings(switch_ip=switch_ip,
if_id=if_id))
def add_host_mapping(host_id, nexus_ip, interface, ch_grp, is_static):
"""Add Host to interface mapping entry into mapping data base.
host_id is the name of the host to add
interface is the interface for this host
nexus_ip is the ip addr of the nexus switch for this interface
ch_grp is the port channel this interface belos
is_static whether this is from conf file or learned
from baremetal.
"""
LOG.debug("add_nexusport_binding() called")
session = db.get_session()
mapping = nexus_models_v2.NexusHostMapping(host_id=host_id,
if_id=interface,
switch_ip=nexus_ip,
ch_grp=ch_grp,
is_static=is_static)
session.add(mapping)
session.flush()
return mapping
def update_host_mapping(host_id, interface, nexus_ip, new_ch_grp):
"""Change channel_group in host/interface mapping data base."""
LOG.debug("update_host_mapping called")
session = db.get_session()
mapping = _lookup_one_host_mapping(
session=session,
host_id=host_id,
if_id=interface,
switch_ip=nexus_ip)
mapping.ch_grp = new_ch_grp
session.merge(mapping)
session.flush()
return mapping
def remove_host_mapping(interface, nexus_ip):
"""Remove host to interface mapping entry from mapping data base."""
LOG.debug("remove_host_mapping() called")
session = db.get_session()
try:
mapping = _lookup_one_host_mapping(
session=session,
if_id=interface,
switch_ip=nexus_ip)
session.delete(mapping)
session.flush()
except c_exc.NexusHostMappingNotFound:
pass
def remove_all_static_host_mappings():
"""Remove all entries defined in config file from mapping data base."""
LOG.debug("remove_host_mapping() called")
session = db.get_session()
try:
mapping = _lookup_all_host_mappings(
session=session,
is_static=True)
for host in mapping:
session.delete(host)
session.flush()
except c_exc.NexusHostMappingNotFound:
pass

View File

@ -94,3 +94,17 @@ class NexusMcastGroup(bc.model_base.BASEV2, bc.model_base.HasId):
'ml2_nexus_vxlan_allocations.vxlan_vni',
ondelete="CASCADE"),
nullable=False)
class NexusHostMapping(bc.model_base.BASEV2):
"""Nexus Host to interface Mapping."""
__tablename__ = 'cisco_ml2_nexus_host_interface_mapping'
host_id = sa.Column(sa.String(255), nullable=False, index=True)
switch_ip = sa.Column(sa.String(255), nullable=False, primary_key=True,
index=True)
if_id = sa.Column(sa.String(255), nullable=False, primary_key=True)
ch_grp = sa.Column(sa.Integer(), nullable=False)
is_static = sa.Column(sa.Boolean(), nullable=False)

View File

@ -239,7 +239,7 @@ class CiscoNexusSshDriver(basedrvr.CiscoNexusBaseDriver):
if not self.ncclient:
self.ncclient = self._import_client()
nexus_ssh_port = int(self.nexus_switches[nexus_host, 'ssh_port'])
nexus_ssh_port = int(self.nexus_switches[nexus_host, const.SSHPORT])
nexus_user = self.nexus_switches[nexus_host, const.USERNAME]
nexus_password = self.nexus_switches[nexus_host, const.PASSWORD]
hostkey_verify = cfg.CONF.ml2_cisco.host_key_checks

View File

@ -175,7 +175,7 @@ class CiscoNexusRestapiDriver(basedrvr.CiscoNexusBaseDriver):
except Exception:
pass
LOG.debug("GET interface %(key)s port channel is %(pc)",
LOG.debug("GET interface %(key)s port channel is %(pc)d",
{'key': match_key, 'pc': ch_grp})
return ch_grp

View File

@ -19,11 +19,12 @@ from oslo_config import cfg
from networking_cisco.plugins.ml2.drivers.cisco.nexus import (
config as cisco_config)
from networking_cisco.plugins.ml2.drivers.cisco.nexus import nexus_db_v2
from neutron.tests import base
from neutron.tests.unit import testlib_api
class TestCiscoNexusPluginConfig(base.BaseTestCase):
class TestCiscoNexusPluginConfig(testlib_api.SqlTestCase):
def setUp(self):
self.config_parse()
@ -59,19 +60,39 @@ class TestCiscoNexusPluginConfig(base.BaseTestCase):
('1.1.1.1', 'username'): 'admin',
('1.1.1.1', 'password'): 'mySecretPassword',
('1.1.1.1', 'ssh_port'): 22,
('1.1.1.1', 'compute1'): '1/1',
('1.1.1.1', 'compute2'): '1/2',
('1.1.1.1', 'compute5'): '1/3,1/4',
('2.2.2.2', 'username'): 'admin',
('2.2.2.2', 'password'): 'mySecretPassword',
('2.2.2.2', 'ssh_port'): 22,
('2.2.2.2', 'compute3'): '1/1',
('2.2.2.2', 'compute4'): '1/2',
('2.2.2.2', 'compute5'): 'portchannel:20,portchannel:30',
}
host_map_data = [
('compute1', '1.1.1.1', '1/1'),
('compute2', '1.1.1.1', '1/2'),
('compute3', '2.2.2.2', '1/1'),
('compute4', '2.2.2.2', '1/2'),
('compute5', '1.1.1.1', '1/3'),
('compute5', '1.1.1.1', '1/4'),
('compute5', '2.2.2.2', 'portchannel:20'),
('compute5', '2.2.2.2', 'portchannel:30')
]
with mock.patch.object(cfg, 'MultiConfigParser') as parser:
parser.return_value.read.return_value = cfg.CONF.config_file
parser.return_value.parsed = [test_config]
cisco_config.ML2MechCiscoConfig()
self.assertEqual(expected_dev_dict,
cisco_config.ML2MechCiscoConfig.nexus_dict)
mappings = nexus_db_v2.get_all_host_mappings()
idx = 0
maps_sorted = []
for map in mappings:
maps_sorted.append([map.host_id, map.switch_ip,
map.if_id, map.ch_grp, map.is_static])
maps_sorted.sort()
for map in maps_sorted:
self.assertEqual(map[0], host_map_data[idx][0])
self.assertEqual(map[1], host_map_data[idx][1])
self.assertEqual(map[2], host_map_data[idx][2])
self.assertEqual(map[3], 0)
self.assertTrue(map[4])
idx += 1

View File

@ -71,6 +71,7 @@ HOST_NAME_4 = 'testhost4'
HOST_NAME_5 = 'testhost5'
HOST_NAME_6 = 'testhost6'
HOST_NAME_UNUSED = 'unused'
HOST_NAME_Baremetal = 'baremetal'
INSTANCE_1 = 'testvm1'
INSTANCE_2 = 'testvm2'
@ -80,6 +81,7 @@ INSTANCE_DUAL = 'testdualvm'
NEXUS_BAREMETAL_PORT_1 = 'Ethernet 1/10'
NEXUS_PORT_1 = 'ethernet:1/10'
NEXUS_PORT_2 = 'ethernet:1/20'
NEXUS_PORT_3 = 'ethernet:1/30'
NEXUS_DUAL1 = 'ethernet:1/3'
NEXUS_DUAL2 = 'ethernet:1/2'
NEXUS_PORTCHANNELS = 'portchannel:2'
@ -238,13 +240,14 @@ class FakePortContext(object):
def __init__(self, device_id, host_name, device_owner,
network_context, bottom_segment=None,
profile=None, vnic_type=u'normal', netid=None):
profile=None, vnic_type=u'normal',
dns_name=None, netid=None):
if profile is None:
profile = []
if not netid:
netid = NETID
self._set_port(device_id, host_name, device_owner,
profile, vnic_type, netid)
profile, vnic_type, dns_name, netid)
self._port_orig = None
self._network = network_context
if network_context:
@ -257,13 +260,15 @@ class FakePortContext(object):
self._segments_to_bind = None
def _set_port(self, device_id, host_name, device_owner,
profile=None, vnic_type=u'normal', netid=None):
profile=None, vnic_type=u'normal',
dns_name=None, netid=None):
self._port = {
'status': PORT_STATE,
'device_id': device_id,
'device_owner': device_owner,
api.ID: PORT_ID,
'dns_name': dns_name,
'network_id': netid,
bc.portbindings.HOST_ID: host_name,
bc.portbindings.VNIC_TYPE: vnic_type,
@ -272,13 +277,15 @@ class FakePortContext(object):
}
def set_orig_port(self, device_id, host_name, device_owner,
profile=None, vnic_type=u'normal', netid=None):
profile=None, vnic_type=u'normal',
dns_name=None, netid=None):
self._port_orig = {
'status': PORT_STATE,
'device_id': device_id,
'device_owner': device_owner,
api.ID: PORT_ID,
'dns_name': dns_name,
'network_id': netid,
bc.portbindings.HOST_ID: host_name,
bc.portbindings.VNIC_TYPE: vnic_type,
@ -368,7 +375,7 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
TestConfigObj = collections.namedtuple(
'TestConfigObj',
'nexus_ip_addr host_name nexus_port instance_id vlan_id vxlan_id '
'mcast_group device_owner profile vnic_type')
'mcast_group device_owner profile dns_name vnic_type')
def mock_init(self):
@ -452,21 +459,24 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
for name, config in self.test_configs.items():
ip_addr = config.nexus_ip_addr
host_name = config.host_name
nexus_port = config.nexus_port
nexus_ports = config.nexus_port
# baremetal config done differently
if not ip_addr:
continue
if host_name is not HOST_NAME_UNUSED:
if (ip_addr, host_name) in mech_instance._nexus_switches:
saved_port = (mech_instance._nexus_switches[
(ip_addr, host_name)])
if saved_port != nexus_port:
mech_instance._nexus_switches[
(ip_addr, host_name)] = (
saved_port + ',' + nexus_port)
else:
mech_instance._nexus_switches[
(ip_addr, host_name)] = nexus_port
# if VNIC_TYPE is baremetal
# VMs that reference this baremetal
# do not configure an entry in the host mapping db
# since code learns this information.
if (host_name is not HOST_NAME_UNUSED and
HOST_NAME_Baremetal not in host_name):
for nexus_port in nexus_ports.split(','):
try:
nexus_db_v2.get_switch_if_host_mappings(
ip_addr, nexus_port)
except exceptions.NexusHostMappingNotFound:
nexus_db_v2.add_host_mapping(
host_name, ip_addr, nexus_port,
0, True)
mech_instance._nexus_switches[(ip_addr,
'ssh_port')] = NEXUS_SSH_PORT
mech_instance._nexus_switches[(ip_addr,
@ -474,7 +484,7 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
mech_instance._nexus_switches[(ip_addr,
constants.PASSWORD)] = 'password'
mech_instance._nexus_switches[(ip_addr,
'physnet')] = PHYSNET
const.PHYSNET)] = PHYSNET
mech_instance.driver.nexus_switches = (
mech_instance._nexus_switches)
mech_instance.context = bc.get_context()
@ -506,6 +516,7 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
device_owner = port_config.device_owner
profile = port_config.profile
vnic_type = port_config.vnic_type
dns_name = port_config.dns_name
if override_netid:
netid = override_netid
else:
@ -519,23 +530,23 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
port_context = FakeUnbindPortContext(
instance_id, host_name, device_owner,
vxlan_network_context, network_context,
profile, vnic_type, netid)
profile, vnic_type, dns_name, netid)
else:
port_context = FakePortContext(
instance_id, host_name, device_owner,
vxlan_network_context, network_context,
profile, vnic_type, netid)
profile, vnic_type, dns_name, netid)
else:
if unbind_port:
port_context = FakeUnbindPortContext(
instance_id, host_name, device_owner,
network_context, None,
profile, vnic_type, netid)
profile, vnic_type, dns_name, netid)
else:
port_context = FakePortContext(
instance_id, host_name, device_owner,
network_context, None,
profile, vnic_type, netid)
profile, vnic_type, dns_name, netid)
return port_context
@ -713,6 +724,7 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
def _basic_delete_verify_port_vlan(self, test_name, test_result,
nbr_of_bindings=0,
nbr_of_mappings=0,
other_test=None):
"""Create port vlan and verify results."""
@ -735,6 +747,19 @@ class TestCiscoNexusBase(testlib_api.SqlTestCase):
port_bindings = []
self.assertEqual(nbr_of_bindings, len(port_bindings))
port_context = self._generate_port_context(other_test)
if self._cisco_mech_driver._is_baremetal(port_context.current):
connections = self._cisco_mech_driver._get_baremetal_connections(
port_context.current, False, True)
for switch_ip, intf_type, port, is_p_vlan in connections:
port_id = intf_type + ':' + port
try:
host_mapping = nexus_db_v2.get_switch_if_host_mappings(
switch_ip, port_id)
except exceptions.NexusHostMappingNotFound:
host_mapping = []
self.assertEqual(nbr_of_mappings, len(host_mapping))
# Make sure there is only a single attempt to configure.
self._verify_results(test_result)
@ -1030,9 +1055,14 @@ class TestCiscoNexusReplayBase(TestCiscoNexusBase):
# just the result of replay()
self.mock_ncclient.reset_mock()
if 'nbr_db_mappings' in del_result1:
nbr_db_mappings = del_result1['nbr_db_mappings']
else:
nbr_db_mappings = 0
self._basic_delete_verify_port_vlan(
test2, del_result1['driver_results'],
del_result1['nbr_db_entries'])
del_result1['nbr_db_entries'],
nbr_db_mappings)
self._basic_delete_verify_port_vlan(
test1, del_result2['driver_results'],
del_result2['nbr_db_entries'])
@ -1068,6 +1098,7 @@ class TestContext(TestCiscoNexusBase):
None,
DEVICE_OWNER_COMPUTE,
{},
None,
NORMAL_VNIC),
'test_vxlan_unique1': TestCiscoNexusBase.TestConfigObj(
NEXUS_IP_ADDRESS_1,
@ -1079,6 +1110,7 @@ class TestContext(TestCiscoNexusBase):
'225.1.1.1',
DEVICE_OWNER_COMPUTE,
{},
None,
NORMAL_VNIC),
'test_bm_vlan_unique1': TestCiscoNexusBase.TestConfigObj(
NEXUS_IP_ADDRESS_1,
@ -1090,6 +1122,7 @@ class TestContext(TestCiscoNexusBase):
None,
DEVICE_OWNER_COMPUTE,
baremetal_profile,
None,
BAREMETAL_VNIC),
}
test_configs = collections.OrderedDict(sorted(test_configs.items()))

View File

@ -48,6 +48,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -60,6 +61,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config3':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -72,6 +74,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config4':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -84,6 +87,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config5':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -96,6 +100,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_portchannel':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -108,6 +113,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_dual':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -120,6 +126,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_dhcp':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -132,6 +139,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_DHCP,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_router_ha_intf':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -144,6 +152,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_ROUTER_HA_INTF,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_router_intf':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -156,6 +165,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_ROUTER_INTF,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_router_gw':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -168,6 +178,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_ROUTER_GW,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_portchannel2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -180,6 +191,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_portchannel3':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -192,10 +204,11 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_migrate':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_3,
test_cisco_nexus_base.HOST_NAME_6,
test_cisco_nexus_base.NEXUS_PORT_2,
test_cisco_nexus_base.INSTANCE_1,
@ -204,6 +217,7 @@ class TestCiscoNexusDeviceConfig(object):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
@ -855,6 +869,7 @@ class TestCiscoNexusDeviceFailure(test_cisco_nexus_base.TestCiscoNexusBase,
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
@ -978,9 +993,10 @@ class TestCiscoNexusInitResults(
# set 1 - switch 1.1.1.1 sets eth 1/10 & 1/20 to None
# set 2 - switch 8.8.8.8 sets eth 1/10 & 1/20 to None
# set 3 - switch 4.4.4.4 sets eth 1/3 & portchannel 2 to None
# set 4 - switch 2.2.2.2 sets portchannel 2 to None
# set 5 - switch 6.6.6.6 sets portchannel 2 to None
# set 6 - switch 7.7.7.7 sets portchannel 2 to None
# set 4 - switch 3.3.3.3 sets eth 1/20 to None
# set 5 - switch 2.2.2.2 sets portchannel 2 to None
# set 6 - switch 6.6.6.6 sets portchannel 2 to None
# set 7 - switch 7.7.7.7 sets portchannel 2 to None
'duplicate_init_port_driver_result1': (
[test_cisco_nexus_base.RESULT_INTERFACE.
format('ethernet', '1\/10', 'None'),
@ -988,6 +1004,8 @@ class TestCiscoNexusInitResults(
format('ethernet', '1\/10', 'None'),
test_cisco_nexus_base.RESULT_INTERFACE.
format('ethernet', '1\/3', 'None'),
test_cisco_nexus_base.RESULT_INTERFACE.
format('ethernet', '1\/20', 'None'),
test_cisco_nexus_base.RESULT_INTERFACE.
format('portchannel', '2', 'None'),
test_cisco_nexus_base.RESULT_INTERFACE.
@ -1006,6 +1024,7 @@ class TestCiscoNexusInitResults(
format('portchannel', '2', 'None'),
None,
None,
None,
None])
}
@ -1056,6 +1075,16 @@ class TestCiscoNexusBaremetalResults(
format('ethernet', '1\/10', 267),
test_cisco_nexus_base.RESULT_DEL_VLAN.format(267)]),
'add_vm_port_ethernet_driver_result': (
[test_cisco_nexus_base.RESULT_ADD_VLAN.format(265),
test_cisco_nexus_base.RESULT_ADD_INTERFACE.
format('ethernet', '1\/10', 265)]),
'delete_vm_port_ethernet_driver_result': (
[test_cisco_nexus_base.RESULT_DEL_INTERFACE.
format('ethernet', '1\/10', 265),
test_cisco_nexus_base.RESULT_DEL_VLAN.format(265)]),
'add_port_channel_driver_result': (
[test_cisco_nexus_base.RESULT_ADD_VLAN.format(267),
test_cisco_nexus_base.RESULT_ADD_INTERFACE.
@ -1128,7 +1157,21 @@ class TestCiscoNexusBaremetalDevice(test_cisco_nexus_base.TestCiscoNexusBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_BAREMETAL,
baremetal_profile,
test_cisco_nexus_base.HOST_NAME_Baremetal + '1',
test_cisco_nexus_base.BAREMETAL_VNIC),
'test_config_vm':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.HOST_NAME_Baremetal + '1',
test_cisco_nexus_base.NEXUS_BAREMETAL_PORT_1,
test_cisco_nexus_base.INSTANCE_2,
test_cisco_nexus_base.VLAN_ID_2,
test_cisco_nexus_base.NO_VXLAN_ID,
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_config_native':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
@ -1140,6 +1183,7 @@ class TestCiscoNexusBaremetalDevice(test_cisco_nexus_base.TestCiscoNexusBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_BAREMETAL,
baremetal_profile_is_native,
None,
test_cisco_nexus_base.BAREMETAL_VNIC),
}
@ -1158,69 +1202,69 @@ class TestCiscoNexusBaremetalDevice(test_cisco_nexus_base.TestCiscoNexusBase):
'channel-group 469 mode active'}
self.mock_ncclient.configure_mock(**data_xml)
def test_create_delete_basic_ethernet_port(self):
def test_create_delete_basic_bm_ethernet_port_and_vm(self):
"""Basic creation and deletion test of 1 ethernet port."""
# nbr_of_bindings includes reserved port binding
self._basic_create_verify_port_vlan(
'test_config1',
self.results.get_test_results(
'add_port_ethernet_driver_result'),
2)
'add_port_ethernet_driver_result'))
# Clean all the ncclient mock_calls so we can evaluate
# results of delete operations.
# Clean all driver mock_calls so we can evaluate next
# set of results.
self.mock_ncclient.reset_mock()
# nbr_of_bindings includes reserved port binding
self._basic_create_verify_port_vlan(
'test_config_vm',
self.results.get_test_results(
'add_vm_port_ethernet_driver_result'),
nbr_of_bindings=2)
self._basic_delete_verify_port_vlan(
'test_config_vm',
self.results.get_test_results(
'delete_vm_port_ethernet_driver_result'),
nbr_of_bindings=1)
self._basic_delete_verify_port_vlan(
'test_config1',
self.results.get_test_results(
'delete_port_ethernet_driver_result'),
nbr_of_bindings=1)
'delete_port_ethernet_driver_result'))
def test_create_delete_basic_port_channel(self):
"""Basic creation and deletion test of 1 port-channel."""
self._init_port_channel()
# nbr_of_bindings includes reserved port binding
self._basic_create_verify_port_vlan(
'test_config1',
self.results.get_test_results(
'add_port_channel_driver_result'),
2)
'add_port_channel_driver_result'))
# Clean all the ncclient mock_calls so we can evaluate
# results of delete operations.
self.mock_ncclient.reset_mock()
# nbr_of_bindings includes reserved port binding
self._basic_delete_verify_port_vlan(
'test_config1',
self.results.get_test_results(
'delete_port_channel_driver_result'),
nbr_of_bindings=1)
'delete_port_channel_driver_result'))
def test_create_delete_basic_eth_port_is_native(self):
"""Basic creation and deletion test of 1 ethernet port."""
# nbr_of_bindings includes reserved port binding
self._basic_create_verify_port_vlan(
'test_config_native',
self.results.get_test_results(
'add_port_ethernet_native_driver_result'),
2)
'add_port_ethernet_native_driver_result'))
# Clean all the ncclient mock_calls so we can evaluate
# results of delete operations.
self.mock_ncclient.reset_mock()
# nbr_of_bindings includes reserved port binding
self._basic_delete_verify_port_vlan(
'test_config_native',
self.results.get_test_results(
'delete_port_ethernet_native_driver_result'),
nbr_of_bindings=1)
'delete_port_ethernet_native_driver_result'))
def test_create_delete_switch_ip_not_defined(self):
"""Create/delete of 1 ethernet port switchinfo is string."""
@ -1258,28 +1302,142 @@ class TestCiscoNexusBaremetalDevice(test_cisco_nexus_base.TestCiscoNexusBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_BAREMETAL,
baremetal_profile_no_switch_ip,
test_cisco_nexus_base.HOST_NAME_Baremetal + '3',
test_cisco_nexus_base.BAREMETAL_VNIC),
}
# nbr_of_bindings includes reserved port binding
self._basic_create_verify_port_vlan(
'',
self.results.get_test_results(
'add_port_ethernet_driver_result'), 2,
'add_port_ethernet_driver_result'), 1,
other_test=local_test_configs['test_config1'])
# Clean all the ncclient mock_calls so we can evaluate
# results of delete operations.
self.mock_ncclient.reset_mock()
# nbr_of_bindings includes reserved port binding
self._basic_delete_verify_port_vlan(
'',
self.results.get_test_results(
'delete_port_ethernet_driver_result'),
nbr_of_bindings=1,
nbr_of_bindings=0,
other_test=local_test_configs['test_config1'])
def test_new_host_mapping_db(self):
nexus_db_v2.add_host_mapping(
"host-1", "1.1.1.1", "ethernet:1/1", 0, False)
nexus_db_v2.add_host_mapping(
"host-1", "2.2.2.2", "ethernet:1/1", 0, False)
nexus_db_v2.add_host_mapping(
"host-2", "1.1.1.1", "ethernet:2/2", 0, False)
nexus_db_v2.add_host_mapping(
"host-3", "3.3.3.3", "ethernet:3/3", 0, True)
nexus_db_v2.add_host_mapping(
"host-4", "4.4.4.4", "ethernet:4/4", 0, True)
# Do a get 1.1.1.1 and verify only host-1 is returned
mappings = nexus_db_v2.get_switch_if_host_mappings(
"1.1.1.1", "ethernet:1/1")
self.assertEqual(
len(mappings),
1,
"Unexpected number of switch interface mappings")
for map in mappings:
self.assertEqual(
map.host_id,
"host-1",
"Expecting host-1 returned from "
"get_switch_if_host_mappings")
# Do a get on host-1 and verify 2 entries returned
mappings = nexus_db_v2.get_host_mappings("host-1")
self.assertEqual(
len(mappings),
2,
"Unexpected number of host mappings")
for map in mappings:
self.assertEqual(
map.host_id,
"host-1",
"Expecting host-1 returned from "
"get_host_mappings")
self.assertEqual(
map.if_id,
"ethernet:1/1",
"Expecting interface returned from "
"get_host_mappings")
# Do a get on switch 1.1.1.1 and verify 2 entries returned
mappings = nexus_db_v2.get_switch_host_mappings("1.1.1.1")
self.assertEqual(
len(mappings),
2,
"Unexpected number of switch mappings")
for map in mappings:
self.assertEqual(
map.switch_ip,
"1.1.1.1",
"Expecting switch_ip returned from "
"get_switch_host_mappings")
# Update host mapping by changing the ch_grp
nexus_db_v2.update_host_mapping(
"host-2",
"ethernet:2/2",
"1.1.1.1",
2)
mappings = nexus_db_v2.get_host_mappings("host-2")
self.assertEqual(
len(mappings),
1,
"Unexpected number of host mappings aft update")
for map in mappings:
self.assertEqual(
map.host_id,
"host-2",
"Expecting host-2 returned from "
"get_host_mappings")
self.assertEqual(
map.ch_grp,
2,
"Expecting ch_grp 2 returned from "
"get_host_mappings for host 2")
# remove 1 host mapping
nexus_db_v2.remove_host_mapping(
"ethernet:2/2", "1.1.1.1")
# Verify it is gone
self.assertRaises(
exceptions.NexusHostMappingNotFound,
nexus_db_v2.get_host_mappings,
"host-2")
# remove all static host mapping
nexus_db_v2.remove_all_static_host_mappings()
# Verify it is gone
mappings = nexus_db_v2.get_all_host_mappings()
self.assertEqual(
len(mappings),
2,
"Unexpected number of non-static entries")
for map in mappings:
self.assertFalse(
map.is_static,
"Expecting remaining hosts from"
"get_all_host_mappings to be dynamic")
# remove host mappings
nexus_db_v2.remove_host_mapping(
"ethernet:1/1", "2.2.2.2")
nexus_db_v2.remove_host_mapping(
"ethernet:1/1", "1.1.1.1")
# Verify it is gone
self.assertRaises(
exceptions.NexusHostMappingNotFound,
nexus_db_v2.get_host_mappings,
"host-1")
class TestCiscoNexusNonCacheSshDevice(
test_cisco_nexus_base.TestCiscoNexusBase):
@ -1300,6 +1458,7 @@ class TestCiscoNexusNonCacheSshDevice(
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}

View File

@ -19,6 +19,8 @@ import mock
from oslo_config import cfg
from networking_cisco import backwards_compatibility as bc
from networking_cisco.plugins.ml2.drivers.cisco.nexus import (
constants as const)
from networking_cisco.plugins.ml2.drivers.cisco.nexus import exceptions
from networking_cisco.plugins.ml2.drivers.cisco.nexus import nexus_db_v2
@ -50,6 +52,7 @@ class TestCiscoNexusVxlanDeviceConfig(object):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_vxlan_config2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -62,10 +65,11 @@ class TestCiscoNexusVxlanDeviceConfig(object):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_vxlan_config3':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_6,
test_cisco_nexus_base.HOST_NAME_3,
test_cisco_nexus_base.NEXUS_PORT_1,
test_cisco_nexus_base.INSTANCE_1,
@ -74,10 +78,11 @@ class TestCiscoNexusVxlanDeviceConfig(object):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_vxlan_config4':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_2,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_7,
test_cisco_nexus_base.HOST_NAME_3,
test_cisco_nexus_base.NEXUS_DUAL_2,
test_cisco_nexus_base.INSTANCE_1,
@ -86,10 +91,11 @@ class TestCiscoNexusVxlanDeviceConfig(object):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_vxlan_config5':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_8,
test_cisco_nexus_base.HOST_NAME_4,
test_cisco_nexus_base.NEXUS_PORT_1,
test_cisco_nexus_base.INSTANCE_1,
@ -98,10 +104,11 @@ class TestCiscoNexusVxlanDeviceConfig(object):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_vxlan_config6':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_8,
test_cisco_nexus_base.HOST_NAME_5,
test_cisco_nexus_base.NEXUS_PORT_2,
test_cisco_nexus_base.INSTANCE_1,
@ -110,6 +117,7 @@ class TestCiscoNexusVxlanDeviceConfig(object):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
@ -195,7 +203,22 @@ class TestCiscoNexusVxlanResults(
format(1, 70001, 265),
test_cisco_nexus_base.RESULT_DEL_INTERFACE.
format('ethernet', '1\/20', 265),
test_cisco_nexus_base.RESULT_DEL_VLAN.format(265)])
test_cisco_nexus_base.RESULT_DEL_VLAN.format(265)]),
'add_port_driver_result4': (
[test_cisco_nexus_base.RESULT_ADD_NVE_INTERFACE.
format(1, 70000, '255.1.1.1'),
test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.
format(267, 70000),
test_cisco_nexus_base.RESULT_ADD_INTERFACE.
format('ethernet', '1\/10', 267)]),
'delete_port_driver_result4': (
[test_cisco_nexus_base.RESULT_DEL_NVE_INTERFACE.
format(1, 70000, 267),
test_cisco_nexus_base.RESULT_DEL_INTERFACE.
format('ethernet', '1\/10', 267),
test_cisco_nexus_base.RESULT_DEL_VLAN.format(267)])
}
@ -311,6 +334,7 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_vxlan_config_no_mcast':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -323,6 +347,7 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
test_list = ('test_vxlan_config_no_vni',
@ -363,7 +388,7 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
"""
self._cisco_mech_driver._nexus_switches.pop(
(test_cisco_nexus_base.NEXUS_IP_ADDRESS_1, 'physnet'))
(test_cisco_nexus_base.NEXUS_IP_ADDRESS_1, const.PHYSNET))
try:
self._bind_port(self.test_configs['test_vxlan_config1'])
@ -398,8 +423,8 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
'add_port_driver_result3'))
for switch_ip, nbr_bind in [
(test_cisco_nexus_base.NEXUS_IP_ADDRESS_1, 1),
(test_cisco_nexus_base.NEXUS_IP_ADDRESS_2, 2)]:
(test_cisco_nexus_base.NEXUS_IP_ADDRESS_6, 1),
(test_cisco_nexus_base.NEXUS_IP_ADDRESS_7, 2)]:
bindings = nexus_db_v2.get_nexusvlan_binding(
test_cisco_nexus_base.VLAN_ID_1,
switch_ip)
@ -416,8 +441,8 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
'delete_port_driver_result3'))
for switch_ip in [
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_2]:
test_cisco_nexus_base.NEXUS_IP_ADDRESS_6,
test_cisco_nexus_base.NEXUS_IP_ADDRESS_7]:
try:
bindings = nexus_db_v2.get_nexusvlan_binding(
test_cisco_nexus_base.VLAN_ID_1,
@ -437,7 +462,7 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
self._basic_create_verify_port_vlan(
'test_vxlan_config5',
self.results.get_test_results(
'add_port_driver_result'))
'add_port_driver_result4'))
self._create_port(
self.test_configs['test_vxlan_config6'],
@ -447,7 +472,7 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
'add_port_driver_result2'))
binding = nexus_db_v2.get_nve_switch_bindings(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1)
test_cisco_nexus_base.NEXUS_IP_ADDRESS_8)
self.assertEqual(2, len(binding))
# Clean all the ncclient mock_calls so we can evaluate
@ -463,11 +488,11 @@ class TestCiscoNexusVxlanDevice(test_cisco_nexus_base.TestCiscoNexusBase,
self._basic_delete_verify_port_vlan(
'test_vxlan_config5',
self.results.get_test_results(
'delete_port_driver_result'))
'delete_port_driver_result4'))
try:
binding = nexus_db_v2.get_nve_switch_bindings(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1)
test_cisco_nexus_base.NEXUS_IP_ADDRESS_8)
except exceptions.NexusPortBindingNotFound:
binding = []
self.assertEqual(0, len(binding))

View File

@ -145,6 +145,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_unique2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -157,6 +158,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_duplvlan1':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -169,6 +171,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_duplvlan2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -181,6 +184,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_duplport1':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -193,6 +197,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_duplport2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -205,6 +210,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_dual':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -217,6 +223,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_dual2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -229,6 +236,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
'test_replay_vxlan_unique1':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -241,6 +249,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
test_cisco_nexus_base.MCAST_GROUP,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
test_configs = collections.OrderedDict(sorted(test_configs.items()))
@ -695,6 +704,7 @@ class TestCiscoNexusReplay(test_cisco_nexus_base.TestCiscoNexusReplayBase):
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC)
self._cisco_mech_driver.set_switch_ip_and_active_state(
tmp_cfg.nexus_ip_addr, const.SWITCH_ACTIVE)
@ -1060,6 +1070,7 @@ class TestCiscoNexusBaremetalReplay(
None,
test_cisco_nexus_base.DEVICE_OWNER_BAREMETAL,
baremetal_profile,
test_cisco_nexus_base.HOST_NAME_Baremetal + '1',
test_cisco_nexus_base.BAREMETAL_VNIC),
'test_replay_unique2':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -1072,6 +1083,7 @@ class TestCiscoNexusBaremetalReplay(
None,
test_cisco_nexus_base.DEVICE_OWNER_BAREMETAL,
baremetal_profile,
test_cisco_nexus_base.HOST_NAME_Baremetal + '1',
test_cisco_nexus_base.BAREMETAL_VNIC),
'test_replay_unique_native1':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
@ -1084,7 +1096,21 @@ class TestCiscoNexusBaremetalReplay(
None,
test_cisco_nexus_base.DEVICE_OWNER_BAREMETAL,
baremetal_profile_is_native,
test_cisco_nexus_base.HOST_NAME_Baremetal + '1',
test_cisco_nexus_base.BAREMETAL_VNIC),
'test_config_vm':
test_cisco_nexus_base.TestCiscoNexusBase.TestConfigObj(
test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
test_cisco_nexus_base.HOST_NAME_Baremetal + '1',
test_cisco_nexus_base.NEXUS_BAREMETAL_PORT_1,
test_cisco_nexus_base.INSTANCE_2,
test_cisco_nexus_base.VLAN_ID_2,
test_cisco_nexus_base.NO_VXLAN_ID,
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
test_configs = collections.OrderedDict(sorted(test_configs.items()))
@ -1112,19 +1138,20 @@ class TestCiscoNexusBaremetalReplay(
first_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_add1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_add2'),
'nbr_db_entries': 3}
'nbr_db_entries': 2}
first_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1,
'nbr_db_mappings': 1}
second_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del2'),
'nbr_db_entries': 1}
'nbr_db_entries': 0}
self._process_replay(
'test_replay_unique1',
@ -1138,25 +1165,58 @@ class TestCiscoNexusBaremetalReplay(
first_del,
second_del)
def test_replay_unique_ethernet_port_and_vm(self):
"""Provides replay data and result data for unique ports. """
first_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_add1'),
'nbr_db_entries': 1}
second_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_add2'),
'nbr_db_entries': 2}
first_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del1'),
'nbr_db_entries': 1}
second_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del2'),
'nbr_db_entries': 0}
self._process_replay(
'test_replay_unique1',
'test_config_vm',
self.results.get_test_results(
'driver_result_unique_eth_init'),
first_add,
second_add,
self.results.get_test_results(
'driver_result_unique_2vlan_replay'),
first_del,
second_del)
def test_replay_unique_vPC_ports(self):
"""Provides replay data and result data for unique ports. """
first_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_add1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_add2'),
'nbr_db_entries': 3}
'nbr_db_entries': 2}
first_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_del1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1,
'nbr_db_mappings': 1}
second_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_del2'),
'nbr_db_entries': 1}
'nbr_db_entries': 0}
self._init_port_channel(469)
@ -1175,6 +1235,8 @@ class TestCiscoNexusBaremetalReplay(
def test_replay_unique_vPC_ports_chg_vPC_nbr(self):
"""Provides replay data and result data for unique ports. """
self.skipTest("Disable until HN-72 automated vPC implemented")
def replay_init():
# This causes port-channel 470 to get configured instead.
self._init_port_channel(470)
@ -1182,19 +1244,19 @@ class TestCiscoNexusBaremetalReplay(
first_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_add1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_add2'),
'nbr_db_entries': 3}
'nbr_db_entries': 2}
first_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC470_del1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC470_del2'),
'nbr_db_entries': 1}
'nbr_db_entries': 0}
# This is to cause port-channel 469 to get configured
self._init_port_channel(469)
@ -1216,6 +1278,8 @@ class TestCiscoNexusBaremetalReplay(
def test_replay_unique_vPC_ports_chg_to_enet(self):
"""Provides replay data and result data for unique ports. """
self.skipTest("Disable until HN-72 automated vPC implemented")
def replay_init():
# This causes port-channel to get replaced with enet
# by eliminating channel-group config from enet config.
@ -1227,19 +1291,19 @@ class TestCiscoNexusBaremetalReplay(
first_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_add1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_vPC_add2'),
'nbr_db_entries': 3}
'nbr_db_entries': 2}
first_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del1'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del2'),
'nbr_db_entries': 1}
'nbr_db_entries': 0}
self._init_port_channel(469)
@ -1263,19 +1327,20 @@ class TestCiscoNexusBaremetalReplay(
first_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_native_port_ethernet_add'),
'nbr_db_entries': 2}
'nbr_db_entries': 1}
second_add = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_add1'),
'nbr_db_entries': 3}
'nbr_db_entries': 2}
first_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_eth_del2'),
'nbr_db_entries': 2}
'nbr_db_entries': 1,
'nbr_db_mappings': 1}
second_del = {
'driver_results': self.results.get_test_results(
'driver_result_unique_native_port_ethernet_del'),
'nbr_db_entries': 1}
'nbr_db_entries': 0}
self._process_replay(
'test_replay_unique_native1',
@ -1308,6 +1373,7 @@ class TestCiscoNexusNonCachedSshReplay(
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC),
}
@ -1324,6 +1390,7 @@ class TestCiscoNexusNonCachedSshReplay(
None,
test_cisco_nexus_base.DEVICE_OWNER_COMPUTE,
{},
None,
test_cisco_nexus_base.NORMAL_VNIC)
self._cisco_mech_driver.set_switch_ip_and_active_state(

View File

@ -208,11 +208,11 @@ class TestCiscoNexusRestDeviceResults(base.TestCiscoNexusBaseResults):
],
'migrate_add_host2_driver_result': [
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_3,
(snipp.BODY_VLAN_ADD % 267),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/20]'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_3,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+267')),
base.POST]
],
@ -287,11 +287,6 @@ class TestCiscoNexusRestInitResults(base.TestCiscoNexusBaseResults):
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '')),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/20]'),
base.NEXUS_IP_ADDRESS_1,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '')),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '')),
@ -312,6 +307,11 @@ class TestCiscoNexusRestInitResults(base.TestCiscoNexusBaseResults):
(snipp.BODY_TRUNKVLAN % ('pcAggrIf', '')),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/20]'),
base.NEXUS_IP_ADDRESS_3,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '')),
base.POST],
[(snipp.PATH_IF % 'aggr-[po2]'),
base.NEXUS_IP_ADDRESS_2,
(snipp.BODY_TRUNKVLAN % ('pcAggrIf', '')),
@ -434,6 +434,28 @@ class TestCiscoNexusRestBaremetalResults(base.TestCiscoNexusBaseResults):
base.DELETE]
],
'add_vm_port_ethernet_driver_result': [
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_1,
(snipp.BODY_VLAN_ADD % 265),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_1,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+265')),
base.POST]
],
'delete_vm_port_ethernet_driver_result': [
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_1,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '-265')),
base.POST],
[(snipp.PATH_VLAN % '265'),
base.NEXUS_IP_ADDRESS_1,
'',
base.DELETE]
],
'add_port_channel_driver_result': [
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_1,
@ -550,9 +572,9 @@ class TestCiscoNexusRestBaremetalDevice(
super(TestCiscoNexusRestBaremetalDevice, self).setUp()
self.results = TestCiscoNexusRestBaremetalResults()
def test_create_delete_basic_ethernet_port(self):
def test_create_delete_basic_bm_ethernet_port_and_vm(self):
(super(TestCiscoNexusRestBaremetalDevice, self).
test_create_delete_basic_ethernet_port())
test_create_delete_basic_bm_ethernet_port_and_vm())
def test_create_delete_basic_port_channel(self):
(super(TestCiscoNexusRestBaremetalDevice, self).

View File

@ -99,106 +99,137 @@ class TestCiscoNexusRestVxlanResults(base.TestCiscoNexusBaseResults):
'add_port_driver_result3': [
[(snipp.PATH_VNI_UPDATE % ('1', '70000')),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_6,
(snipp.BODY_VNI_UPDATE % (
'70000', '70000', '70000',
base.MCAST_GROUP)),
base.POST],
[(snipp.PATH_VNI_UPDATE % ('1', '70000')),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_VNI_UPDATE % (
'70000', '70000', '70000',
base.MCAST_GROUP)),
base.POST],
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_6,
(snipp.BODY_VXLAN_ADD % (267, 70000)),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_6,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+267')),
base.POST],
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_VXLAN_ADD % (267, 70000)),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/2]'),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+267')),
base.POST],
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_VXLAN_ADD % (267, 70000)),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/3]'),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+267')),
base.POST]
],
'delete_port_driver_result3': [
[(snipp.PATH_VNI_UPDATE % ('1', '70000')),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_6,
'',
base.DELETE],
[(snipp.PATH_VNI_UPDATE % ('1', '70000')),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
'',
base.DELETE],
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_6,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '-267')),
base.POST],
[(snipp.PATH_VLAN % '267'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_6,
'',
base.DELETE],
[(snipp.PATH_IF % 'phys-[eth1/2]'),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '-267')),
base.POST],
[(snipp.PATH_VLAN % '267'),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
'',
base.DELETE],
[(snipp.PATH_IF % 'phys-[eth1/3]'),
base.NEXUS_IP_ADDRESS_2,
base.NEXUS_IP_ADDRESS_7,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '-267')),
base.POST]
base.POST],
],
'add_port_driver_result2': [
[(snipp.PATH_VNI_UPDATE % ('1', '70001')),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_VNI_UPDATE % (
'70001', '70001', '70001',
base.MCAST_GROUP)),
base.POST],
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_VXLAN_ADD % (265, 70001)),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/20]'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+265')),
base.POST]
],
'delete_port_driver_result2': [
[(snipp.PATH_VNI_UPDATE % ('1', '70001')),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_8,
'',
base.DELETE],
[(snipp.PATH_IF % 'phys-[eth1/20]'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '-265')),
base.POST],
[(snipp.PATH_VLAN % '265'),
base.NEXUS_IP_ADDRESS_1,
base.NEXUS_IP_ADDRESS_8,
'',
base.DELETE]
],
'add_port_driver_result4': [
[(snipp.PATH_VNI_UPDATE % ('1', '70000')),
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_VNI_UPDATE % (
'70000', '70000', '70000',
base.MCAST_GROUP)),
base.POST],
[snipp.PATH_VLAN_ALL,
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_VXLAN_ADD % (267, 70000)),
base.POST],
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '+267')),
base.POST]
],
'delete_port_driver_result4': [
[(snipp.PATH_VNI_UPDATE % ('1', '70000')),
base.NEXUS_IP_ADDRESS_8,
'',
base.DELETE],
[(snipp.PATH_IF % 'phys-[eth1/10]'),
base.NEXUS_IP_ADDRESS_8,
(snipp.BODY_TRUNKVLAN % ('l1PhysIf', '-267')),
base.POST],
[(snipp.PATH_VLAN % '267'),
base.NEXUS_IP_ADDRESS_8,
'',
base.DELETE]
],
}