Merge "Clean up ECDriver"
This commit is contained in:
commit
aa7a2c0cf2
|
@ -142,8 +142,22 @@ class PyECLib_FRAGHDRCHKSUM_Types(PyECLibEnum):
|
|||
|
||||
# Main ECDriver class
|
||||
class ECDriver(object):
|
||||
'''A driver to encode, decode, and reconstruct erasure-coded data.'''
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, **kwargs):
|
||||
'''
|
||||
:param ec_type: the erasure coding type to use for this driver.
|
||||
:param k: number of data fragments to use. Required.
|
||||
:param m: number of parity fragments to use. Required.
|
||||
:param chksum_type:
|
||||
:param validate: default: False
|
||||
:param library_import_str: default: 'pyeclib.core.ECPyECLibDriver'
|
||||
|
||||
You must provide either ``ec_type`` or ``library_import_str``;
|
||||
typically you just want to use ``ec_type``. See ALL_EC_TYPES for the
|
||||
list of all EC types supported by PyECLib, and VALID_EC_TYPES for the
|
||||
list of all EC types currently available on this system.
|
||||
'''
|
||||
self.k = -1
|
||||
self.m = -1
|
||||
self.hd = -1
|
||||
|
@ -156,6 +170,11 @@ class ECDriver(object):
|
|||
raise ECDriverError(
|
||||
"Invalid Argument: %s is required" % required)
|
||||
|
||||
if 'ec_type' not in kwargs and 'library_import_str' not in kwargs:
|
||||
raise ECDriverError(
|
||||
"Invalid Argument: either ec_type or library_import_str "
|
||||
"must be provided")
|
||||
|
||||
for (key, value) in kwargs.items():
|
||||
if key == "k":
|
||||
try:
|
||||
|
|
|
@ -119,22 +119,29 @@ class TestPyECLibDriver(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_invalid_km_args(self):
|
||||
def test_missing_required_args(self):
|
||||
# missing ec_type
|
||||
with self.assertRaises(ECDriverError) as err_context:
|
||||
ECDriver(k=1, m=1)
|
||||
self.assertEqual(str(err_context.exception),
|
||||
"Invalid Argument: either ec_type or "
|
||||
"library_import_str must be provided")
|
||||
|
||||
for ec_type in VALID_EC_TYPES:
|
||||
# missing k
|
||||
with self.assertRaises(ECDriverError) as err_context:
|
||||
ECDriver(ec_type=ec_type, m=1)
|
||||
|
||||
self.assertEqual(str(err_context.exception),
|
||||
"Invalid Argument: k is required")
|
||||
|
||||
# missing m
|
||||
with self.assertRaises(ECDriverError) as err_context:
|
||||
ECDriver(ec_type=ec_type, k=1)
|
||||
|
||||
self.assertEqual(str(err_context.exception),
|
||||
"Invalid Argument: m is required")
|
||||
|
||||
def test_invalid_km_args(self):
|
||||
for ec_type in VALID_EC_TYPES:
|
||||
with self.assertRaises(ECDriverError) as err_context:
|
||||
# k is smaller than 1
|
||||
ECDriver(ec_type=ec_type, k=-100, m=1)
|
||||
|
|
Loading…
Reference in New Issue