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):
|
def __int__(self):
|
||||||
return self.idx
|
return self.idx
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __eq__(self, other):
|
||||||
return cmp(self.idx, int(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):
|
def __repr__(self):
|
||||||
return ("%s(%d, %r, is_default=%s, "
|
return ("%s(%d, %r, is_default=%s, "
|
||||||
@ -923,7 +932,12 @@ def reload_storage_policies():
|
|||||||
Reload POLICIES from ``swift.conf``.
|
Reload POLICIES from ``swift.conf``.
|
||||||
"""
|
"""
|
||||||
global _POLICIES
|
global _POLICIES
|
||||||
|
if six.PY2:
|
||||||
policy_conf = ConfigParser()
|
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)
|
policy_conf.read(utils.SWIFT_CONF_FILE)
|
||||||
try:
|
try:
|
||||||
_POLICIES = parse_storage_policies(policy_conf)
|
_POLICIES = parse_storage_policies(policy_conf)
|
||||||
|
@ -70,7 +70,10 @@ class FakeStoragePolicy(BaseStoragePolicy):
|
|||||||
class TestStoragePolicies(unittest.TestCase):
|
class TestStoragePolicies(unittest.TestCase):
|
||||||
def _conf(self, conf_str):
|
def _conf(self, conf_str):
|
||||||
conf_str = "\n".join(line.strip() for line in conf_str.split("\n"))
|
conf_str = "\n".join(line.strip() for line in conf_str.split("\n"))
|
||||||
|
if six.PY2:
|
||||||
conf = ConfigParser()
|
conf = ConfigParser()
|
||||||
|
else:
|
||||||
|
conf = ConfigParser(strict=False)
|
||||||
conf.readfp(six.StringIO(conf_str))
|
conf.readfp(six.StringIO(conf_str))
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
@ -679,7 +682,7 @@ class TestStoragePolicies(unittest.TestCase):
|
|||||||
with capture_logging('swift.common.storage_policy') as records, \
|
with capture_logging('swift.common.storage_policy') as records, \
|
||||||
self.assertRaises(PolicyError) as exc_mgr:
|
self.assertRaises(PolicyError) as exc_mgr:
|
||||||
parse_storage_policies(bad_conf)
|
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 '
|
'Storage policy bad-policy uses an EC '
|
||||||
'configuration known to harm data durability. This '
|
'configuration known to harm data durability. This '
|
||||||
'policy MUST be deprecated.')
|
'policy MUST be deprecated.')
|
||||||
@ -1048,7 +1051,7 @@ class TestStoragePolicies(unittest.TestCase):
|
|||||||
[storage-policy:00]
|
[storage-policy:00]
|
||||||
name = double-zero
|
name = double-zero
|
||||||
""")
|
""")
|
||||||
with NamedTemporaryFile() as f:
|
with NamedTemporaryFile(mode='w+t') as f:
|
||||||
conf.write(f)
|
conf.write(f)
|
||||||
f.flush()
|
f.flush()
|
||||||
with mock.patch('swift.common.utils.SWIFT_CONF_FILE',
|
with mock.patch('swift.common.utils.SWIFT_CONF_FILE',
|
||||||
|
1
tox.ini
1
tox.ini
@ -38,6 +38,7 @@ commands =
|
|||||||
test/unit/common/test_linkat.py \
|
test/unit/common/test_linkat.py \
|
||||||
test/unit/common/test_manager.py \
|
test/unit/common/test_manager.py \
|
||||||
test/unit/common/test_splice.py \
|
test/unit/common/test_splice.py \
|
||||||
|
test/unit/common/test_storage_policy.py \
|
||||||
test/unit/common/test_utils.py
|
test/unit/common/test_utils.py
|
||||||
|
|
||||||
[testenv:py35]
|
[testenv:py35]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user