Simplify required-method check

Change-Id: I527ab490d707871cc9c08345e3213ec2da7c0c43
This commit is contained in:
Tim Burke 2017-05-02 16:20:28 -07:00
parent ea1b479a81
commit 607500d3c5

View File

@ -215,30 +215,25 @@ class ECDriver(object):
#
# Verify that the imported library implements the required functions
#
required_methods = {
'decode': 0,
'encode': 0,
'reconstruct': 0,
'fragments_needed': 0,
'min_parity_fragments_needed': 0,
'get_metadata': 0,
'verify_stripe_metadata': 0,
'get_segment_info': 0
}
required_methods = [
'decode',
'encode',
'reconstruct',
'fragments_needed',
'min_parity_fragments_needed',
'get_metadata',
'verify_stripe_metadata',
'get_segment_info',
]
for attr in dir(self.ec_lib_reference):
if hasattr(getattr(self.ec_lib_reference, attr), "__call__"):
required_methods[attr] = 1
missing_methods = ' '.join(
method for method in required_methods
if not callable(getattr(self.ec_lib_reference, method, None)))
not_implemented_str = ""
for (method, is_implemented) in required_methods.items():
if is_implemented == 0:
not_implemented_str += method + " "
if len(not_implemented_str) > 0:
if missing_methods:
raise ECDriverError(
"The following required methods are not implemented "
"in %s: %s" % (self.library_import_str, not_implemented_str))
"in %s: %s" % (self.library_import_str, missing_methods))
def __repr__(self):
return '%s(ec_type=%r, k=%r, m=%r)' % (