Fix postgresql failures related to Data type to API-v3 fixed-ip
Postgresql is kind of sensitive about different kind of data in a query, so it was failing in cases like looking for an ip using a filter which wasn't a valid ip or ids values greater than the id type on the table. This patch fix this behavior to fixed ips in API-v3. In v2 this was fixed by change I83d532c28c9aec690e8e1ffad8b58e71d619d728 Fixes bug 1182754 Fixes bug 1204503 Change-Id: I9aa14bea2f29f1df85dfd1f07eb0b1947d2c1100
This commit is contained in:
@@ -36,7 +36,8 @@ class FixedIPController(object):
|
||||
|
||||
try:
|
||||
fixed_ip = db.fixed_ip_get_by_address_detailed(context, id)
|
||||
except exception.FixedIpNotFoundForAddress as ex:
|
||||
except (exception.FixedIpNotFoundForAddress,
|
||||
exception.FixedIpInvalid) as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.format_message())
|
||||
|
||||
fixed_ip_info = {"fixed_ip": {}}
|
||||
@@ -75,7 +76,8 @@ class FixedIPController(object):
|
||||
fixed_ip = db.fixed_ip_get_by_address(context, address)
|
||||
db.fixed_ip_update(context, fixed_ip['address'],
|
||||
{'reserved': reserved})
|
||||
except exception.FixedIpNotFoundForAddress:
|
||||
except (exception.FixedIpNotFoundForAddress,
|
||||
exception.FixedIpInvalid) as ex:
|
||||
msg = _("Fixed IP %s not found") % address
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
|
||||
@@ -134,6 +134,11 @@ class FixedIpTest(test.TestCase):
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
|
||||
'10.0.0.1')
|
||||
|
||||
def test_fixed_ips_get_invalid_ip_address(self):
|
||||
req = fakes.HTTPRequest.blank('/v3/os-fixed-ips/inv.ali.d.ip')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
|
||||
'inv.ali.d.ip')
|
||||
|
||||
def test_fixed_ips_get_deleted_ip_fail(self):
|
||||
req = fakes.HTTPRequest.blank('/v3/fake/os-fixed-ips/10.0.0.2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
|
||||
@@ -156,6 +161,12 @@ class FixedIpTest(test.TestCase):
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req,
|
||||
'10.0.0.1', body)
|
||||
|
||||
def test_fixed_ip_reserve_invalid_ip_address(self):
|
||||
body = {'reserve': None}
|
||||
req = fakes.HTTPRequest.blank('/v3/os-fixed-ips/inv.ali.d.ip/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.action, req, 'inv.ali.d.ip', body)
|
||||
|
||||
def test_fixed_ip_reserve_deleted_ip(self):
|
||||
body = {'reserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
@@ -180,6 +191,12 @@ class FixedIpTest(test.TestCase):
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req,
|
||||
'10.0.0.1', body)
|
||||
|
||||
def test_fixed_ip_unreserve_invalid_ip_address(self):
|
||||
body = {'unreserve': None}
|
||||
req = fakes.HTTPRequest.blank('/v3/os-fixed-ips/inv.ali.d.ip/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.action, req, 'inv.ali.d.ip', body)
|
||||
|
||||
def test_fixed_ip_unreserve_deleted_ip(self):
|
||||
body = {'unreserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
|
||||
Reference in New Issue
Block a user