]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Validate loadbalancing method when updating a pool
authorEugene Nikanorov <enikanorov@mirantis.com>
Wed, 19 Nov 2014 10:05:05 +0000 (14:05 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Wed, 19 Nov 2014 10:05:05 +0000 (14:05 +0400)
Validate the input for the lb_method and avoid DBIntegrityError.

Change-Id: Iea3d464abdeb1ed377db2453581124742f9fb0ac
Closes-Bug: #1390078

neutron/extensions/loadbalancer.py
neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py

index ae91b6515e260e748fe921d01ff06fe3be5c4b25..fdc23d8265e9b8dbb300f2eb07e82017a397fa8e 100644 (file)
@@ -184,7 +184,9 @@ RESOURCE_ATTRIBUTE_MAP = {
                      'validate': {'type:string': None},
                      'is_visible': True, 'default': attr.ATTR_NOT_SPECIFIED},
         'lb_method': {'allow_post': True, 'allow_put': True,
-                      'validate': {'type:string': None},
+                      'validate': {'type:values': ['ROUND_ROBIN',
+                                                   'LEAST_CONNECTIONS',
+                                                   'SOURCE_IP']},
                       'is_visible': True},
         'members': {'allow_post': False, 'allow_put': False,
                     'is_visible': True},
index e3f3a3d8cf765dd018bf3015811bf07c6f5216df..69a15a4d09a4f075e50fe844d8a5ea9c624e98c2 100644 (file)
@@ -1121,6 +1121,14 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
                                                     (m1, m2, m3),
                                                     ('delay', 'asc'), 2, 2)
 
+    def test_update_pool_invalid_lb_method(self):
+        with self.pool() as pool:
+            update_data = {'pool': {'lb_method': 'dummy'}}
+            req = self.new_update_request('pools', update_data,
+                                          pool['pool']['id'], fmt=self.fmt)
+            res = req.get_response(self.ext_api)
+            self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int)
+
     def test_update_pool_stats_with_no_stats(self):
         keys = ["bytes_in", "bytes_out",
                 "active_connections",