From: Abhishek Raut Date: Fri, 2 May 2014 01:16:33 +0000 (-0700) Subject: Fix network profile subtype validation in N1kv plugin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1dd0bdc06dedf0f577d220f4c1a1f9f43f04a0fe;p=openstack-build%2Fneutron-build.git Fix network profile subtype validation in N1kv plugin Network profile of type Trunk expects a subtype field for creation. If a subtype is missing in the request body, plugin should raise an exception. This patch fixes the validation logic to detect missing subtype field. Change-Id: I6b4fb533576a317f7d568b4a0fe4117b5464ffa6 Closes-Bug: 1315197 --- diff --git a/neutron/plugins/cisco/db/n1kv_db_v2.py b/neutron/plugins/cisco/db/n1kv_db_v2.py index 0d9fa212d..5e256bbef 100644 --- a/neutron/plugins/cisco/db/n1kv_db_v2.py +++ b/neutron/plugins/cisco/db/n1kv_db_v2.py @@ -1210,7 +1210,7 @@ class NetworkProfile_db_mixin(object): raise n_exc.InvalidInput(error_message=msg) if segment_type in [c_const.NETWORK_TYPE_TRUNK, c_const.NETWORK_TYPE_OVERLAY]: - if "sub_type" not in net_p: + if not attributes.is_attr_set(net_p.get("sub_type")): msg = _("Argument sub_type missing " "for network profile") LOG.exception(msg) diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py index 369102076..931ddf16e 100644 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py +++ b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py @@ -266,6 +266,8 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase): netp['network_profile']['sub_type'] = 'enhanced' or 'native_vxlan' netp['network_profile']['multicast_ip_range'] = ("224.1.1.1-" "224.1.1.10") + elif segment_type == 'trunk': + netp['network_profile']['sub_type'] = 'vlan' return netp def test_create_network_profile_vlan(self): @@ -280,6 +282,19 @@ class TestN1kvNetworkProfiles(N1kvPluginTestCase): 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') + 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['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['network_profile']['segment_range'] = '10000-100000000001'