Fixes Tempest XML test failures for Cisco N1kv plugin

Renamed N1kv_profile class to N1kv.
Modified N1kv attribute extension class to fix XML namespace issues.

Change-Id: I29b541730fc95c5e16667b64efd180be31e25b17
Closes-Bug: #1282352
This commit is contained in:
Sourabh Patwardhan 2014-02-19 18:16:47 -08:00
parent 46e2c5b4ae
commit 546259bce3
4 changed files with 56 additions and 55 deletions

View File

@ -19,6 +19,7 @@
# @author: Aruna Kushwaha, Cisco Systems, Inc.
# @author: Sergey Sudakovich, Cisco Systems, Inc.
from neutron.api import extensions
from neutron.api.v2 import attributes
@ -56,7 +57,7 @@ EXTENDED_ATTRIBUTES_2_0 = {
}
class N1kv_profile(object):
class N1kv(extensions.ExtensionDescriptor):
"""Extension class supporting N1kv profiles.
@ -80,11 +81,11 @@ class N1kv_profile(object):
@classmethod
def get_name(cls):
return "n1kv_profile"
return "n1kv"
@classmethod
def get_alias(cls):
return "n1kv_profile"
return "n1kv"
@classmethod
def get_description(cls):
@ -92,7 +93,7 @@ class N1kv_profile(object):
@classmethod
def get_namespace(cls):
return "http://docs.openstack.org/ext/n1kv_profile/api/v2.0"
return "http://docs.openstack.org/ext/n1kv/api/v2.0"
@classmethod
def get_updated(cls):

View File

@ -28,7 +28,7 @@ from neutron.plugins.cisco.common import cisco_constants as c_const
from neutron.plugins.cisco.common import cisco_credentials_v2 as c_cred
from neutron.plugins.cisco.common import cisco_exceptions as c_exc
from neutron.plugins.cisco.db import network_db_v2
from neutron.plugins.cisco.extensions import n1kv_profile
from neutron.plugins.cisco.extensions import n1kv
from neutron import wsgi
LOG = logging.getLogger(__name__)
@ -180,7 +180,7 @@ class Client(object):
'subType': overlay_subtype,
'tenantId': network['tenant_id']}
if overlay_subtype == c_const.NETWORK_SUBTYPE_NATIVE_VXLAN:
body['groupIp'] = network[n1kv_profile.MULTICAST_IP]
body['groupIp'] = network[n1kv.MULTICAST_IP]
return self._post(self.bridge_domains_path,
body=body)

View File

@ -48,7 +48,7 @@ from neutron.plugins.cisco.common import cisco_exceptions
from neutron.plugins.cisco.common import config as c_conf
from neutron.plugins.cisco.db import n1kv_db_v2
from neutron.plugins.cisco.db import network_db_v2
from neutron.plugins.cisco.extensions import n1kv_profile
from neutron.plugins.cisco.extensions import n1kv
from neutron.plugins.cisco.n1kv import n1kv_client
from neutron.plugins.common import constants as svc_constants
@ -146,7 +146,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
# bulk operations.
__native_bulk_support = False
supported_extension_aliases = ["provider", "agent",
"n1kv_profile", "network_profile",
"n1kv", "network_profile",
"policy_profile", "external-net", "router",
"credential"]
@ -288,18 +288,18 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
if binding.network_type == c_const.NETWORK_TYPE_OVERLAY:
network[providernet.PHYSICAL_NETWORK] = None
network[providernet.SEGMENTATION_ID] = binding.segmentation_id
network[n1kv_profile.MULTICAST_IP] = binding.multicast_ip
network[n1kv.MULTICAST_IP] = binding.multicast_ip
elif binding.network_type == c_const.NETWORK_TYPE_VLAN:
network[providernet.PHYSICAL_NETWORK] = binding.physical_network
network[providernet.SEGMENTATION_ID] = binding.segmentation_id
elif binding.network_type == c_const.NETWORK_TYPE_TRUNK:
network[providernet.PHYSICAL_NETWORK] = binding.physical_network
network[providernet.SEGMENTATION_ID] = None
network[n1kv_profile.MULTICAST_IP] = None
network[n1kv.MULTICAST_IP] = None
elif binding.network_type == c_const.NETWORK_TYPE_MULTI_SEGMENT:
network[providernet.PHYSICAL_NETWORK] = None
network[providernet.SEGMENTATION_ID] = None
network[n1kv_profile.MULTICAST_IP] = None
network[n1kv.MULTICAST_IP] = None
def _process_provider_create(self, context, attrs):
network_type = attrs.get(providernet.NETWORK_TYPE)
@ -537,9 +537,9 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
member_dict = {'segment': net['name'],
'dot1qtag': dot1qtag}
trunk_list.append(member_dict)
if oper == n1kv_profile.SEGMENT_ADD:
if oper == n1kv.SEGMENT_ADD:
network['add_segment_list'] = trunk_list
elif oper == n1kv_profile.SEGMENT_DEL:
elif oper == n1kv.SEGMENT_DEL:
network['del_segment_list'] = trunk_list
def _parse_multi_segments(self, context, attrs, param):
@ -649,23 +649,23 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
elif binding.network_type == c_const.NETWORK_TYPE_MULTI_SEGMENT:
members = n1kv_db_v2.get_multi_segment_members(context.session,
network['id'])
network[n1kv_profile.MEMBER_SEGMENTS] = members
network[n1kv.MEMBER_SEGMENTS] = members
def _extend_network_dict_profile(self, context, network):
"""Add the extended parameter network profile to the network."""
binding = n1kv_db_v2.get_network_binding(context.session,
network['id'])
network[n1kv_profile.PROFILE_ID] = binding.profile_id
network[n1kv.PROFILE_ID] = binding.profile_id
def _extend_port_dict_profile(self, context, port):
"""Add the extended parameter port profile to the port."""
binding = n1kv_db_v2.get_port_binding(context.session,
port['id'])
port[n1kv_profile.PROFILE_ID] = binding.profile_id
port[n1kv.PROFILE_ID] = binding.profile_id
def _process_network_profile(self, context, network):
"""Validate network profile exists."""
profile_id = network.get(n1kv_profile.PROFILE_ID)
profile_id = network.get(n1kv.PROFILE_ID)
profile_id_set = attributes.is_attr_set(profile_id)
if not profile_id_set:
profile_name = c_conf.CISCO_N1K.default_network_profile
@ -677,7 +677,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
def _process_policy_profile(self, context, attrs):
"""Validates whether policy profile exists."""
profile_id = attrs.get(n1kv_profile.PROFILE_ID)
profile_id = attrs.get(n1kv.PROFILE_ID)
profile_id_set = attributes.is_attr_set(profile_id)
if not profile_id_set:
msg = _("n1kv:profile_id does not exist")
@ -755,13 +755,13 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
"""
LOG.debug(_('_send_create_network_request: %s'), network['id'])
profile = self.get_network_profile(context,
network[n1kv_profile.PROFILE_ID])
network[n1kv.PROFILE_ID])
n1kvclient = n1kv_client.Client()
if network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_OVERLAY:
n1kvclient.create_bridge_domain(network, profile['sub_type'])
if network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_TRUNK:
self._populate_member_segments(context, network, segment_pairs,
n1kv_profile.SEGMENT_ADD)
n1kv.SEGMENT_ADD)
network['del_segment_list'] = []
if profile['sub_type'] == c_const.NETWORK_TYPE_OVERLAY:
encap_dict = {'name': (network['name'] +
@ -788,7 +788,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
LOG.debug(_('_send_update_network_request: %s'), network['id'])
db_session = context.session
profile = n1kv_db_v2.get_network_profile(
db_session, network[n1kv_profile.PROFILE_ID])
db_session, network[n1kv.PROFILE_ID])
n1kvclient = n1kv_client.Client()
body = {'publishName': network['name'],
'id': network['id'],
@ -800,9 +800,9 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
'delSegments': []}
if network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_TRUNK:
self._populate_member_segments(context, network, add_segments,
n1kv_profile.SEGMENT_ADD)
n1kv.SEGMENT_ADD)
self._populate_member_segments(context, network, del_segments,
n1kv_profile.SEGMENT_DEL)
n1kv.SEGMENT_DEL)
body['mode'] = c_const.NETWORK_TYPE_TRUNK
body['segmentType'] = profile['sub_type']
body['addSegments'] = network['add_segment_list']
@ -840,7 +840,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
n1kvclient.delete_bridge_domain(name)
elif network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_TRUNK:
profile = self.get_network_profile(
context, network[n1kv_profile.PROFILE_ID])
context, network[n1kv.PROFILE_ID])
if profile['sub_type'] == c_const.NETWORK_TYPE_OVERLAY:
profile_name = (network['id'] +
c_const.ENCAPSULATION_PROFILE_SUFFIX)
@ -905,18 +905,18 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
try:
vm_network = n1kv_db_v2.get_vm_network(
context.session,
port[n1kv_profile.PROFILE_ID],
port[n1kv.PROFILE_ID],
port['network_id'])
except cisco_exceptions.VMNetworkNotFound:
policy_profile = n1kv_db_v2.get_policy_profile(
context.session, port[n1kv_profile.PROFILE_ID])
context.session, port[n1kv.PROFILE_ID])
vm_network_name = (c_const.VM_NETWORK_NAME_PREFIX +
str(port[n1kv_profile.PROFILE_ID]) +
str(port[n1kv.PROFILE_ID]) +
"_" + str(port['network_id']))
port_count = 1
n1kv_db_v2.add_vm_network(context.session,
vm_network_name,
port[n1kv_profile.PROFILE_ID],
port[n1kv.PROFILE_ID],
port['network_id'],
port_count)
n1kvclient = n1kv_client.Client()
@ -958,7 +958,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
LOG.debug(_('_send_delete_port_request: %s'), id)
port = self.get_port(context, id)
vm_network = n1kv_db_v2.get_vm_network(context.session,
port[n1kv_profile.PROFILE_ID],
port[n1kv.PROFILE_ID],
port['network_id'])
vm_network['port_count'] -= 1
n1kv_db_v2.update_vm_network_port_count(
@ -967,7 +967,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
n1kvclient.delete_n1kv_port(vm_network['name'], id)
if vm_network['port_count'] == 0:
n1kv_db_v2.delete_vm_network(context.session,
port[n1kv_profile.PROFILE_ID],
port[n1kv.PROFILE_ID],
port['network_id'])
n1kvclient.delete_vm_network(vm_network['name'])
@ -1015,14 +1015,14 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
if network_type == c_const.NETWORK_TYPE_MULTI_SEGMENT:
segment_pairs = (
self._parse_multi_segments(context, network['network'],
n1kv_profile.SEGMENT_ADD))
n1kv.SEGMENT_ADD))
LOG.debug(_('Seg list %s '), segment_pairs)
elif network_type == c_const.NETWORK_TYPE_TRUNK:
network_profile = self.get_network_profile(context,
profile_id)
segment_pairs = (
self._parse_trunk_segments(context, network['network'],
n1kv_profile.SEGMENT_ADD,
n1kv.SEGMENT_ADD,
physical_network,
network_profile['sub_type']
))
@ -1093,12 +1093,12 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
if binding.network_type == c_const.NETWORK_TYPE_MULTI_SEGMENT:
add_segments = (
self._parse_multi_segments(context, network['network'],
n1kv_profile.SEGMENT_ADD))
n1kv.SEGMENT_ADD))
n1kv_db_v2.add_multi_segment_binding(session,
net['id'], add_segments)
del_segments = (
self._parse_multi_segments(context, network['network'],
n1kv_profile.SEGMENT_DEL))
n1kv.SEGMENT_DEL))
self._send_add_multi_segment_request(context, net['id'],
add_segments)
self._send_del_multi_segment_request(context, net['id'],
@ -1110,14 +1110,14 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
binding.profile_id)
add_segments = (
self._parse_trunk_segments(context, network['network'],
n1kv_profile.SEGMENT_ADD,
n1kv.SEGMENT_ADD,
binding.physical_network,
network_profile['sub_type']))
n1kv_db_v2.add_trunk_segment_binding(session,
net['id'], add_segments)
del_segments = (
self._parse_trunk_segments(context, network['network'],
n1kv_profile.SEGMENT_DEL,
n1kv.SEGMENT_DEL,
binding.physical_network,
network_profile['sub_type']))
n1kv_db_v2.del_trunk_segment_binding(session,
@ -1226,8 +1226,8 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
port['port']['n1kv:profile_id'] = p_profile['id']
profile_id_set = False
if n1kv_profile.PROFILE_ID in port['port']:
profile_id = port['port'].get(n1kv_profile.PROFILE_ID)
if n1kv.PROFILE_ID in port['port']:
profile_id = port['port'].get(n1kv.PROFILE_ID)
profile_id_set = attributes.is_attr_set(profile_id)
if not profile_id_set:

View File

@ -27,7 +27,7 @@ import neutron.db.api as db
from neutron.plugins.cisco.db import n1kv_db_v2
from neutron.plugins.cisco.db import network_db_v2 as cdb
from neutron.plugins.cisco import extensions
from neutron.plugins.cisco.extensions import n1kv_profile
from neutron.plugins.cisco.extensions import n1kv
from neutron.plugins.cisco.extensions import network_profile
from neutron.plugins.cisco.n1kv import n1kv_client
from neutron.plugins.cisco.n1kv import n1kv_neutron_plugin
@ -212,9 +212,9 @@ class N1kvPluginTestCase(test_plugin.NeutronDbPluginV2TestCase):
self.saved_attr_map[resource] = attrs.copy()
# Update the RESOURCE_ATTRIBUTE_MAP with n1kv specific extended attrs.
attributes.RESOURCE_ATTRIBUTE_MAP["networks"].update(
n1kv_profile.EXTENDED_ATTRIBUTES_2_0["networks"])
n1kv.EXTENDED_ATTRIBUTES_2_0["networks"])
attributes.RESOURCE_ATTRIBUTE_MAP["ports"].update(
n1kv_profile.EXTENDED_ATTRIBUTES_2_0["ports"])
n1kv.EXTENDED_ATTRIBUTES_2_0["ports"])
self.addCleanup(self.restore_resource_attribute_map)
self.addCleanup(db.clear_db)
super(N1kvPluginTestCase, self).setUp(self._plugin_name,
@ -307,32 +307,32 @@ class TestN1kvHTTPResponse(test_plugin.TestV2HTTPResponse,
class TestN1kvPorts(test_plugin.TestPortsV2,
N1kvPluginTestCase):
def test_create_port_with_default_n1kv_profile_id(self):
def test_create_port_with_default_n1kv_policy_profile_id(self):
"""Test port create without passing policy profile id."""
with self.port() as port:
db_session = db.get_session()
pp = n1kv_db_v2.get_policy_profile(
db_session, port['port'][n1kv_profile.PROFILE_ID])
db_session, port['port'][n1kv.PROFILE_ID])
self.assertEqual(pp['name'], 'service_profile')
def test_create_port_with_n1kv_profile_id(self):
def test_create_port_with_n1kv_policy_profile_id(self):
"""Test port create with policy profile id."""
profile_obj = self._make_test_policy_profile(name='test_profile')
with self.network() as network:
data = {'port': {n1kv_profile.PROFILE_ID: profile_obj.id,
data = {'port': {n1kv.PROFILE_ID: profile_obj.id,
'tenant_id': self.tenant_id,
'network_id': network['network']['id']}}
port_req = self.new_create_request('ports', data)
port = self.deserialize(self.fmt,
port_req.get_response(self.api))
self.assertEqual(port['port'][n1kv_profile.PROFILE_ID],
self.assertEqual(port['port'][n1kv.PROFILE_ID],
profile_obj.id)
self._delete('ports', port['port']['id'])
def test_update_port_with_n1kv_profile_id(self):
def test_update_port_with_n1kv_policy_profile_id(self):
"""Test port update failure while updating policy profile id."""
with self.port() as port:
data = {'port': {n1kv_profile.PROFILE_ID: 'some-profile-uuid'}}
data = {'port': {n1kv.PROFILE_ID: 'some-profile-uuid'}}
port_req = self.new_update_request('ports',
data,
port['port']['id'])
@ -346,31 +346,31 @@ class TestN1kvNetworks(test_plugin.TestNetworksV2,
def _prepare_net_data(self, net_profile_id):
return {'network': {'name': 'net1',
n1kv_profile.PROFILE_ID: net_profile_id,
n1kv.PROFILE_ID: net_profile_id,
'tenant_id': self.tenant_id}}
def test_create_network_with_default_n1kv_profile_id(self):
def test_create_network_with_default_n1kv_network_profile_id(self):
"""Test network create without passing network profile id."""
with self.network() as network:
db_session = db.get_session()
np = n1kv_db_v2.get_network_profile(
db_session, network['network'][n1kv_profile.PROFILE_ID])
db_session, network['network'][n1kv.PROFILE_ID])
self.assertEqual(np['name'], 'default_network_profile')
def test_create_network_with_n1kv_profile_id(self):
def test_create_network_with_n1kv_network_profile_id(self):
"""Test network create with network profile id."""
profile_obj = self._make_test_profile(name='test_profile')
data = self._prepare_net_data(profile_obj.id)
network_req = self.new_create_request('networks', data)
network = self.deserialize(self.fmt,
network_req.get_response(self.api))
self.assertEqual(network['network'][n1kv_profile.PROFILE_ID],
self.assertEqual(network['network'][n1kv.PROFILE_ID],
profile_obj.id)
def test_update_network_with_n1kv_profile_id(self):
def test_update_network_with_n1kv_network_profile_id(self):
"""Test network update failure while updating network profile id."""
with self.network() as network:
data = {'network': {n1kv_profile.PROFILE_ID: 'some-profile-uuid'}}
data = {'network': {n1kv.PROFILE_ID: 'some-profile-uuid'}}
network_req = self.new_update_request('networks',
data,
network['network']['id'])