]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add negative UT cases for subnet/GW create/update
authorPaul Michali <pcm@cisco.com>
Fri, 10 May 2013 13:17:24 +0000 (06:17 -0700)
committerPaul Michali <pcm@cisco.com>
Wed, 15 May 2013 02:28:39 +0000 (19:28 -0700)
When force_gateway_on_subnet is configured, ensure
that a GW with IP same as subnet, and BCAST GW IP
are rejected during subnet create. For subnet update,
ensure GW outside of subnet is rejected.

bug 1178675

Change-Id: Ice58f7e1be7966b247c165e52807405401e5a4ea

quantum/tests/unit/midonet/test_midonet_plugin.py
quantum/tests/unit/test_db_plugin.py

index 11bb9b0632c627f390c6d668ae5338a5a32f3902..424beadb13ead429d81c6cc94c7c320dd45f17bd 100644 (file)
@@ -300,9 +300,20 @@ class TestMidonetSubnetsV2(test_plugin.TestSubnetsV2,
         self._setup_subnet_mocks()
         super(TestMidonetSubnetsV2, self).test_create_subnet_gw_values()
 
-    def test_create_force_subnet_gw_values(self):
+    def test_create_subnet_gw_outside_cidr_force_on_returns_400(self):
         self._setup_subnet_mocks()
-        super(TestMidonetSubnetsV2, self).test_create_force_subnet_gw_values()
+        super(TestMidonetSubnetsV2,
+              self).test_create_subnet_gw_outside_cidr_force_on_returns_400()
+
+    def test_create_subnet_gw_of_network_force_on_returns_400(self):
+        self._setup_subnet_mocks()
+        super(TestMidonetSubnetsV2,
+              self).test_create_subnet_gw_of_network_force_on_returns_400()
+
+    def test_create_subnet_gw_bcast_force_on_returns_400(self):
+        self._setup_subnet_mocks()
+        super(TestMidonetSubnetsV2,
+              self).test_create_subnet_gw_bcast_force_on_returns_400()
 
     def test_create_subnet_with_allocation_pool(self):
         self._setup_subnet_mocks()
@@ -398,6 +409,9 @@ class TestMidonetSubnetsV2(test_plugin.TestSubnetsV2,
         super(TestMidonetSubnetsV2,
               self).test_update_subnet_shared_returns_400()
 
+    def test_update_subnet_gw_outside_cidr_force_on_returns_400(self):
+        pass
+
     def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
         pass
 
index 825193feeeacb96978c4d54f988fcdd32439dbf3..2b7269a7c1d92e7719f9e544aa5ad6c8267a6719 100644 (file)
@@ -2695,7 +2695,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
         self._test_create_subnet(expected=expected,
                                  gateway_ip=gateway)
 
-    def test_create_force_subnet_gw_values(self):
+    def test_create_subnet_gw_outside_cidr_force_on_returns_400(self):
         cfg.CONF.set_override('force_gateway_on_subnet', True)
         with self.network() as network:
             self._create_subnet(self.fmt,
@@ -2704,6 +2704,24 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
                                 400,
                                 gateway_ip='100.0.0.1')
 
+    def test_create_subnet_gw_of_network_force_on_returns_400(self):
+        cfg.CONF.set_override('force_gateway_on_subnet', True)
+        with self.network() as network:
+            self._create_subnet(self.fmt,
+                                network['network']['id'],
+                                '10.0.0.0/24',
+                                400,
+                                gateway_ip='10.0.0.0')
+
+    def test_create_subnet_gw_bcast_force_on_returns_400(self):
+        cfg.CONF.set_override('force_gateway_on_subnet', True)
+        with self.network() as network:
+            self._create_subnet(self.fmt,
+                                network['network']['id'],
+                                '10.0.0.0/24',
+                                400,
+                                gateway_ip='10.0.0.255')
+
     def test_create_subnet_with_allocation_pool(self):
         gateway_ip = '10.0.0.1'
         cidr = '10.0.0.0/24'
@@ -2968,6 +2986,16 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
                 res = req.get_response(self.api)
                 self.assertEqual(res.status_int, 400)
 
+    def test_update_subnet_gw_outside_cidr_force_on_returns_400(self):
+        cfg.CONF.set_override('force_gateway_on_subnet', True)
+        with self.network() as network:
+            with self.subnet(network=network) as subnet:
+                data = {'subnet': {'gateway_ip': '100.0.0.1'}}
+                req = self.new_update_request('subnets', data,
+                                              subnet['subnet']['id'])
+                res = req.get_response(self.api)
+                self.assertEqual(res.status_int, 400)
+
     def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
         with self.network() as network:
             with self.subnet(network=network) as subnet: