Skip to content

Commit e8f3103

Browse files
author
Dean Troyer
committed
Ignore more exceptions in quota list
Additional exceptions can be thrown here, ignore additional project lookup exceptions, but still not all. Server failures are still interesting, for example. Change-Id: I9a750ae8e8efa29a36bbd1e34b50b6ace0658260
1 parent c69304e commit e8f3103

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

openstackclient/common/quota.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def take_action(self, parsed_args):
135135
try:
136136
data = compute_client.quotas.get(p)
137137
except Exception as ex:
138-
if type(ex).__name__ == 'NotFound':
138+
if (
139+
type(ex).__name__ == 'NotFound' or
140+
ex.http_status >= 400 and ex.http_status <= 499
141+
):
139142
# Project not found, move on to next one
140143
LOG.warning("Project %s not found: %s" % (p, ex))
141144
continue

openstackclient/tests/unit/common/test_quota.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_quota_list_compute_default(self):
242242
self.assertEqual(self.compute_reference_data, ret_quotas[0])
243243
self.assertEqual(1, len(ret_quotas))
244244

245-
def test_quota_list_compute_no_project(self):
245+
def test_quota_list_compute_no_project_not_found(self):
246246
# Make one of the projects disappear
247247
self.compute.quotas.get = mock.Mock(
248248
side_effect=[
@@ -266,6 +266,53 @@ def test_quota_list_compute_no_project(self):
266266
self.assertEqual(self.compute_reference_data, ret_quotas[0])
267267
self.assertEqual(1, len(ret_quotas))
268268

269+
def test_quota_list_compute_no_project_4xx(self):
270+
# Make one of the projects disappear
271+
self.compute.quotas.get = mock.Mock(
272+
side_effect=[
273+
self.compute_quotas[0],
274+
exceptions.BadRequest("Bad request"),
275+
],
276+
)
277+
278+
arglist = [
279+
'--compute',
280+
]
281+
verifylist = [
282+
('compute', True),
283+
]
284+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
285+
286+
columns, data = self.cmd.take_action(parsed_args)
287+
ret_quotas = list(data)
288+
289+
self.assertEqual(self.compute_column_header, columns)
290+
self.assertEqual(self.compute_reference_data, ret_quotas[0])
291+
self.assertEqual(1, len(ret_quotas))
292+
293+
def test_quota_list_compute_no_project_5xx(self):
294+
# Make one of the projects disappear
295+
self.compute.quotas.get = mock.Mock(
296+
side_effect=[
297+
self.compute_quotas[0],
298+
exceptions.HTTPNotImplemented("Not implemented??"),
299+
],
300+
)
301+
302+
arglist = [
303+
'--compute',
304+
]
305+
verifylist = [
306+
('compute', True),
307+
]
308+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
309+
310+
self.assertRaises(
311+
exceptions.HTTPNotImplemented,
312+
self.cmd.take_action,
313+
parsed_args,
314+
)
315+
269316
def test_quota_list_network(self):
270317
# Two projects with non-default quotas
271318
self.network.get_quota = mock.Mock(

0 commit comments

Comments
 (0)