Gracefully handle the ring file not found error.

Change-Id: I35c33f3938709d5d9a9a55640a503f186df9a965
Signed-off-by: Mohammed Junaid <junaid@redhat.com>
Reviewed-on: http://review.gluster.org/5368
Reviewed-by: Luis Pabon <lpabon@redhat.com>
Tested-by: Luis Pabon <lpabon@redhat.com>
This commit is contained in:
Mohammed Junaid 2013-07-22 10:38:26 +05:30 committed by Luis Pabon
parent 7ef1581a07
commit b1919bd794
2 changed files with 25 additions and 2 deletions

View File

@ -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()

View File

@ -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.')