encryption_ref = volume_type_encryption_get(context,
volume_ref['volume_type_id'])
- return {
+ values = {
'encryption_key_id': volume_ref['encryption_key_id'],
- 'control_location': encryption_ref['control_location'],
- 'cipher': encryption_ref['cipher'],
- 'key_size': encryption_ref['key_size'],
- 'provider': encryption_ref['provider'],
}
+ if encryption_ref:
+ for key in ['control_location', 'cipher', 'key_size', 'provider']:
+ values[key] = encryption_ref[key]
+
+ return values
+
####################
class DBAPIEncryptionTestCase(BaseTest):
- """Tests for the db.api.volume_type_encryption_* methods."""
+ """Tests for the db.api.volume_(type_)?encryption_* methods."""
_ignored_keys = [
'deleted',
encryption['volume_type_id'])
self.assertIsNone(encryption_get)
+ def test_volume_encryption_get(self):
+ # normal volume -- metadata should be None
+ volume = db.volume_create(self.ctxt, {})
+ values = db.volume_encryption_metadata_get(self.ctxt, volume.id)
+
+ self.assertEqual({'encryption_key_id': None}, values)
+
+ # encrypted volume -- metadata should match volume type
+ volume_type = self.created[0]
+
+ volume = db.volume_create(self.ctxt, {'volume_type_id':
+ volume_type['volume_type_id']})
+ values = db.volume_encryption_metadata_get(self.ctxt, volume.id)
+
+ expected = {
+ 'encryption_key_id': volume.encryption_key_id,
+ 'control_location': volume_type['control_location'],
+ 'cipher': volume_type['cipher'],
+ 'key_size': volume_type['key_size'],
+ 'provider': volume_type['provider'],
+ }
+ self.assertEqual(expected, values)
+
class DBAPIReservationTestCase(BaseTest):