diff --git a/gluster/swift/common/ring.py b/gluster/swift/common/ring.py index a3209e2..d86a534 100644 --- a/gluster/swift/common/ring.py +++ b/gluster/swift/common/ring.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os +import errno from ConfigParser import ConfigParser from swift.common.ring import ring from swift.common.utils import search_tree @@ -39,12 +41,20 @@ if not reseller_prefix.endswith('_'): class Ring(ring.Ring): - def __init__(self, *args, **kwargs): + def __init__(self, serialized_path, *args, **kwargs): self.false_node = {'zone': 1, 'weight': 100.0, 'ip': '127.0.0.1', 'id': 0, 'meta': '', 'device': 'volume_not_in_ring', 'port': 6012} self.account_list = [] - ring.Ring.__init__(self, *args, **kwargs) + + ring_file = os.path.join(serialized_path, kwargs['ring_name'] + + '.ring.gz') + if not os.path.exists(ring_file): + raise OSError(errno.ENOENT, 'No such file or directory', + 'ring files do not exists under %s, ' + 'aborting proxy-server start.' % serialized_path) + + ring.Ring.__init__(self, serialized_path, *args, **kwargs) def _get_part_nodes(self, part): seen_ids = set() diff --git a/test/unit/common/test_ring.py b/test/unit/common/test_ring.py index ca9fc5c..32dd7bb 100644 --- a/test/unit/common/test_ring.py +++ b/test/unit/common/test_ring.py @@ -14,6 +14,7 @@ # limitations under the License. import os +import errno import unittest import gluster.swift.common.constraints import swift.common.utils @@ -66,3 +67,15 @@ class TestRing(unittest.TestCase): def test_invalid_partition(self): nodes = self.ring.get_part_nodes(0) self.assertEqual(nodes[0]['device'], 'volume_not_in_ring') + + def test_ring_file_enoent(self): + swiftdir = os.path.join(os.getcwd(), "common", "data") + try: + self.ring = Ring(swiftdir, ring_name='obj') + except OSError as ose: + if ose.errno == errno.ENOENT: + pass + else: + self.fail('ENOENT expected, %s received.' %ose.errno) + else: + self.fail('OSError expected.')