summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r--glanceclient/common/utils.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index dee9978..bc0c0eb 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -28,10 +28,10 @@ import uuid
import six
-if os.name == 'nt':
- import msvcrt
-else:
- msvcrt = None
+if os.name == 'nt': # noqa
+ import msvcrt # noqa
+else: # noqa
+ msvcrt = None # noqa
from oslo_utils import encodeutils
from oslo_utils import strutils
@@ -449,6 +449,26 @@ def integrity_iter(iter, checksum):
(md5sum, checksum))
+def serious_integrity_iter(iter, hasher, hash_value):
+ """Check image data integrity using the Glance "multihash".
+
+ :param iter: iterable containing the image data
+ :param hasher: a hashlib object
+ :param hash_value: hexdigest of the image data
+ :raises: IOError if the hashdigest of the data is not hash_value
+ """
+ for chunk in iter:
+ yield chunk
+ if isinstance(chunk, six.string_types):
+ chunk = six.b(chunk)
+ hasher.update(chunk)
+ computed = hasher.hexdigest()
+ if computed != hash_value:
+ raise IOError(errno.EPIPE,
+ 'Corrupt image download. Hash was %s expected %s' %
+ (computed, hash_value))
+
+
def memoized_property(fn):
attr_name = '_lazy_once_' + fn.__name__