Port volume transfer to Python 3
Encode Unicode to UTF-8 for salt and authentication key when computing the crypt hash. Partially implements: blueprint cinder-python3 Change-Id: I19d337cf0d40d91378e1c42061bc51b6009970a2
This commit is contained in:
parent
9ba2d75a5a
commit
d548495e9e
@ -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."""
|
||||
|
1
tox.ini
1
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 \
|
||||
|
Loading…
x
Reference in New Issue
Block a user