Using oslo_config's min attribute

"min=0" is now introduced in oslo_config, so no
need to check for negative integer in code for
"max_attempts".

Change-Id: I3889368b98f5514db871112053b76827b9295d90
This commit is contained in:
gengchc2 2016-08-24 16:53:35 +08:00
parent 3b6932f676
commit 993e804407
3 changed files with 1 additions and 5 deletions

View File

@ -75,7 +75,7 @@ _COMMON_OPTIONS = (
group=_deprecated_group), ], group=_deprecated_group), ],
help='Database name.'), help='Database name.'),
cfg.IntOpt('max_attempts', default=1000, cfg.IntOpt('max_attempts', min=0, default=1000,
deprecated_opts=[cfg.DeprecatedOpt( deprecated_opts=[cfg.DeprecatedOpt(
'max_attempts', 'max_attempts',
group=_deprecated_group), ], group=_deprecated_group), ],

View File

@ -87,8 +87,6 @@ def calculate_backoff(attempt, max_attempts, max_sleep, max_jitter=0):
the interval [0, max_sleep), determined linearly according to the interval [0, max_sleep), determined linearly according to
the ratio attempt / max_attempts, with optional jitter. the ratio attempt / max_attempts, with optional jitter.
""" """
if max_attempts < 0:
raise ValueError(u'max_attempts must be >= 0')
if max_sleep < 0: if max_sleep < 0:
raise ValueError(u'max_sleep must be >= 0') raise ValueError(u'max_sleep must be >= 0')

View File

@ -110,8 +110,6 @@ class MongodbUtilsTest(MongodbSetupMixin, testing.TestBase):
self.assertRaises(ValueError, utils.calculate_backoff, 0, 10, -2, 0) self.assertRaises(ValueError, utils.calculate_backoff, 0, 10, -2, 0)
self.assertRaises(ValueError, utils.calculate_backoff, 0, 10, 2, -1) self.assertRaises(ValueError, utils.calculate_backoff, 0, 10, 2, -1)
self.assertRaises(ValueError, utils.calculate_backoff, -2, -10, 2, 0)
self.assertRaises(ValueError, utils.calculate_backoff, 2, -10, 2, 0)
self.assertRaises(ValueError, utils.calculate_backoff, -2, 10, 2, 0) self.assertRaises(ValueError, utils.calculate_backoff, -2, 10, 2, 0)
self.assertRaises(ValueError, utils.calculate_backoff, -1, 10, 2, 0) self.assertRaises(ValueError, utils.calculate_backoff, -1, 10, 2, 0)
self.assertRaises(ValueError, utils.calculate_backoff, 10, 10, 2, 0) self.assertRaises(ValueError, utils.calculate_backoff, 10, 10, 2, 0)