summaryrefslogtreecommitdiff
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-05-19 15:49:33 +0000
committerGerrit Code Review <review@openstack.org>2017-05-19 15:49:33 +0000
commitf60d848e090ee31ec6783d6311feb131e953dfaa (patch)
tree190f911dae74eb55ebff14dd0412a7db7546805f /nova
parentf9babd74057fb559c9d851e5947086639bf895ec (diff)
parent53a71c1241aac70018c16d174032427a172378ed (diff)
downloadnova-f60d848e090ee31ec6783d6311feb131e953dfaa.tar.gz
Merge "Fix decoding of encryption key passed to dmcrypt"
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/unit/virt/libvirt/storage/test_dmcrypt.py5
-rw-r--r--nova/virt/libvirt/storage/dmcrypt.py5
2 files changed, 6 insertions, 4 deletions
diff --git a/nova/tests/unit/virt/libvirt/storage/test_dmcrypt.py b/nova/tests/unit/virt/libvirt/storage/test_dmcrypt.py
index df16f53bfd..a09ee39319 100644
--- a/nova/tests/unit/virt/libvirt/storage/test_dmcrypt.py
+++ b/nova/tests/unit/virt/libvirt/storage/test_dmcrypt.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import binascii
import mock
from oslo_concurrency import processutils
@@ -29,8 +30,8 @@ class LibvirtDmcryptTestCase(test.NoDBTestCase):
self.NAME = 'disk'
self.TARGET = dmcrypt.volume_name(self.NAME)
self.PATH = '/dev/nova-lvm/instance_disk'
- self.KEY = range(0, self.KEY_SIZE)
- self.KEY_STR = ''.join(["%02x" % x for x in range(0, self.KEY_SIZE)])
+ self.KEY = bytes(bytearray(x for x in range(0, self.KEY_SIZE)))
+ self.KEY_STR = binascii.hexlify(self.KEY).decode('utf-8')
@mock.patch('nova.utils.execute')
def test_create_volume(self, mock_execute):
diff --git a/nova/virt/libvirt/storage/dmcrypt.py b/nova/virt/libvirt/storage/dmcrypt.py
index cb82a06a07..7b21de7ab3 100644
--- a/nova/virt/libvirt/storage/dmcrypt.py
+++ b/nova/virt/libvirt/storage/dmcrypt.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import binascii
import os
from oslo_concurrency import processutils
@@ -52,7 +53,7 @@ def create_volume(target, device, cipher, key_size, key):
:param device: underlying block device
:param cipher: encryption cipher string digestible by cryptsetup
:param key_size: encryption key size
- :param key: encryption key as an array of unsigned bytes
+ :param key: encoded encryption key bytestring
"""
cmd = ('cryptsetup',
'create',
@@ -61,7 +62,7 @@ def create_volume(target, device, cipher, key_size, key):
'--cipher=' + cipher,
'--key-size=' + str(key_size),
'--key-file=-')
- key = ''.join(map(lambda byte: "%02x" % byte, key))
+ key = binascii.hexlify(key).decode('utf-8')
try:
utils.execute(*cmd, process_input=key, run_as_root=True)
except processutils.ProcessExecutionError as e: