diff options
author | Claudiu Belu <cbelu@cloudbasesolutions.com> | 2016-02-10 23:56:05 +0200 |
---|---|---|
committer | Claudiu Belu <cbelu@cloudbasesolutions.com> | 2016-03-21 14:38:15 +0200 |
commit | c514065c70e7f0dcff87b3daccfdd8978c10d1c8 (patch) | |
tree | db1c84d166ec2d99f0776dda7dfe8d8e471721f6 /nova/tests/unit/keymgr | |
parent | c4763d46fe76c524363a0cf55d1e8afe4bd23f53 (diff) | |
download | nova-c514065c70e7f0dcff87b3daccfdd8978c10d1c8.tar.gz |
Fixes hex decoding related unit tests
Uses codecs module in order to decode hex.
Enables keymgr unit tests for gate-nova-python34.
Enables volume.encryptors unit tests for gate-nova-python34.
Partially Implements: blueprint nova-python3-newton
Change-Id: I43504da03c42c6b684da0ca1c3640c31a9843a45
Diffstat (limited to 'nova/tests/unit/keymgr')
-rw-r--r-- | nova/tests/unit/keymgr/test_barbican.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/keymgr/test_conf_key_mgr.py | 4 | ||||
-rw-r--r-- | nova/tests/unit/keymgr/test_key.py | 5 | ||||
-rw-r--r-- | nova/tests/unit/keymgr/test_mock_key_mgr.py | 7 | ||||
-rw-r--r-- | nova/tests/unit/keymgr/test_single_key_mgr.py | 5 |
5 files changed, 17 insertions, 6 deletions
diff --git a/nova/tests/unit/keymgr/test_barbican.py b/nova/tests/unit/keymgr/test_barbican.py index 0028acf40d..f8274c362c 100644 --- a/nova/tests/unit/keymgr/test_barbican.py +++ b/nova/tests/unit/keymgr/test_barbican.py @@ -195,7 +195,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('Nova Compute Key', - 'AQKgsw==', + b'AQKgsw==', 'application/octet-stream', 'base64', 'AES', 32, 'CBC', diff --git a/nova/tests/unit/keymgr/test_conf_key_mgr.py b/nova/tests/unit/keymgr/test_conf_key_mgr.py index ee9b5a2cc2..060e0a5fff 100644 --- a/nova/tests/unit/keymgr/test_conf_key_mgr.py +++ b/nova/tests/unit/keymgr/test_conf_key_mgr.py @@ -18,6 +18,7 @@ Test cases for the conf key manager. """ import array +import codecs from oslo_config import cfg @@ -28,6 +29,7 @@ from nova.tests.unit.keymgr import test_single_key_mgr CONF = cfg.CONF CONF.import_opt('fixed_key', 'nova.keymgr.conf_key_mgr', group='keymgr') +decode_hex = codecs.getdecoder("hex_codec") class ConfKeyManagerTestCase(test_single_key_mgr.SingleKeyManagerTestCase): @@ -43,7 +45,7 @@ class ConfKeyManagerTestCase(test_single_key_mgr.SingleKeyManagerTestCase): def setUp(self): super(ConfKeyManagerTestCase, self).setUp() - encoded_key = array.array('B', self._hex_key.decode('hex')).tolist() + encoded_key = array.array('B', decode_hex(self._hex_key)[0]).tolist() self.key = key.SymmetricKey('AES', encoded_key) def test_init(self): diff --git a/nova/tests/unit/keymgr/test_key.py b/nova/tests/unit/keymgr/test_key.py index 14766fd201..ba08567f29 100644 --- a/nova/tests/unit/keymgr/test_key.py +++ b/nova/tests/unit/keymgr/test_key.py @@ -18,10 +18,13 @@ Test cases for the key classes. """ import array +import codecs from nova.keymgr import key from nova import test +decode_hex = codecs.getdecoder("hex_codec") + class KeyTestCase(test.NoDBTestCase): @@ -41,7 +44,7 @@ class SymmetricKeyTestCase(KeyTestCase): def setUp(self): self.algorithm = 'AES' - self.encoded = array.array('B', ('0' * 64).decode('hex')).tolist() + self.encoded = array.array('B', decode_hex('0' * 64)[0]).tolist() super(SymmetricKeyTestCase, self).setUp() diff --git a/nova/tests/unit/keymgr/test_mock_key_mgr.py b/nova/tests/unit/keymgr/test_mock_key_mgr.py index 9d0c2174d1..46f5c5ffa1 100644 --- a/nova/tests/unit/keymgr/test_mock_key_mgr.py +++ b/nova/tests/unit/keymgr/test_mock_key_mgr.py @@ -18,6 +18,7 @@ Test cases for the mock key manager. """ import array +import codecs from nova import context from nova import exception @@ -25,6 +26,8 @@ from nova.keymgr import key as keymgr_key from nova.keymgr import mock_key_mgr from nova.tests.unit.keymgr import test_key_mgr +decode_hex = codecs.getdecoder("hex_codec") + class MockKeyManagerTestCase(test_key_mgr.KeyManagerTestCase): @@ -46,14 +49,14 @@ class MockKeyManagerTestCase(test_key_mgr.KeyManagerTestCase): for length in [64, 128, 256]: key_id = self.key_mgr.create_key(self.ctxt, key_length=length) key = self.key_mgr.get_key(self.ctxt, key_id) - self.assertEqual(length / 8, len(key.get_encoded())) + self.assertEqual(length // 8, len(key.get_encoded())) def test_create_null_context(self): self.assertRaises(exception.Forbidden, self.key_mgr.create_key, None) def test_store_key(self): - secret_key = array.array('B', ('0' * 64).decode('hex')).tolist() + secret_key = array.array('B', decode_hex('0' * 64)[0]).tolist() _key = keymgr_key.SymmetricKey('AES', secret_key) key_id = self.key_mgr.store_key(self.ctxt, _key) diff --git a/nova/tests/unit/keymgr/test_single_key_mgr.py b/nova/tests/unit/keymgr/test_single_key_mgr.py index 3cf1de8da2..984bf032a0 100644 --- a/nova/tests/unit/keymgr/test_single_key_mgr.py +++ b/nova/tests/unit/keymgr/test_single_key_mgr.py @@ -18,12 +18,15 @@ Test cases for the single key manager. """ import array +import codecs from nova import exception from nova.keymgr import key from nova.keymgr import single_key_mgr from nova.tests.unit.keymgr import test_mock_key_mgr +decode_hex = codecs.getdecoder("hex_codec") + class SingleKeyManagerTestCase(test_mock_key_mgr.MockKeyManagerTestCase): @@ -34,7 +37,7 @@ class SingleKeyManagerTestCase(test_mock_key_mgr.MockKeyManagerTestCase): super(SingleKeyManagerTestCase, self).setUp() self.key_id = '00000000-0000-0000-0000-000000000000' - encoded = array.array('B', ('0' * 64).decode('hex')).tolist() + encoded = array.array('B', decode_hex('0' * 64)[0]).tolist() self.key = key.SymmetricKey('AES', encoded) def test___init__(self): |