From df3ac534f099712485a71488812b799ca82cfc6e Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Thu, 25 Jul 2013 15:36:30 -0400 Subject: [PATCH] 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 --- .../openstack/compute/plugins/v3/fixed_ips.py | 6 ++++-- .../compute/plugins/v3/test_fixed_ips.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/plugins/v3/fixed_ips.py b/nova/api/openstack/compute/plugins/v3/fixed_ips.py index 5fa4ae3c21b2..6870ba130f85 100644 --- a/nova/api/openstack/compute/plugins/v3/fixed_ips.py +++ b/nova/api/openstack/compute/plugins/v3/fixed_ips.py @@ -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) diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_fixed_ips.py b/nova/tests/api/openstack/compute/plugins/v3/test_fixed_ips.py index 2a1387d154e5..19e592170606 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_fixed_ips.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_fixed_ips.py @@ -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(