summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-09-13 21:06:46 +0000
committerGerrit Code Review <review@openstack.org>2017-09-13 21:06:46 +0000
commitaa7a2c0cf20b91919bea77b2569da6999aa47525 (patch)
treecfdfe9100e0a04adb50728224e0b52830a4fc04c
parent0cdfbf6f6eaf2a4f67c83d4019614cde414ca2f9 (diff)
parentf990e62dc05c46e323019ca0267e5564c3cf15a7 (diff)
downloadpyeclib-aa7a2c0cf20b91919bea77b2569da6999aa47525.tar.gz
Merge "Clean up ECDriver"
-rw-r--r--pyeclib/ec_iface.py23
-rw-r--r--test/test_pyeclib_api.py13
2 files changed, 31 insertions, 5 deletions
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index ed7a7a6..43f0e61 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -142,8 +142,22 @@ class PyECLib_FRAGHDRCHKSUM_Types(PyECLibEnum):
# Main ECDriver class
class ECDriver(object):
-
- def __init__(self, *args, **kwargs):
+ '''A driver to encode, decode, and reconstruct erasure-coded data.'''
+
+ 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:
diff --git a/test/test_pyeclib_api.py b/test/test_pyeclib_api.py
index e8732af..fb9c04d 100644
--- a/test/test_pyeclib_api.py
+++ b/test/test_pyeclib_api.py
@@ -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)