Don't log exception for None timeout_mins
If a request contains a timeout_mins key but it is None (which is now the case for all requests sent via python-heatclient), we log an exception, but really we just want to ignore the value and continue (as well as other "None" values, ie '0' which was the previous default for no key) So split the test for a key and conversion to int, and only log the exception if there is an error doing the type conversion, not if we get a value which implies ignoring/doing nothing. Change-Id: I6b8d1f053b47fd4c22a5df636481a95bd046b1df Closes-Bug: #1297759
This commit is contained in:
@@ -29,13 +29,17 @@ def extract_args(params):
|
||||
conversion where appropriate
|
||||
'''
|
||||
kwargs = {}
|
||||
try:
|
||||
timeout_mins = int(params.get(api.PARAM_TIMEOUT, 0))
|
||||
except (ValueError, TypeError):
|
||||
logger.exception(_('create timeout conversion'))
|
||||
else:
|
||||
if timeout_mins > 0:
|
||||
kwargs[api.PARAM_TIMEOUT] = timeout_mins
|
||||
timeout_mins = params.get(api.PARAM_TIMEOUT)
|
||||
if timeout_mins not in ('0', 0, None):
|
||||
try:
|
||||
timeout = int(timeout_mins)
|
||||
except (ValueError, TypeError):
|
||||
logger.exception(_('Timeout conversion failed'))
|
||||
else:
|
||||
if timeout > 0:
|
||||
kwargs[api.PARAM_TIMEOUT] = timeout
|
||||
else:
|
||||
raise ValueError(_('Invalid timeout value %s') % timeout)
|
||||
|
||||
if api.PARAM_DISABLE_ROLLBACK in params:
|
||||
disable_rollback = params.get(api.PARAM_DISABLE_ROLLBACK)
|
||||
|
||||
@@ -51,6 +51,11 @@ class EngineApiTest(HeatTestCase):
|
||||
args = api.extract_args(p)
|
||||
self.assertNotIn('timeout_mins', args)
|
||||
|
||||
def test_timeout_extract_negative(self):
|
||||
p = {'timeout_mins': '-100'}
|
||||
error = self.assertRaises(ValueError, api.extract_args, p)
|
||||
self.assertIn('Invalid timeout value', str(error))
|
||||
|
||||
def test_timeout_extract_not_present(self):
|
||||
args = api.extract_args({})
|
||||
self.assertNotIn('timeout_mins', args)
|
||||
|
||||
Reference in New Issue
Block a user