summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp>2016-07-11 14:47:03 -0700
committerKota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp>2016-09-06 22:36:16 -0700
commit25bc26b9149f8c28439238ecfe7d45e394e111e6 (patch)
tree9d2ea7ca82fc04e76c498a6fc427d23af60ac494
parent5ebce22641776706be929aa26bfba400574ada2b (diff)
downloadpyeclib-25bc26b9149f8c28439238ecfe7d45e394e111e6.tar.gz
Fix arg k, m to be required
Right now ECDriver doesn't check if k, m exist in the kwargs for init. That can tigger unfortunately success to init and that will fail at encode/decode (or result in odd with get_segment_info) Once, we have jerasure_rs_vand in default, that worked becuase jerasure did the assertion for the k, m parameters but we can reproduce the failures which this patch want fix with like: driver = ECDriver(ec_type='liberasurecode_rs_vand') # <- this is default and it succeeded! driver.encode(' ') # <- And then, this will result in ECDriverError: Out of memory, whooa! This patch fixes this to check the k, m existence in the init process. Change-Id: I0757c0a4e510ba42f357db0cac22861919d0ca26
-rw-r--r--pyeclib/ec_iface.py6
-rw-r--r--test/test_pyeclib_api.py28
2 files changed, 34 insertions, 0 deletions
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 9310ae7..dd3a8b9 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -114,6 +114,12 @@ class ECDriver(object):
self.ec_type = None
self.chksum_type = None
self.validate = False
+
+ for required in ('k', 'm'):
+ if required not in kwargs:
+ raise ECDriverError(
+ "Invalid Argument: %s is required" % required)
+
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 cd304b7..03b05be 100644
--- a/test/test_pyeclib_api.py
+++ b/test/test_pyeclib_api.py
@@ -109,6 +109,34 @@ class TestPyECLibDriver(unittest.TestCase):
def tearDown(self):
pass
+ def test_invalid_km_args(self):
+ 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")
+
+ with self.assertRaises(ECDriverError) as err_context:
+ # m is smaller than 1
+ ECDriver(ec_type=ec_type, k=-100, m=1)
+ self.assertEqual(str(err_context.exception),
+ "Invalid number of data fragments (k)")
+
+ with self.assertRaises(ECDriverError) as err_context:
+ # m is smaller than 1
+ ECDriver(ec_type=ec_type, k=1, m=-100)
+ self.assertEqual(str(err_context.exception),
+ "Invalid number of data fragments (m)")
+
def test_valid_ec_types(self):
# Build list of available types and compare to VALID_EC_TYPES
available_ec_types = []