]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Validate IPv6 modes in API when IP version is 4
authorXuhan Peng <xuhanp@cn.ibm.com>
Tue, 15 Apr 2014 03:12:16 +0000 (11:12 +0800)
committerXuhan Peng <xuhanp@cn.ibm.com>
Fri, 18 Apr 2014 02:19:47 +0000 (10:19 +0800)
Add a validation to ipv6_ra_mode and ipv6_address_mode with ip
version. An InvalidInput error is prompted when ipv6_ra_mode
or ipv6_address_mode is specified in subnet create and update
API and ip version is 4.

Change-Id: I9a0356f23e6b162c31f2d289a34f4bd261cee91e
Closes-Bug: 1307788

neutron/db/db_base_plugin_v2.py
neutron/tests/unit/test_db_plugin.py

index 1be937cbaea81a9eb8d5c879774300b5fa6456b6..8f485c86f3c16ca706a9d9995dc4f505ed540ceb 100644 (file)
@@ -1108,6 +1108,15 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
             for rt in s['host_routes']:
                 self._validate_host_route(rt, ip_ver)
 
+        if ip_ver == 4:
+            if attributes.is_attr_set(s.get('ipv6_ra_mode')):
+                raise n_exc.InvalidInput(
+                    error_message=(_("ipv6_ra_mode is not valid when "
+                                     "ip_version is 4")))
+            if attributes.is_attr_set(s.get('ipv6_address_mode')):
+                raise n_exc.InvalidInput(
+                    error_message=(_("ipv6_address_mode is not valid when "
+                                     "ip_version is 4")))
         if ip_ver == 6:
             self._validate_ipv6_attributes(s, cur_subnet)
 
index d6bf0c090ce6d68cdd31ba1e70300e9641bcd0da..0808b69943b5046586653235d4f70c5d53d10909 100644 (file)
@@ -3050,6 +3050,25 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
                                      ipv6_ra_mode=mode,
                                      ipv6_address_mode=None)
 
+    def test_create_subnet_ipv6_ra_mode_ip_version_4(self):
+        cidr = '10.0.2.0/24'
+        with testlib_api.ExpectedException(
+            webob.exc.HTTPClientError) as ctx_manager:
+            self._test_create_subnet(cidr=cidr, ip_version=4,
+                                     ipv6_ra_mode=constants.DHCPV6_STATEFUL)
+        self.assertEqual(ctx_manager.exception.code,
+                         webob.exc.HTTPClientError.code)
+
+    def test_create_subnet_ipv6_address_mode_ip_version_4(self):
+        cidr = '10.0.2.0/24'
+        with testlib_api.ExpectedException(
+            webob.exc.HTTPClientError) as ctx_manager:
+            self._test_create_subnet(
+                cidr=cidr, ip_version=4,
+                ipv6_address_mode=constants.DHCPV6_STATEFUL)
+        self.assertEqual(ctx_manager.exception.code,
+                         webob.exc.HTTPClientError.code)
+
     def test_update_subnet_no_gateway(self):
         with self.subnet() as subnet:
             data = {'subnet': {'gateway_ip': '11.0.0.1'}}
@@ -3258,6 +3277,28 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
             self.assertEqual(res.status_int,
                              webob.exc.HTTPClientError.code)
 
+    def test_update_subnet_ipv6_ra_mode_ip_version_4(self):
+        with self.network() as network:
+            with self.subnet(network=network) as subnet:
+                data = {'subnet': {'ipv6_ra_mode':
+                                   constants.DHCPV6_STATEFUL}}
+                req = self.new_update_request('subnets', data,
+                                              subnet['subnet']['id'])
+                res = req.get_response(self.api)
+                self.assertEqual(res.status_int,
+                                 webob.exc.HTTPClientError.code)
+
+    def test_update_subnet_ipv6_address_mode_ip_version_4(self):
+        with self.network() as network:
+            with self.subnet(network=network) as subnet:
+                data = {'subnet': {'ipv6_address_mode':
+                                   constants.DHCPV6_STATEFUL}}
+                req = self.new_update_request('subnets', data,
+                                              subnet['subnet']['id'])
+                res = req.get_response(self.api)
+                self.assertEqual(res.status_int,
+                                 webob.exc.HTTPClientError.code)
+
     def test_show_subnet(self):
         with self.network() as network:
             with self.subnet(network=network) as subnet: