creating a Ring will ensure a valid HASH_PATH_SUFFIX
To make sure that node lookups match what the servers return the generated hashes need to match. All the utils that use the ring should validate their HASH_PATH_SUFFIX.
This commit is contained in:
parent
24e4137219
commit
ae1c2d73ab
@ -18,7 +18,7 @@ from gzip import GzipFile
|
||||
from os.path import getmtime
|
||||
from struct import unpack_from
|
||||
from time import time
|
||||
from swift.common.utils import hash_path
|
||||
from swift.common.utils import hash_path, validate_configuration
|
||||
|
||||
|
||||
class RingData(object):
|
||||
@ -39,6 +39,8 @@ class Ring(object):
|
||||
"""
|
||||
|
||||
def __init__(self, pickle_gz_path, reload_time=15):
|
||||
# can't use the ring unless HASH_PATH_SUFFIX is set
|
||||
validate_configuration()
|
||||
self.pickle_gz_path = pickle_gz_path
|
||||
self.reload_time = reload_time
|
||||
self._reload(force=True)
|
||||
|
@ -69,6 +69,13 @@ class TestRing(unittest.TestCase):
|
||||
self.assertEquals(self.ring.devs, self.intended_devs)
|
||||
self.assertEquals(self.ring.reload_time, self.intended_reload_time)
|
||||
self.assertEquals(self.ring.pickle_gz_path, self.testgz)
|
||||
# test invalid endcap
|
||||
_orig_hash_path_suffix = utils.HASH_PATH_SUFFIX
|
||||
try:
|
||||
utils.HASH_PATH_SUFFIX = ''
|
||||
self.assertRaises(SystemExit, ring.Ring, self.testgz)
|
||||
finally:
|
||||
utils.HASH_PATH_SUFFIX = _orig_hash_path_suffix
|
||||
|
||||
def test_has_changed(self):
|
||||
self.assertEquals(self.ring.has_changed(), False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user