summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2018-02-01 14:30:19 -0800
committerTim Burke <tim.burke@gmail.com>2018-02-26 10:57:41 +0000
commit4b19ac772364778a4b96d7e18834db9a7645f482 (patch)
tree83482ae428feb09e1118e373207d7b589e9dd4e8
parent6060af8db96e23d32f3ecc3d02f7f0dd27a57eba (diff)
downloadswift-4b19ac772364778a4b96d7e18834db9a7645f482.tar.gz
py3: port common/storage_policy.py
Change-Id: I7030280a8495628df9ed8edcc8abc31f901da72e
-rw-r--r--swift/common/storage_policy.py20
-rw-r--r--test/unit/common/test_storage_policy.py9
-rw-r--r--tox.ini1
3 files changed, 24 insertions, 6 deletions
diff --git a/swift/common/storage_policy.py b/swift/common/storage_policy.py
index 75650e5bd..baf224227 100644
--- a/swift/common/storage_policy.py
+++ b/swift/common/storage_policy.py
@@ -203,8 +203,17 @@ class BaseStoragePolicy(object):
def __int__(self):
return self.idx
- def __cmp__(self, other):
- return cmp(self.idx, int(other))
+ def __eq__(self, other):
+ return self.idx == int(other)
+
+ def __ne__(self, other):
+ return self.idx != int(other)
+
+ def __lt__(self, other):
+ return self.idx < int(other)
+
+ def __gt__(self, other):
+ return self.idx > int(other)
def __repr__(self):
return ("%s(%d, %r, is_default=%s, "
@@ -923,7 +932,12 @@ def reload_storage_policies():
Reload POLICIES from ``swift.conf``.
"""
global _POLICIES
- policy_conf = ConfigParser()
+ if six.PY2:
+ policy_conf = ConfigParser()
+ else:
+ # Python 3.2 disallows section or option duplicates by default
+ # strict=False allows us to preserve the older behavior
+ policy_conf = ConfigParser(strict=False)
policy_conf.read(utils.SWIFT_CONF_FILE)
try:
_POLICIES = parse_storage_policies(policy_conf)
diff --git a/test/unit/common/test_storage_policy.py b/test/unit/common/test_storage_policy.py
index fc9b3c788..e82305aaf 100644
--- a/test/unit/common/test_storage_policy.py
+++ b/test/unit/common/test_storage_policy.py
@@ -70,7 +70,10 @@ class FakeStoragePolicy(BaseStoragePolicy):
class TestStoragePolicies(unittest.TestCase):
def _conf(self, conf_str):
conf_str = "\n".join(line.strip() for line in conf_str.split("\n"))
- conf = ConfigParser()
+ if six.PY2:
+ conf = ConfigParser()
+ else:
+ conf = ConfigParser(strict=False)
conf.readfp(six.StringIO(conf_str))
return conf
@@ -679,7 +682,7 @@ class TestStoragePolicies(unittest.TestCase):
with capture_logging('swift.common.storage_policy') as records, \
self.assertRaises(PolicyError) as exc_mgr:
parse_storage_policies(bad_conf)
- self.assertEqual(exc_mgr.exception.message,
+ self.assertEqual(exc_mgr.exception.args[0],
'Storage policy bad-policy uses an EC '
'configuration known to harm data durability. This '
'policy MUST be deprecated.')
@@ -1048,7 +1051,7 @@ class TestStoragePolicies(unittest.TestCase):
[storage-policy:00]
name = double-zero
""")
- with NamedTemporaryFile() as f:
+ with NamedTemporaryFile(mode='w+t') as f:
conf.write(f)
f.flush()
with mock.patch('swift.common.utils.SWIFT_CONF_FILE',
diff --git a/tox.ini b/tox.ini
index f28ca1a25..6acbb34f5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -38,6 +38,7 @@ commands =
test/unit/common/test_linkat.py \
test/unit/common/test_manager.py \
test/unit/common/test_splice.py \
+ test/unit/common/test_storage_policy.py \
test/unit/common/test_utils.py
[testenv:py35]