]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
The DB migration shouldn't populate types table
authorMichael Kerrin <michael.kerrin@hp.com>
Fri, 23 Aug 2013 14:42:46 +0000 (14:42 +0000)
committerDuncan Thomas <duncan.thomas@hp.com>
Fri, 23 Aug 2013 17:57:01 +0000 (18:57 +0100)
It is up to the system adminisator to do this via an API call.

Also fixes up a few cases of dict() being used rather than the prefered {}
(https://github.com/openstack-dev/hacking/blob/master/HACKING.rst#dictionarieslists)

Fixes bug: 1215962

Change-Id: I6b2eea0c03467b157ec147292dbea54e7f99006c

cinder/db/sqlalchemy/migrate_repo/versions/017_add_encryption_information.py
cinder/tests/test_volume.py

index 60d31eaae461ab06ecd7e1fee563cf8bf4325a9a..6b80969d1b56b0a847e2afeacc6aa1090c3deacc 100644 (file)
@@ -26,54 +26,6 @@ from cinder.openstack.common import uuidutils
 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)
 
@@ -131,8 +83,6 @@ def upgrade(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)
@@ -165,5 +115,3 @@ def downgrade(migrate_engine):
     except Exception:
         LOG.error(_("encryption table not dropped"))
         raise
-
-    # TODO(joel-coffman): Should remove volume_types related to encryption...
index 424401e7fc29fe383aac4823c56bbbdd2098fa97..36fd1653578fee16cae80ddf914e3b48e3af3515 100644 (file)
@@ -30,7 +30,6 @@ import mox
 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
@@ -65,6 +64,8 @@ QUOTAS = quota.QUOTAS
 
 CONF = cfg.CONF
 
+ENCRYPTION_PROVIDER = 'nova.volume.encryptors.cryptsetup.CryptsetupEncryptor'
+
 fake_opt = [
     cfg.StrOpt('fake_opt', default='fake', help='fake opts')
 ]
@@ -269,7 +270,7 @@ class VolumeTestCase(BaseVolumeTestCase):
         # 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)
@@ -285,7 +286,7 @@ class VolumeTestCase(BaseVolumeTestCase):
         # 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)
 
@@ -299,10 +300,19 @@ class VolumeTestCase(BaseVolumeTestCase):
     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,
@@ -372,6 +382,16 @@ class VolumeTestCase(BaseVolumeTestCase):
         """
         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(),
@@ -416,6 +436,16 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         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,
@@ -450,9 +480,9 @@ class VolumeTestCase(BaseVolumeTestCase):
     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,