diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-06-06 20:53:33 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-06-06 20:53:33 +0000 |
commit | 6768ad4403bcb533801ab5c31e170684bd66cfa7 (patch) | |
tree | ba2b793001674da57fc8c220dac9c236190381d4 | |
parent | 4e94ec6c0bb9364d00d12671f6b63e1aadccd74a (diff) | |
parent | 607500d3c5957449720d17228954221784201d97 (diff) | |
download | pyeclib-6768ad4403bcb533801ab5c31e170684bd66cfa7.tar.gz |
Merge "Simplify required-method check"
-rw-r--r-- | pyeclib/ec_iface.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py index 13fe505..ed7a7a6 100644 --- a/pyeclib/ec_iface.py +++ b/pyeclib/ec_iface.py @@ -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 - } - - for attr in dir(self.ec_lib_reference): - if hasattr(getattr(self.ec_lib_reference, attr), "__call__"): - required_methods[attr] = 1 - - 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: + required_methods = [ + 'decode', + 'encode', + 'reconstruct', + 'fragments_needed', + 'min_parity_fragments_needed', + 'get_metadata', + 'verify_stripe_metadata', + 'get_segment_info', + ] + + missing_methods = ' '.join( + method for method in required_methods + if not callable(getattr(self.ec_lib_reference, method, None))) + + 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)' % ( |