Simplify required-method check
Change-Id: I527ab490d707871cc9c08345e3213ec2da7c0c43
This commit is contained in:
parent
ea1b479a81
commit
607500d3c5
@ -215,30 +215,25 @@ class ECDriver(object):
|
|||||||
#
|
#
|
||||||
# Verify that the imported library implements the required functions
|
# Verify that the imported library implements the required functions
|
||||||
#
|
#
|
||||||
required_methods = {
|
required_methods = [
|
||||||
'decode': 0,
|
'decode',
|
||||||
'encode': 0,
|
'encode',
|
||||||
'reconstruct': 0,
|
'reconstruct',
|
||||||
'fragments_needed': 0,
|
'fragments_needed',
|
||||||
'min_parity_fragments_needed': 0,
|
'min_parity_fragments_needed',
|
||||||
'get_metadata': 0,
|
'get_metadata',
|
||||||
'verify_stripe_metadata': 0,
|
'verify_stripe_metadata',
|
||||||
'get_segment_info': 0
|
'get_segment_info',
|
||||||
}
|
]
|
||||||
|
|
||||||
for attr in dir(self.ec_lib_reference):
|
missing_methods = ' '.join(
|
||||||
if hasattr(getattr(self.ec_lib_reference, attr), "__call__"):
|
method for method in required_methods
|
||||||
required_methods[attr] = 1
|
if not callable(getattr(self.ec_lib_reference, method, None)))
|
||||||
|
|
||||||
not_implemented_str = ""
|
if missing_methods:
|
||||||
for (method, is_implemented) in required_methods.items():
|
|
||||||
if is_implemented == 0:
|
|
||||||
not_implemented_str += method + " "
|
|
||||||
|
|
||||||
if len(not_implemented_str) > 0:
|
|
||||||
raise ECDriverError(
|
raise ECDriverError(
|
||||||
"The following required methods are not implemented "
|
"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):
|
def __repr__(self):
|
||||||
return '%s(ec_type=%r, k=%r, m=%r)' % (
|
return '%s(ec_type=%r, k=%r, m=%r)' % (
|
||||||
|
Loading…
Reference in New Issue
Block a user