From 993e8044072b6d1eb5604f6aba774d001d19c900 Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Wed, 24 Aug 2016 16:53:35 +0800 Subject: [PATCH] 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 --- zaqar/storage/mongodb/options.py | 2 +- zaqar/storage/mongodb/utils.py | 2 -- zaqar/tests/unit/storage/test_impl_mongodb.py | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/zaqar/storage/mongodb/options.py b/zaqar/storage/mongodb/options.py index 627d9b52d..74667601b 100644 --- a/zaqar/storage/mongodb/options.py +++ b/zaqar/storage/mongodb/options.py @@ -75,7 +75,7 @@ _COMMON_OPTIONS = ( group=_deprecated_group), ], help='Database name.'), - cfg.IntOpt('max_attempts', default=1000, + cfg.IntOpt('max_attempts', min=0, default=1000, deprecated_opts=[cfg.DeprecatedOpt( 'max_attempts', group=_deprecated_group), ], diff --git a/zaqar/storage/mongodb/utils.py b/zaqar/storage/mongodb/utils.py index b2d711fdf..198808c30 100644 --- a/zaqar/storage/mongodb/utils.py +++ b/zaqar/storage/mongodb/utils.py @@ -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 ratio attempt / max_attempts, with optional jitter. """ - if max_attempts < 0: - raise ValueError(u'max_attempts must be >= 0') if max_sleep < 0: raise ValueError(u'max_sleep must be >= 0') diff --git a/zaqar/tests/unit/storage/test_impl_mongodb.py b/zaqar/tests/unit/storage/test_impl_mongodb.py index abc635931..6e902cbec 100644 --- a/zaqar/tests/unit/storage/test_impl_mongodb.py +++ b/zaqar/tests/unit/storage/test_impl_mongodb.py @@ -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, -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, -1, 10, 2, 0) self.assertRaises(ValueError, utils.calculate_backoff, 10, 10, 2, 0)