LOG = logging.getLogger(__name__)
-def _populate_encryption_types(volume_types, encryption):
- # TODO(joel-coffman): The database currently doesn't enforce uniqueness
- # for volume type names.
- default_encryption_types = {
- 'dm-crypt': {
- 'cipher': 'aes-xts-plain64',
- 'control_location': 'front-end',
- 'key_size': 512, # only half of key is used for cipher in XTS mode
- 'provider':
- 'nova.volume.encryptors.cryptsetup.CryptsetupEncryptor',
- },
- 'LUKS': {
- 'cipher': 'aes-xts-plain64',
- 'control_location': 'front-end',
- 'key_size': 512, # only half of key is used for cipher in XTS mode
- 'provider': 'nova.volume.encryptors.luks.LuksEncryptor',
- },
- }
-
- try:
- volume_types_insert = volume_types.insert()
- encryption_insert = encryption.insert()
-
- for key, values in default_encryption_types.iteritems():
- current_time = timeutils.utcnow()
- volume_type = {
- 'id': uuidutils.generate_uuid(),
- 'name': key,
- 'created_at': current_time,
- 'updated_at': current_time,
- 'deleted': False,
- }
- volume_types_insert.execute(volume_type)
-
- values['id'] = uuidutils.generate_uuid()
- values['volume_type_id'] = volume_type['id']
-
- values['created_at'] = timeutils.utcnow()
- values['updated_at'] = values['created_at']
- values['deleted'] = False
-
- encryption_insert.execute(values)
- except Exception:
- LOG.error(_("Error populating default encryption types!"))
- # NOTE(joel-coffman): do not raise because deployed environment may
- # have volume types already defined with the same name
-
-
def upgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)
LOG.error(_("Table |%s| not created!"), repr(encryption))
raise
- _populate_encryption_types(volume_types, encryption)
-
def downgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)
except Exception:
LOG.error(_("encryption table not dropped"))
raise
-
- # TODO(joel-coffman): Should remove volume_types related to encryption...
from oslo.config import cfg
from cinder.backup import driver as backup_driver
-from cinder.brick.initiator import connector as brick_conn
from cinder.brick.iscsi import iscsi
from cinder.brick.local_dev import lvm as brick_lvm
from cinder import context
CONF = cfg.CONF
+ENCRYPTION_PROVIDER = 'nova.volume.encryptors.cryptsetup.CryptsetupEncryptor'
+
fake_opt = [
cfg.StrOpt('fake_opt', default='fake', help='fake opts')
]
# Create default volume type
vol_type = conf_fixture.def_vol_type
db.volume_type_create(context.get_admin_context(),
- dict(name=vol_type, extra_specs={}))
+ {'name': vol_type, 'extra_specs': {}})
db_vol_type = db.volume_type_get_by_name(context.get_admin_context(),
vol_type)
# Create volume with specific volume type
vol_type = 'test'
db.volume_type_create(context.get_admin_context(),
- dict(name=vol_type, extra_specs={}))
+ {'name': vol_type, 'extra_specs': {}})
db_vol_type = db.volume_type_get_by_name(context.get_admin_context(),
vol_type)
def test_create_volume_with_encrypted_volume_type(self):
self.stubs.Set(keymgr, "API", fake_keymgr.fake_api)
+ ctxt = context.get_admin_context()
+
+ db.volume_type_create(ctxt,
+ {'id': '61298380-0c12-11e3-bfd6-4b48424183be',
+ 'name': 'LUKS'})
+ db.volume_type_encryption_update_or_create(
+ ctxt,
+ '61298380-0c12-11e3-bfd6-4b48424183be',
+ {'control_location': 'front-end', 'provider': ENCRYPTION_PROVIDER})
+
volume_api = cinder.volume.api.API()
- db_vol_type = db.volume_type_get_by_name(context.get_admin_context(),
- 'LUKS')
+ db_vol_type = db.volume_type_get_by_name(ctxt, 'LUKS')
volume = volume_api.create(self.context,
1,
"""
self.stubs.Set(keymgr, 'API', fake_keymgr.fake_api)
+ ctxt = context.get_admin_context()
+
+ db.volume_type_create(ctxt,
+ {'id': '61298380-0c12-11e3-bfd6-4b48424183be',
+ 'name': 'LUKS'})
+ db.volume_type_encryption_update_or_create(
+ ctxt,
+ '61298380-0c12-11e3-bfd6-4b48424183be',
+ {'control_location': 'front-end', 'provider': ENCRYPTION_PROVIDER})
+
volume_api = cinder.volume.api.API()
db_vol_type = db.volume_type_get_by_name(context.get_admin_context(),
volume_api = cinder.volume.api.API()
+ ctxt = context.get_admin_context()
+
+ db.volume_type_create(ctxt,
+ {'id': '61298380-0c12-11e3-bfd6-4b48424183be',
+ 'name': 'LUKS'})
+ db.volume_type_encryption_update_or_create(
+ ctxt,
+ '61298380-0c12-11e3-bfd6-4b48424183be',
+ {'control_location': 'front-end', 'provider': ENCRYPTION_PROVIDER})
+
db_vol_type = db.volume_type_get_by_name(context.get_admin_context(),
'LUKS')
volume_src = volume_api.create(self.context,
def test_create_volume_from_snapshot_fail_bad_size(self):
"""Test volume can't be created from snapshot with bad volume size."""
volume_api = cinder.volume.api.API()
- snapshot = dict(id=1234,
- status='available',
- volume_size=10)
+ snapshot = {'id': 1234,
+ 'status': 'available',
+ 'volume_size': 10}
self.assertRaises(exception.InvalidInput,
volume_api.create,
self.context,