py3: port common/storage_policy.py
Change-Id: I7030280a8495628df9ed8edcc8abc31f901da72e
This commit is contained in:
parent
6060af8db9
commit
4b19ac7723
@ -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)
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user