Use consistent type checking of project_id in API
We were using inconsistent type checking for the project_id in various API endpoints. This could lead to erratic behavior if some API requests specified the project_id UUID with hyphens and some without hyphens and normlization occurred. This patch changes this behavior to use consistent type checking for the project_id for all API endpoints. Since this bug is a regression that is less than 2 weeks old, I've also introduced a few unit tests which should ensure we don't have another regression of the desired behavior anytime soon. Change-Id: I4c3ec52c01547196160e977029ecc5ded97c79ed Closes-Bug: #1555401
This commit is contained in:
parent
972cdba6ee
commit
26d850c711
@ -34,7 +34,7 @@ class LoadBalancerResponse(base.BaseType):
|
||||
operating_status = wtypes.wsattr(wtypes.StringType())
|
||||
enabled = wtypes.wsattr(bool)
|
||||
vip = wtypes.wsattr(VIP)
|
||||
project_id = wtypes.wsattr(wtypes.UuidType())
|
||||
project_id = wtypes.wsattr(wtypes.StringType())
|
||||
listeners = wtypes.wsattr([listener.ListenerResponse])
|
||||
|
||||
@classmethod
|
||||
@ -64,7 +64,7 @@ class LoadBalancerPOST(base.BaseType):
|
||||
description = wtypes.wsattr(wtypes.StringType(max_length=255))
|
||||
enabled = wtypes.wsattr(bool, default=True)
|
||||
vip = wtypes.wsattr(VIP, mandatory=True)
|
||||
project_id = wtypes.wsattr(wtypes.UuidType())
|
||||
project_id = wtypes.wsattr(wtypes.StringType(max_length=36))
|
||||
listeners = wtypes.wsattr([listener.ListenerPOST], default=[])
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ class PoolResponse(base.BaseType):
|
||||
protocol = wtypes.wsattr(wtypes.text)
|
||||
lb_algorithm = wtypes.wsattr(wtypes.text)
|
||||
session_persistence = wtypes.wsattr(SessionPersistenceResponse)
|
||||
project_id = wtypes.wsattr(wtypes.UuidType())
|
||||
project_id = wtypes.wsattr(wtypes.StringType())
|
||||
health_monitor = wtypes.wsattr(health_monitor.HealthMonitorResponse)
|
||||
members = wtypes.wsattr([member.MemberResponse])
|
||||
|
||||
@ -95,7 +95,7 @@ class PoolPOST(base.BaseType):
|
||||
wtypes.Enum(str, *constants.SUPPORTED_LB_ALGORITHMS),
|
||||
mandatory=True)
|
||||
session_persistence = wtypes.wsattr(SessionPersistencePOST)
|
||||
project_id = wtypes.wsattr(wtypes.UuidType())
|
||||
project_id = wtypes.wsattr(wtypes.StringType(max_length=36))
|
||||
health_monitor = wtypes.wsattr(health_monitor.HealthMonitorPOST)
|
||||
members = wtypes.wsattr([member.MemberPOST])
|
||||
|
||||
|
@ -109,6 +109,13 @@ class TestHealthMonitorPOST(base.BaseTypesTest, TestHealthMonitor):
|
||||
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
|
||||
body)
|
||||
|
||||
def test_non_uuid_project_id(self):
|
||||
body = {"type": constants.HEALTH_MONITOR_HTTP, "delay": 1,
|
||||
"timeout": 1, "fall_threshold": 1, "rise_threshold": 1,
|
||||
"project_id": "non-uuid"}
|
||||
hm = wsme_json.fromjson(self._type, body)
|
||||
self.assertEqual(hm.project_id, body['project_id'])
|
||||
|
||||
|
||||
class TestHealthMonitorPUT(base.BaseTypesTest, TestHealthMonitor):
|
||||
|
||||
|
@ -80,6 +80,14 @@ class TestListenerPOST(base.BaseTypesTest, TestListener):
|
||||
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
|
||||
body)
|
||||
|
||||
def test_non_uuid_project_id(self):
|
||||
body = {"name": "test", "description": "test", "connection_limit": 10,
|
||||
"protocol": constants.PROTOCOL_HTTP, "protocol_port": 80,
|
||||
"default_pool_id": uuidutils.generate_uuid(),
|
||||
"project_id": "non-uuid"}
|
||||
listener = wsme_json.fromjson(self._type, body)
|
||||
self.assertEqual(listener.project_id, body['project_id'])
|
||||
|
||||
|
||||
class TestListenerPUT(base.BaseTypesTest, TestListener):
|
||||
|
||||
|
@ -66,6 +66,12 @@ class TestLoadBalancerPOST(base.BaseTypesTest, TestLoadBalancer):
|
||||
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
|
||||
body)
|
||||
|
||||
def test_non_uuid_project_id(self):
|
||||
body = {"name": "test_name", "description": "test_description",
|
||||
"vip": {}, "project_id": "non-uuid"}
|
||||
lb = wsme_json.fromjson(self._type, body)
|
||||
self.assertEqual(lb.project_id, body['project_id'])
|
||||
|
||||
|
||||
class TestLoadBalancerPUT(base.BaseTypesTest, TestLoadBalancer):
|
||||
|
||||
|
@ -67,6 +67,12 @@ class TestMemberPOST(base.BaseTypesTest):
|
||||
"weight": "test"}
|
||||
self.assertRaises(ValueError, wsme_json.fromjson, self._type, body)
|
||||
|
||||
def test_non_uuid_project_id(self):
|
||||
body = {"ip_address": "10.0.0.1", "protocol_port": 80,
|
||||
"project_id": "non-uuid"}
|
||||
member = wsme_json.fromjson(self._type, body)
|
||||
self.assertEqual(member.project_id, body['project_id'])
|
||||
|
||||
|
||||
class TestMemberPUT(base.BaseTypesTest):
|
||||
|
||||
|
@ -86,6 +86,13 @@ class TestPoolPOST(base.BaseTypesTest):
|
||||
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
|
||||
body)
|
||||
|
||||
def test_non_uuid_project_id(self):
|
||||
body = {"protocol": constants.PROTOCOL_HTTP,
|
||||
"lb_algorithm": constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
"project_id": "non-uuid"}
|
||||
pool = wsme_json.fromjson(self._type, body)
|
||||
self.assertEqual(pool.project_id, body['project_id'])
|
||||
|
||||
|
||||
class TestPoolPUT(base.BaseTypesTest):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user