]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port volume transfer to Python 3
authorVictor Stinner <vstinner@redhat.com>
Fri, 21 Aug 2015 18:52:18 +0000 (11:52 -0700)
committerVictor Stinner <vstinner@redhat.com>
Tue, 1 Sep 2015 11:11:13 +0000 (13:11 +0200)
Encode Unicode to UTF-8 for salt and authentication key when computing
the crypt hash.

Partially implements: blueprint cinder-python3
Change-Id: I19d337cf0d40d91378e1c42061bc51b6009970a2

cinder/transfer/api.py
tox.ini

index e29dee773b1a66cfbd8c9e26d7eac1346b98a96e..04d48cadcebdd8c93077bb26ca137a1f537bbafc 100644 (file)
@@ -25,6 +25,7 @@ import os
 from oslo_config import cfg
 from oslo_log import log as logging
 from oslo_utils import excutils
+import six
 
 from cinder.db import base
 from cinder import exception
@@ -98,9 +99,15 @@ class API(base.Base):
 
     def _get_crypt_hash(self, salt, auth_key):
         """Generate a random hash based on the salt and the auth key."""
-        return hmac.new(str(salt),
-                        str(auth_key),
-                        hashlib.sha1).hexdigest()
+        if not isinstance(salt, (six.binary_type, six.text_type)):
+            salt = str(salt)
+        if isinstance(salt, six.text_type):
+            salt = salt.encode('utf-8')
+        if not isinstance(auth_key, (six.binary_type, six.text_type)):
+            auth_key = str(auth_key)
+        if isinstance(auth_key, six.text_type):
+            auth_key = auth_key.encode('utf-8')
+        return hmac.new(salt, auth_key, hashlib.sha1).hexdigest()
 
     def create(self, context, volume_id, display_name):
         """Creates an entry in the transfers table."""
diff --git a/tox.ini b/tox.ini
index b026e036b0fd36e9a9b33de493d0add14df9ff55..11ad4736c5f154084d5012db84e573aad11cce02 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -96,6 +96,7 @@ commands =
     cinder.tests.unit.test_volume_configuration \
     cinder.tests.unit.test_volume_glance_metadata \
     cinder.tests.unit.test_volume_rpcapi \
+    cinder.tests.unit.test_volume_transfer \
     cinder.tests.unit.test_volume_types \
     cinder.tests.unit.test_volume_types_extra_specs \
     cinder.tests.unit.test_volume_utils \