Skip to content

Commit

Permalink
Merge "Tests: Combine similar encrypted volume tests w/ ddt"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Aug 19, 2019
2 parents 6722bb2 + d754988 commit f0dddd6
Showing 1 changed file with 7 additions and 43 deletions.
50 changes: 7 additions & 43 deletions cinder/tests/unit/volume/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,15 @@ def test_create_volume_with_encrypted_volume_type_multiattach(self):
'description',
volume_type=db_vol_type)

@ddt.data({'cipher': 'blowfish-cbc', 'algo': 'blowfish', 'length': 32},
{'cipher': 'aes-xts-plain64', 'algo': 'aes', 'length': 256})
@ddt.unpack
@mock.patch.object(key_manager, 'API', fake_keymgr.fake_api)
def test_create_volume_with_encrypted_volume_type_aes(self):
def test_create_volume_with_encrypted_volume_types(
self, cipher, algo, length):
ctxt = context.get_admin_context()

cipher = 'aes-xts-plain64'
key_size = 256
key_size = length
control_location = 'front-end'

db.volume_type_create(ctxt,
Expand All @@ -747,46 +750,7 @@ def test_create_volume_with_encrypted_volume_type_aes(self):
key_manager = volume_api.key_manager
key = key_manager.get(self.context, volume['encryption_key_id'])
self.assertEqual(key_size, len(key.get_encoded()) * 8)
self.assertEqual('aes', key.algorithm)

metadata = db.volume_encryption_metadata_get(self.context, volume.id)
self.assertEqual(db_vol_type.get('id'), volume['volume_type_id'])
self.assertEqual(cipher, metadata.get('cipher'))
self.assertEqual(key_size, metadata.get('key_size'))
self.assertIsNotNone(volume['encryption_key_id'])

@mock.patch.object(key_manager, 'API', fake_keymgr.fake_api)
def test_create_volume_with_encrypted_volume_type_blowfish(self):
ctxt = context.get_admin_context()

cipher = 'blowfish-cbc'
key_size = 32
control_location = 'front-end'

db.volume_type_create(ctxt,
{'id': '61298380-0c12-11e3-bfd6-4b48424183be',
'name': 'LUKS'})
db.volume_type_encryption_create(
ctxt,
'61298380-0c12-11e3-bfd6-4b48424183be',
{'control_location': control_location,
'provider': ENCRYPTION_PROVIDER,
'cipher': cipher,
'key_size': key_size})

volume_api = cinder.volume.api.API()

db_vol_type = db.volume_type_get_by_name(ctxt, 'LUKS')

volume = volume_api.create(self.context,
1,
'name',
'description',
volume_type=db_vol_type)

key_manager = volume_api.key_manager
key = key_manager.get(self.context, volume['encryption_key_id'])
self.assertEqual('blowfish', key.algorithm)
self.assertEqual(algo, key.algorithm)

metadata = db.volume_encryption_metadata_get(self.context, volume.id)
self.assertEqual(db_vol_type.get('id'), volume['volume_type_id'])
Expand Down

0 comments on commit f0dddd6

Please sign in to comment.