Catch FloatingIpNotFoundForHost exception

When showing floating ips for a given host, the FloatingIpNotFoundForHost
exception isn't handled when no floating ips can be found for the host.
This patch fixes this bug.

Closes-Bug: #1289164
Change-Id: Ic25ffd66945fd40ba10d69515e0cbfeae840313c
This commit is contained in:
Haiwei Xu 2014-03-08 01:13:30 +09:00
parent c08cc38b81
commit 27b405e46c
2 changed files with 16 additions and 5 deletions

View File

@ -50,13 +50,16 @@ class FloatingIPBulkController(object):
def _get_floating_ip_info(self, context, host=None):
floating_ip_info = {"floating_ip_info": []}
try:
if host is None:
if host is None:
try:
floating_ips = db.floating_ip_get_all(context)
else:
except exception.NoFloatingIpsDefined:
return floating_ip_info
else:
try:
floating_ips = db.floating_ip_get_all_by_host(context, host)
except exception.NoFloatingIpsDefined:
return floating_ip_info
except exception.FloatingIpNotFoundForHost as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
for floating_ip in floating_ips:
instance_uuid = None

View File

@ -77,6 +77,14 @@ class FloatingIPBulk(test.TestCase):
self.assertEqual(res_dict, response)
def test_list_ip_by_host(self):
ip_range = '192.168.1.1/28'
self._setup_floating_ips(ip_range)
req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips-bulk',
use_admin_context=True)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, req, 'host')
def test_delete_ips(self):
ip_range = '192.168.1.0/20'
self._setup_floating_ips(ip_range)