Merge "Replaced the strings with respective constants"

This commit is contained in:
Jenkins 2014-07-30 08:21:27 +00:00 committed by Gerrit Code Review
commit 8fd406c74e
2 changed files with 85 additions and 68 deletions

View File

@ -24,7 +24,7 @@ from neutron.common import exceptions as n_exc
from neutron import context
from neutron.db import api as db
from neutron.db import common_db_mixin
from neutron.plugins.cisco.common import cisco_constants
from neutron.plugins.cisco.common import cisco_constants as c_const
from neutron.plugins.cisco.common import cisco_exceptions as c_exc
from neutron.plugins.cisco.db import n1kv_db_v2
from neutron.plugins.cisco.db import n1kv_models_v2
@ -46,28 +46,29 @@ TEST_NETWORK_ID = 'abcdefghijklmnopqrstuvwxyz'
TEST_NETWORK_ID2 = 'abcdefghijklmnopqrstuvwxy2'
TEST_NETWORK_ID3 = 'abcdefghijklmnopqrstuvwxy3'
TEST_NETWORK_PROFILE = {'name': 'test_profile',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'physnet1',
'segment_range': '10-19'}
TEST_NETWORK_PROFILE_2 = {'name': 'test_profile_2',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'physnet1',
'segment_range': SEGMENT_RANGE}
TEST_NETWORK_PROFILE_VXLAN = {'name': 'test_profile',
'segment_type': 'overlay',
'sub_type': 'native_vxlan',
'segment_type': c_const.NETWORK_TYPE_OVERLAY,
'sub_type': c_const.NETWORK_SUBTYPE_NATIVE_VXLAN,
'segment_range': '5000-5009',
'multicast_ip_range': '239.0.0.70-239.0.0.80'}
TEST_POLICY_PROFILE = {'id': '4a417990-76fb-11e2-bcfd-0800200c9a66',
'name': 'test_policy_profile'}
TEST_NETWORK_PROFILE_MULTI_SEGMENT = {'name': 'test_profile',
'segment_type': 'multi-segment'}
'segment_type':
c_const.NETWORK_TYPE_MULTI_SEGMENT}
TEST_NETWORK_PROFILE_VLAN_TRUNK = {'name': 'test_profile',
'segment_type': 'trunk',
'sub_type': 'vlan'}
'segment_type': c_const.NETWORK_TYPE_TRUNK,
'sub_type': c_const.NETWORK_TYPE_VLAN}
TEST_NETWORK_PROFILE_VXLAN_TRUNK = {'name': 'test_profile',
'segment_type': 'trunk',
'sub_type': 'overlay'}
'segment_type': c_const.NETWORK_TYPE_TRUNK,
'sub_type': c_const.NETWORK_TYPE_OVERLAY}
def _create_test_network_profile_if_not_there(session,
@ -310,13 +311,13 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
p = _create_test_network_profile_if_not_there(self.session)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'vlan',
self.session, TEST_NETWORK_ID, c_const.NETWORK_TYPE_VLAN,
PHYS_NET, 1234, '0.0.0.0', p.id, None)
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'vlan')
self.assertEqual(binding.network_type, c_const.NETWORK_TYPE_VLAN)
self.assertEqual(binding.physical_network, PHYS_NET)
self.assertEqual(binding.segmentation_id, 1234)
@ -333,13 +334,15 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
self.session,
TEST_NETWORK_PROFILE_MULTI_SEGMENT)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'multi-segment',
self.session, TEST_NETWORK_ID,
c_const.NETWORK_TYPE_MULTI_SEGMENT,
None, 0, '0.0.0.0', p.id, None)
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'multi-segment')
self.assertEqual(binding.network_type,
c_const.NETWORK_TYPE_MULTI_SEGMENT)
self.assertIsNone(binding.physical_network)
self.assertEqual(binding.segmentation_id, 0)
@ -356,14 +359,16 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
self.session,
TEST_NETWORK_PROFILE_MULTI_SEGMENT)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'multi-segment',
self.session, TEST_NETWORK_ID,
c_const.NETWORK_TYPE_MULTI_SEGMENT,
None, 0, '0.0.0.0', p.id,
[(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'multi-segment')
self.assertEqual(binding.network_type,
c_const.NETWORK_TYPE_MULTI_SEGMENT)
self.assertIsNone(binding.physical_network)
self.assertEqual(binding.segmentation_id, 0)
ms_binding = (n1kv_db_v2.get_multi_segment_network_binding(
@ -401,13 +406,13 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
self.session,
TEST_NETWORK_PROFILE_VLAN_TRUNK)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'trunk',
self.session, TEST_NETWORK_ID, c_const.NETWORK_TYPE_TRUNK,
None, 0, '0.0.0.0', p.id, None)
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'trunk')
self.assertEqual(binding.network_type, c_const.NETWORK_TYPE_TRUNK)
self.assertIsNone(binding.physical_network)
self.assertEqual(binding.segmentation_id, 0)
@ -424,13 +429,13 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
self.session,
TEST_NETWORK_PROFILE_VXLAN_TRUNK)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'trunk',
self.session, TEST_NETWORK_ID, c_const.NETWORK_TYPE_TRUNK,
None, 0, '0.0.0.0', p.id, None)
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'trunk')
self.assertEqual(binding.network_type, c_const.NETWORK_TYPE_TRUNK)
self.assertIsNone(binding.physical_network)
self.assertEqual(binding.segmentation_id, 0)
@ -450,19 +455,20 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
TEST_NETWORK_ID2)
p_v = _create_test_network_profile_if_not_there(self.session)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID2, 'vlan',
self.session, TEST_NETWORK_ID2, c_const.NETWORK_TYPE_VLAN,
PHYS_NET, 1234, '0.0.0.0', p_v.id, None)
p = _create_test_network_profile_if_not_there(
self.session,
TEST_NETWORK_PROFILE_VLAN_TRUNK)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'trunk',
self.session, TEST_NETWORK_ID, c_const.NETWORK_TYPE_TRUNK,
None, 0, '0.0.0.0', p.id, [(TEST_NETWORK_ID2, 0)])
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'trunk')
self.assertEqual(binding.network_type,
c_const.NETWORK_TYPE_TRUNK)
self.assertEqual(binding.physical_network, PHYS_NET)
self.assertEqual(binding.segmentation_id, 0)
t_binding = (n1kv_db_v2.get_trunk_network_binding(
@ -502,20 +508,22 @@ class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase):
p_v = _create_test_network_profile_if_not_there(
self.session, TEST_NETWORK_PROFILE_VXLAN_TRUNK)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID2, 'overlay',
self.session, TEST_NETWORK_ID2,
c_const.NETWORK_TYPE_OVERLAY,
None, 5100, '224.10.10.10', p_v.id, None)
p = _create_test_network_profile_if_not_there(
self.session,
TEST_NETWORK_PROFILE_VXLAN_TRUNK)
n1kv_db_v2.add_network_binding(
self.session, TEST_NETWORK_ID, 'trunk',
self.session, TEST_NETWORK_ID, c_const.NETWORK_TYPE_TRUNK,
None, 0, '0.0.0.0', p.id,
[(TEST_NETWORK_ID2, 5)])
binding = n1kv_db_v2.get_network_binding(
self.session, TEST_NETWORK_ID)
self.assertIsNotNone(binding)
self.assertEqual(binding.network_id, TEST_NETWORK_ID)
self.assertEqual(binding.network_type, 'trunk')
self.assertEqual(binding.network_type,
c_const.NETWORK_TYPE_TRUNK)
self.assertIsNone(binding.physical_network)
self.assertEqual(binding.segmentation_id, 0)
t_binding = (n1kv_db_v2.get_trunk_network_binding(
@ -689,31 +697,31 @@ class NetworkProfileTests(base.BaseTestCase,
def test_get_network_profiles(self):
test_profiles = [{'name': 'test_profile1',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '200-210'},
{'name': 'test_profile2',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '211-220'},
{'name': 'test_profile3',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '221-230'},
{'name': 'test_profile4',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '231-240'},
{'name': 'test_profile5',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '241-250'},
{'name': 'test_profile6',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '251-260'},
{'name': 'test_profile7',
'segment_type': 'vlan',
'segment_type': c_const.NETWORK_TYPE_VLAN,
'physical_network': 'phys1',
'segment_range': '261-270'}]
[n1kv_db_v2.create_network_profile(self.session, p)
@ -850,7 +858,7 @@ class ProfileBindingTests(base.BaseTestCase,
test_profile_id = "AAAAAAAA-76ec-11e2-bcfd-0800200c9a66"
test_profile_type = "policy"
n1kv_db_v2.create_profile_binding(self.session,
cisco_constants.TENANT_ID_NOT_SET,
c_const.TENANT_ID_NOT_SET,
test_profile_id,
test_profile_type)
network_profile = {"network_profile": TEST_NETWORK_PROFILE}
@ -862,7 +870,7 @@ class ProfileBindingTests(base.BaseTestCase,
c_exc.ProfileTenantBindingNotFound,
n1kv_db_v2.get_profile_binding,
self.session,
cisco_constants.TENANT_ID_NOT_SET,
c_const.TENANT_ID_NOT_SET,
test_profile_id)
self.assertNotEqual(binding.tenant_id,
cisco_constants.TENANT_ID_NOT_SET)
c_const.TENANT_ID_NOT_SET)

View File

@ -246,53 +246,54 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
netp = {'name': 'netp1',
'segment_type': segment_type,
'tenant_id': self.tenant_id}
if segment_type == 'vlan':
if segment_type == c_const.NETWORK_TYPE_VLAN:
netp['segment_range'] = segment_range or '100-110'
netp['physical_network'] = PHYS_NET
elif segment_type == 'overlay':
elif segment_type == c_const.NETWORK_TYPE_OVERLAY:
netp['segment_range'] = segment_range or '10000-10010'
netp['sub_type'] = sub_type or 'enhanced'
netp['multicast_ip_range'] = (mcast_ip_range or
"224.1.1.1-224.1.1.10")
elif segment_type == 'trunk':
netp['sub_type'] = 'vlan'
elif segment_type == c_const.NETWORK_TYPE_TRUNK:
netp['sub_type'] = c_const.NETWORK_TYPE_VLAN
data = {"network_profile": netp}
return data
def test_create_network_profile_vlan(self):
data = self._prepare_net_profile_data('vlan')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_VLAN)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
def test_create_network_profile_overlay(self):
data = self._prepare_net_profile_data('overlay')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
def test_create_network_profile_trunk(self):
data = self._prepare_net_profile_data('trunk')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_TRUNK)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
def test_create_network_profile_trunk_missing_subtype(self):
data = self._prepare_net_profile_data('trunk')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_TRUNK)
data['network_profile'].pop('sub_type')
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 400)
def test_create_network_profile_overlay_unreasonable_seg_range(self):
data = self._prepare_net_profile_data('overlay',
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
segment_range='10000-1000000001')
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 400)
def test_update_network_profile_plugin(self):
net_p_dict = self._prepare_net_profile_data('overlay')
net_p_dict = (self.
_prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY))
net_p_req = self.new_create_request('network_profiles', net_p_dict)
net_p = self.deserialize(self.fmt,
net_p_req.get_response(self.ext_api))
@ -314,7 +315,8 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
def test_update_network_profile_segment_type_fail(self):
net_p = self._make_test_profile(name='netp1')
data = {'network_profile': {'segment_type': 'overlay'}}
data = {'network_profile': {
'segment_type': c_const.NETWORK_TYPE_OVERLAY}}
net_p_req = self.new_update_request('network_profiles',
data,
net_p['id'])
@ -322,11 +324,12 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(res.status_int, 400)
def test_update_network_profile_sub_type_fail(self):
net_p_dict = self._prepare_net_profile_data('overlay')
net_p_dict = (self.
_prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY))
net_p_req = self.new_create_request('network_profiles', net_p_dict)
net_p = self.deserialize(self.fmt,
net_p_req.get_response(self.ext_api))
data = {'network_profile': {'sub_type': 'vlan'}}
data = {'network_profile': {'sub_type': c_const.NETWORK_TYPE_VLAN}}
update_req = self.new_update_request('network_profiles',
data,
net_p['network_profile']['id'])
@ -355,24 +358,27 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(update_res.status_int, 409)
def test_create_overlay_network_profile_invalid_multicast_fail(self):
data = self._prepare_net_profile_data('overlay',
sub_type='native_vxlan',
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
sub_type=(c_const.
NETWORK_SUBTYPE_NATIVE_VXLAN),
mcast_ip_range='1.1.1.1')
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 400)
def test_create_overlay_network_profile_no_multicast_fail(self):
data = self._prepare_net_profile_data('overlay',
sub_type='native_vxlan')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
sub_type=(c_const.
NETWORK_SUBTYPE_NATIVE_VXLAN))
data['network_profile']['multicast_ip_range'] = ''
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 400)
def test_create_overlay_network_profile_wrong_split_multicast_fail(self):
data = self._prepare_net_profile_data('overlay',
sub_type='native_vxlan',
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
sub_type=(c_const.
NETWORK_SUBTYPE_NATIVE_VXLAN),
mcast_ip_range=
'224.1.1.1.224.1.1.3')
net_p_req = self.new_create_request('network_profiles', data)
@ -380,8 +386,9 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(res.status_int, 400)
def test_create_overlay_network_profile_invalid_minip_multicast_fail(self):
data = self._prepare_net_profile_data('overlay',
sub_type='native_vxlan',
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
sub_type=(c_const.
NETWORK_SUBTYPE_NATIVE_VXLAN),
mcast_ip_range=
'10.0.0.1-224.1.1.3')
net_p_req = self.new_create_request('network_profiles', data)
@ -389,8 +396,9 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(res.status_int, 400)
def test_create_overlay_network_profile_invalid_maxip_multicast_fail(self):
data = self._prepare_net_profile_data('overlay',
sub_type='native_vxlan',
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
sub_type=(c_const.
NETWORK_SUBTYPE_NATIVE_VXLAN),
mcast_ip_range=
'224.1.1.1-20.0.0.1')
net_p_req = self.new_create_request('network_profiles', data)
@ -398,13 +406,13 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(res.status_int, 400)
def test_create_overlay_network_profile_correct_multicast_pass(self):
data = self._prepare_net_profile_data('overlay')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
def test_update_overlay_network_profile_correct_multicast_pass(self):
data = self._prepare_net_profile_data('overlay')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
@ -418,8 +426,9 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(update_res.status_int, 200)
def test_create_overlay_network_profile_reservedip_multicast_fail(self):
data = self._prepare_net_profile_data('overlay',
sub_type='native_vxlan',
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY,
sub_type=(c_const.
NETWORK_SUBTYPE_NATIVE_VXLAN),
mcast_ip_range=
'224.0.0.100-224.0.1.100')
net_p_req = self.new_create_request('network_profiles', data)
@ -427,7 +436,7 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(res.status_int, 400)
def test_update_overlay_network_profile_reservedip_multicast_fail(self):
data = self._prepare_net_profile_data('overlay')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_OVERLAY)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
@ -451,7 +460,7 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(update_res.status_int, 400)
def test_update_trunk_network_profile_segment_range_fail(self):
data = self._prepare_net_profile_data('trunk')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_TRUNK)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
@ -465,7 +474,7 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
self.assertEqual(update_res.status_int, 400)
def test_update_trunk_network_profile_multicast_fail(self):
data = self._prepare_net_profile_data('trunk')
data = self._prepare_net_profile_data(c_const.NETWORK_TYPE_TRUNK)
net_p_req = self.new_create_request('network_profiles', data)
res = net_p_req.get_response(self.ext_api)
self.assertEqual(res.status_int, 201)
@ -480,7 +489,7 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
def test_create_network_profile_populate_vlan_segment_pool(self):
db_session = db.get_session()
net_p_dict = self._prepare_net_profile_data('vlan')
net_p_dict = self._prepare_net_profile_data(c_const.NETWORK_TYPE_VLAN)
net_p_req = self.new_create_request('network_profiles', net_p_dict)
self.deserialize(self.fmt,
net_p_req.get_response(self.ext_api))
@ -515,7 +524,7 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase):
def test_delete_network_profile_deallocate_vlan_segment_pool(self):
db_session = db.get_session()
net_p_dict = self._prepare_net_profile_data('vlan')
net_p_dict = self._prepare_net_profile_data(c_const.NETWORK_TYPE_VLAN)
net_p_req = self.new_create_request('network_profiles', net_p_dict)
net_p = self.deserialize(self.fmt,
net_p_req.get_response(self.ext_api))