Skip to content

Commit

Permalink
Merge pull request #26034 from alfredodeza/wip-rm37963
Browse files Browse the repository at this point in the history
ceph-volume fix TypeError on dmcrypt when using Python3

Reviewed-by: Andrew Schoen <aschoen@redhat.com>
  • Loading branch information
andrewschoen committed Jan 24, 2019
2 parents a9dfd70 + 69613cc commit 0496658
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/ceph-volume/ceph_volume/tests/util/test_encryption.py
Expand Up @@ -33,3 +33,21 @@ def test_mapper_does_not_exist(self, fake_run):
file_name = '/path/does/not/exist'
encryption.dmcrypt_close(file_name)
assert fake_run.calls == []


class TestDmcryptKey(object):

def test_dmcrypt_with_default_size(self, conf_ceph_stub):
conf_ceph_stub('[global]\nfsid=asdf-lkjh')
result = encryption.create_dmcrypt_key()
assert len(result) == 172

def test_dmcrypt_with_custom_size(self, conf_ceph_stub):
conf_ceph_stub('''
[global]
fsid=asdf
[osd]
osd_dmcrypt_size=8
''')
result = encryption.create_dmcrypt_key()
assert len(result) == 172
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/util/encryption.py
Expand Up @@ -23,7 +23,7 @@ def create_dmcrypt_key():
)
# The size of the key is defined in bits, so we must transform that
# value to bytes (dividing by 8) because we read in bytes, not bits
random_string = os.urandom(dmcrypt_key_size / 8)
random_string = os.urandom(int(dmcrypt_key_size / 8))
key = base64.b64encode(random_string).decode('utf-8')
return key

Expand Down

0 comments on commit 0496658

Please sign in to comment.