Port key manager to Python 3

* Replace text.decode('hex') with binascii.unhexlify(text)
* test_barbican: base64 string is a bytes string
* tests-py3.txt: add keymgr tests

Partial-Implements: blueprint cinder-python3
Change-Id: Icc19fa354603857b259458b858e27c5bdd600360
This commit is contained in:
Victor Stinner 2015-11-24 17:42:07 +01:00
parent 6b6863703a
commit 52f62c31f7
5 changed files with 12 additions and 7 deletions

View File

@ -32,6 +32,7 @@ encryption key so *any* volume can be decrypted once the fixed key is known.
"""
import array
import binascii
from oslo_config import cfg
from oslo_log import log as logging
@ -70,8 +71,8 @@ class ConfKeyManager(key_mgr.KeyManager):
def _generate_key(self, **kwargs):
_hex = self._generate_hex_key(**kwargs)
return key.SymmetricKey('AES',
array.array('B', _hex.decode('hex')).tolist())
key_list = array.array('B', binascii.unhexlify(_hex)).tolist()
return key.SymmetricKey('AES', key_list)
def _generate_hex_key(self, **kwargs):
if CONF.keymgr.fixed_key is None:

View File

@ -205,7 +205,7 @@ class BarbicanKeyManagerTestCase(test_key_mgr.KeyManagerTestCase):
returned_uuid = self.key_mgr.store_key(self.ctxt, _key, bit_length=32)
self.create.assert_called_once_with('Cinder Volume Key',
'AQKgsw==',
b'AQKgsw==',
'application/octet-stream',
'base64',
'AES', 32, 'CBC',

View File

@ -18,6 +18,7 @@ Test cases for the conf key manager.
"""
import array
import binascii
from oslo_config import cfg
@ -48,7 +49,7 @@ class ConfKeyManagerTestCase(test_key_mgr.KeyManagerTestCase):
self.ctxt = context.RequestContext('fake', 'fake')
self.key_id = '00000000-0000-0000-0000-000000000000'
encoded = array.array('B', self._hex_key.decode('hex')).tolist()
encoded = array.array('B', binascii.unhexlify(self._hex_key)).tolist()
self.key = key.SymmetricKey('AES', encoded)
def test___init__(self):

View File

@ -17,8 +17,6 @@
Test cases for the key classes.
"""
import array
from cinder.keymgr import key
from cinder import test
@ -41,7 +39,7 @@ class SymmetricKeyTestCase(KeyTestCase):
def setUp(self):
self.algorithm = 'AES'
self.encoded = array.array('B', ('0' * 64).decode('hex')).tolist()
self.encoded = [0] * 32
super(SymmetricKeyTestCase, self).setUp()

View File

@ -18,7 +18,12 @@ cinder.tests.unit.api.test_versions
cinder.tests.unit.api.test_xmlutil
cinder.tests.unit.image.test_cache
cinder.tests.unit.image.test_glance
cinder.tests.unit.keymgr.test_barbican
cinder.tests.unit.keymgr.test_conf_key_mgr
cinder.tests.unit.keymgr.test_key
cinder.tests.unit.keymgr.test_key_mgr
cinder.tests.unit.keymgr.test_mock_key_mgr
cinder.tests.unit.keymgr.test_not_implemented_key_mgr
cinder.tests.unit.scheduler.test_allocated_capacity_weigher
cinder.tests.unit.scheduler.test_capacity_weigher
cinder.tests.unit.scheduler.test_chance_weigher