Merge "Remove logging statements from migrations"

This commit is contained in:
Jenkins 2015-07-24 05:42:05 +00:00 committed by Gerrit Code Review
commit a3ec3dbc1f
25 changed files with 100 additions and 486 deletions

View File

@ -12,15 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime, ForeignKey from sqlalchemy import Boolean, Column, DateTime, ForeignKey
from sqlalchemy import Integer, MetaData, String, Table from sqlalchemy import Integer, MetaData, String, Table
from cinder.i18n import _LE, _LI
LOG = logging.getLogger(__name__)
def define_tables(meta): def define_tables(meta):
migrations = Table( migrations = Table(
@ -236,12 +230,7 @@ def upgrade(migrate_engine):
tables = define_tables(meta) tables = define_tables(meta)
for table in tables: for table in tables:
try: table.create()
table.create()
except Exception:
LOG.info(repr(table))
LOG.exception(_LE('Exception while creating table.'))
raise
if migrate_engine.name == "mysql": if migrate_engine.name == "mysql":
tables = ["sm_flavors", tables = ["sm_flavors",
@ -275,5 +264,4 @@ def downgrade(migrate_engine):
tables = define_tables(meta) tables = define_tables(meta)
tables.reverse() tables.reverse()
for table in tables: for table in tables:
LOG.info(_LI("dropping table %(table)s"), {'table': table})
table.drop() table.drop()

View File

@ -13,14 +13,9 @@
# under the License. # under the License.
from migrate import ForeignKeyConstraint from migrate import ForeignKeyConstraint
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import MetaData, Integer, String, Table, ForeignKey from sqlalchemy import MetaData, Integer, String, Table, ForeignKey
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -44,11 +39,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8', mysql_charset='utf8',
) )
try: quota_classes.create()
quota_classes.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(quota_classes))
raise
quota_usages = Table('quota_usages', meta, quota_usages = Table('quota_usages', meta,
Column('created_at', DateTime(timezone=False)), Column('created_at', DateTime(timezone=False)),
@ -69,11 +60,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8', mysql_charset='utf8',
) )
try: quota_usages.create()
quota_usages.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(quota_usages))
raise
reservations = Table('reservations', meta, reservations = Table('reservations', meta,
Column('created_at', DateTime(timezone=False)), Column('created_at', DateTime(timezone=False)),
@ -100,11 +87,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8', mysql_charset='utf8',
) )
try: reservations.create()
reservations.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(reservations))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -128,29 +111,14 @@ def downgrade(migrate_engine):
'name': fk_name} 'name': fk_name}
if fk_name: if fk_name:
try: fkey = ForeignKeyConstraint(**params)
fkey = ForeignKeyConstraint(**params) fkey.drop()
fkey.drop()
except Exception:
LOG.error(_LE("Dropping foreign key %s failed."), fk_name)
quota_classes = Table('quota_classes', meta, autoload=True) quota_classes = Table('quota_classes', meta, autoload=True)
try: quota_classes.drop()
quota_classes.drop()
except Exception:
LOG.error(_LE("quota_classes table not dropped"))
raise
quota_usages = Table('quota_usages', meta, autoload=True) quota_usages = Table('quota_usages', meta, autoload=True)
try: quota_usages.drop()
quota_usages.drop()
except Exception:
LOG.error(_LE("quota_usages table not dropped"))
raise
reservations = Table('reservations', meta, autoload=True) reservations = Table('reservations', meta, autoload=True)
try: reservations.drop()
reservations.drop()
except Exception:
LOG.error(_LE("reservations table not dropped"))
raise

View File

@ -12,14 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column, DateTime, Text, Boolean from sqlalchemy import Column, DateTime, Text, Boolean
from sqlalchemy import MetaData, Integer, String, Table, ForeignKey from sqlalchemy import MetaData, Integer, String, Table, ForeignKey
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -56,8 +51,6 @@ def upgrade(migrate_engine):
try: try:
volume_glance_metadata.create() volume_glance_metadata.create()
except Exception: except Exception:
LOG.exception(_LE("Exception while creating table "
"'volume_glance_metadata'"))
meta.drop_all(tables=[volume_glance_metadata]) meta.drop_all(tables=[volume_glance_metadata])
raise raise
@ -68,8 +61,4 @@ def downgrade(migrate_engine):
volume_glance_metadata = Table('volume_glance_metadata', volume_glance_metadata = Table('volume_glance_metadata',
meta, autoload=True) meta, autoload=True)
try: volume_glance_metadata.drop()
volume_glance_metadata.drop()
except Exception:
LOG.error(_LE("volume_glance_metadata table not dropped"))
raise

View File

@ -13,13 +13,8 @@
import uuid import uuid
from migrate import ForeignKeyConstraint from migrate import ForeignKeyConstraint
from oslo_log import log as logging
from sqlalchemy import Integer, MetaData, String, Table from sqlalchemy import Integer, MetaData, String, Table
from cinder.i18n import _LI
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
"""Convert volume_type_id to UUID.""" """Convert volume_type_id to UUID."""
@ -79,7 +74,6 @@ def upgrade(migrate_engine):
name=fkey_name) name=fkey_name)
try: try:
fkey.create() fkey.create()
LOG.info(_LI('Created foreign key %s'), fkey_name)
except Exception: except Exception:
if migrate_engine.url.get_dialect().name.startswith('sqlite'): if migrate_engine.url.get_dialect().name.startswith('sqlite'):
pass pass
@ -158,7 +152,6 @@ def downgrade(migrate_engine):
name=fkey_name) name=fkey_name)
try: try:
fkey.create() fkey.create()
LOG.info(_LI('Created foreign key %s'), fkey_name)
except Exception: except Exception:
if migrate_engine.url.get_dialect().name.startswith('sqlite'): if migrate_engine.url.get_dialect().name.startswith('sqlite'):
pass pass

View File

@ -10,12 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column from sqlalchemy import Column
from sqlalchemy import MetaData, String, Table from sqlalchemy import MetaData, String, Table
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
"""Add source volume id column to volumes.""" """Add source volume id column to volumes."""

View File

@ -13,14 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import MetaData, Integer, String, Table from sqlalchemy import MetaData, Integer, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -51,11 +46,7 @@ def upgrade(migrate_engine):
mysql_engine='InnoDB' mysql_engine='InnoDB'
) )
try: backups.create()
backups.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(backups))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -63,8 +54,4 @@ def downgrade(migrate_engine):
meta.bind = migrate_engine meta.bind = migrate_engine
backups = Table('backups', meta, autoload=True) backups = Table('backups', meta, autoload=True)
try: backups.drop()
backups.drop()
except Exception:
LOG.error(_LE("backups table not dropped"))
raise

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import Integer, MetaData, String, Table, ForeignKey from sqlalchemy import Integer, MetaData, String, Table, ForeignKey
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -40,11 +35,7 @@ def upgrade(migrate_engine):
mysql_engine='InnoDB' mysql_engine='InnoDB'
) )
try: snapshot_metadata.create()
snapshot_metadata.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(snapshot_metadata))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -53,8 +44,4 @@ def downgrade(migrate_engine):
snapshot_metadata = Table('snapshot_metadata', snapshot_metadata = Table('snapshot_metadata',
meta, meta,
autoload=True) autoload=True)
try: snapshot_metadata.drop()
snapshot_metadata.drop()
except Exception:
LOG.error(_LE("snapshot_metadata table not dropped"))
raise

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import MetaData, String, Table, ForeignKey from sqlalchemy import MetaData, String, Table, ForeignKey
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -43,11 +38,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8' mysql_charset='utf8'
) )
try: transfers.create()
transfers.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(transfers))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -56,8 +47,4 @@ def downgrade(migrate_engine):
transfers = Table('transfers', transfers = Table('transfers',
meta, meta,
autoload=True) autoload=True)
try: transfers.drop()
transfers.drop()
except Exception:
LOG.error(_LE("transfers table not dropped"))
raise

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime, Integer from sqlalchemy import Boolean, Column, DateTime, Integer
from sqlalchemy import MetaData, String, Table from sqlalchemy import MetaData, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
TABLE_NAME = 'migrations' TABLE_NAME = 'migrations'
@ -26,11 +21,7 @@ def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
meta.bind = migrate_engine meta.bind = migrate_engine
table = Table(TABLE_NAME, meta, autoload=True) table = Table(TABLE_NAME, meta, autoload=True)
try: table.drop()
table.drop()
except Exception:
LOG.error(_LE("migrations table not dropped"))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -56,8 +47,4 @@ def downgrade(migrate_engine):
mysql_charset='utf8' mysql_charset='utf8'
) )
try: table.create()
table.create()
except Exception:
LOG.error(_LE("Table |%s| not created"), repr(table))
raise

View File

@ -12,14 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime, ForeignKey from sqlalchemy import Boolean, Column, DateTime, ForeignKey
from sqlalchemy import Integer, MetaData, String, Table from sqlalchemy import Integer, MetaData, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -32,12 +27,7 @@ def upgrade(migrate_engine):
tables = [sm_volume, sm_backend_config, sm_flavors] tables = [sm_volume, sm_backend_config, sm_flavors]
for table in tables: for table in tables:
try: table.drop()
table.drop()
except Exception:
LOG.exception(_LE('Exception while dropping table %s.'),
repr(table))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -95,9 +85,4 @@ def downgrade(migrate_engine):
tables = [sm_flavors, sm_backend_config, sm_volume] tables = [sm_flavors, sm_backend_config, sm_volume]
for table in tables: for table in tables:
try: table.create()
table.create()
except Exception:
LOG.exception(_LE('Exception while creating table %s.'),
repr(table))
raise

View File

@ -13,15 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column, ForeignKey, MetaData, Table from sqlalchemy import Column, ForeignKey, MetaData, Table
from sqlalchemy import Boolean, DateTime, Integer, String from sqlalchemy import Boolean, DateTime, Integer, String
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData(bind=migrate_engine) meta = MetaData(bind=migrate_engine)
@ -29,26 +23,14 @@ def upgrade(migrate_engine):
# encryption key UUID -- must be stored per volume # encryption key UUID -- must be stored per volume
volumes = Table('volumes', meta, autoload=True) volumes = Table('volumes', meta, autoload=True)
encryption_key = Column('encryption_key_id', String(36)) encryption_key = Column('encryption_key_id', String(36))
try: volumes.create_column(encryption_key)
volumes.create_column(encryption_key)
except Exception:
LOG.error(_LE("Column |%s| not created!"), repr(encryption_key))
raise
# encryption key UUID and volume type id -- must be stored per snapshot # encryption key UUID and volume type id -- must be stored per snapshot
snapshots = Table('snapshots', meta, autoload=True) snapshots = Table('snapshots', meta, autoload=True)
encryption_key = Column('encryption_key_id', String(36)) encryption_key = Column('encryption_key_id', String(36))
try: snapshots.create_column(encryption_key)
snapshots.create_column(encryption_key)
except Exception:
LOG.error(_LE("Column |%s| not created!"), repr(encryption_key))
raise
volume_type = Column('volume_type_id', String(36)) volume_type = Column('volume_type_id', String(36))
try: snapshots.create_column(volume_type)
snapshots.create_column(volume_type)
except Exception:
LOG.error(_LE("Column |%s| not created!"), repr(volume_type))
raise
volume_types = Table('volume_types', meta, autoload=True) volume_types = Table('volume_types', meta, autoload=True)
@ -75,11 +57,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8' mysql_charset='utf8'
) )
try: encryption.create()
encryption.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(encryption))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -87,29 +65,13 @@ def downgrade(migrate_engine):
# drop encryption key UUID for volumes # drop encryption key UUID for volumes
volumes = Table('volumes', meta, autoload=True) volumes = Table('volumes', meta, autoload=True)
try: volumes.c.encryption_key_id.drop()
volumes.c.encryption_key_id.drop()
except Exception:
LOG.error(_LE("encryption_key_id column not dropped from volumes"))
raise
# drop encryption key UUID and volume type id for snapshots # drop encryption key UUID and volume type id for snapshots
snapshots = Table('snapshots', meta, autoload=True) snapshots = Table('snapshots', meta, autoload=True)
try: snapshots.c.encryption_key_id.drop()
snapshots.c.encryption_key_id.drop() snapshots.c.volume_type_id.drop()
except Exception:
LOG.error(_LE("encryption_key_id column not dropped from snapshots"))
raise
try:
snapshots.c.volume_type_id.drop()
except Exception:
LOG.error(_LE("volume_type_id column not dropped from snapshots"))
raise
# drop encryption types table # drop encryption types table
encryption = Table('encryption', meta, autoload=True) encryption = Table('encryption', meta, autoload=True)
try: encryption.drop()
encryption.drop()
except Exception:
LOG.error(_LE("encryption table not dropped"))
raise

View File

@ -14,15 +14,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import ForeignKey, MetaData, String, Table from sqlalchemy import ForeignKey, MetaData, String, Table
from migrate import ForeignKeyConstraint from migrate import ForeignKeyConstraint
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
"""Add volume_type_rate_limit table.""" """Add volume_type_rate_limit table."""
@ -44,23 +39,14 @@ def upgrade(migrate_engine):
mysql_charset='utf8' mysql_charset='utf8'
) )
try: quality_of_service_specs.create()
quality_of_service_specs.create()
except Exception:
LOG.error(_LE("Table quality_of_service_specs not created!"))
raise
volume_types = Table('volume_types', meta, autoload=True) volume_types = Table('volume_types', meta, autoload=True)
qos_specs_id = Column('qos_specs_id', String(36), qos_specs_id = Column('qos_specs_id', String(36),
ForeignKey('quality_of_service_specs.id')) ForeignKey('quality_of_service_specs.id'))
try: volume_types.create_column(qos_specs_id)
volume_types.create_column(qos_specs_id) volume_types.update().values(qos_specs_id=None).execute()
volume_types.update().values(qos_specs_id=None).execute()
except Exception:
LOG.error(_LE("Added qos_specs_id column to volume type table "
"failed."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -80,24 +66,11 @@ def downgrade(migrate_engine):
'refcolumns': [ref_table.c['id']], 'refcolumns': [ref_table.c['id']],
'name': 'volume_types_ibfk_1'} 'name': 'volume_types_ibfk_1'}
try: fkey = ForeignKeyConstraint(**params)
fkey = ForeignKeyConstraint(**params) fkey.drop()
fkey.drop()
except Exception:
LOG.error(_LE("Dropping foreign key volume_types_ibfk_1 failed"))
volume_types = Table('volume_types', meta, autoload=True) volume_types = Table('volume_types', meta, autoload=True)
qos_specs_id = Column('qos_specs_id', String(36)) qos_specs_id = Column('qos_specs_id', String(36))
try: volume_types.drop_column(qos_specs_id)
volume_types.drop_column(qos_specs_id) qos_specs.drop()
except Exception:
LOG.error(_LE("Dropping qos_specs_id column failed."))
raise
try:
qos_specs.drop()
except Exception:
LOG.error(_LE("Dropping quality_of_service_specs table failed."))
raise

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import Integer, MetaData, String, Table, ForeignKey from sqlalchemy import Integer, MetaData, String, Table, ForeignKey
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -41,11 +36,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8' mysql_charset='utf8'
) )
try: volume_admin_metadata.create()
volume_admin_metadata.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(volume_admin_metadata))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -54,8 +45,4 @@ def downgrade(migrate_engine):
volume_admin_metadata = Table('volume_admin_metadata', volume_admin_metadata = Table('volume_admin_metadata',
meta, meta,
autoload=True) autoload=True)
try: volume_admin_metadata.drop()
volume_admin_metadata.drop()
except Exception:
LOG.error(_LE("volume_admin_metadata table not dropped"))
raise

View File

@ -15,11 +15,8 @@
import datetime import datetime
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from sqlalchemy import MetaData, Table from sqlalchemy import MetaData, Table
from cinder.i18n import _LE, _LI
# Get default values via config. The defaults will either # Get default values via config. The defaults will either
# come from the default values set in the quota option # come from the default values set in the quota option
# configuration or via cinder.conf if the user has configured # configuration or via cinder.conf if the user has configured
@ -28,7 +25,6 @@ CONF = cfg.CONF
CONF.import_opt('quota_volumes', 'cinder.quota') CONF.import_opt('quota_volumes', 'cinder.quota')
CONF.import_opt('quota_snapshots', 'cinder.quota') CONF.import_opt('quota_snapshots', 'cinder.quota')
CONF.import_opt('quota_gigabytes', 'cinder.quota') CONF.import_opt('quota_gigabytes', 'cinder.quota')
LOG = logging.getLogger(__name__)
CLASS_NAME = 'default' CLASS_NAME = 'default'
CREATED_AT = datetime.datetime.now() # noqa CREATED_AT = datetime.datetime.now() # noqa
@ -47,34 +43,27 @@ def upgrade(migrate_engine):
# Do not add entries if there are already 'default' entries. We don't # Do not add entries if there are already 'default' entries. We don't
# want to write over something the user added. # want to write over something the user added.
if rows: if rows:
LOG.info(_LI("Found existing 'default' entries in the quota_classes "
"table. Skipping insertion of default values."))
return return
try: # Set default volumes
# Set default volumes qci = quota_classes.insert()
qci = quota_classes.insert() qci.execute({'created_at': CREATED_AT,
qci.execute({'created_at': CREATED_AT, 'class_name': CLASS_NAME,
'class_name': CLASS_NAME, 'resource': 'volumes',
'resource': 'volumes', 'hard_limit': CONF.quota_volumes,
'hard_limit': CONF.quota_volumes, 'deleted': False, })
'deleted': False, }) # Set default snapshots
# Set default snapshots qci.execute({'created_at': CREATED_AT,
qci.execute({'created_at': CREATED_AT, 'class_name': CLASS_NAME,
'class_name': CLASS_NAME, 'resource': 'snapshots',
'resource': 'snapshots', 'hard_limit': CONF.quota_snapshots,
'hard_limit': CONF.quota_snapshots, 'deleted': False, })
'deleted': False, }) # Set default gigabytes
# Set default gigabytes qci.execute({'created_at': CREATED_AT,
qci.execute({'created_at': CREATED_AT, 'class_name': CLASS_NAME,
'class_name': CLASS_NAME, 'resource': 'gigabytes',
'resource': 'gigabytes', 'hard_limit': CONF.quota_gigabytes,
'hard_limit': CONF.quota_gigabytes, 'deleted': False, })
'deleted': False, })
LOG.info(_LI("Added default quota class data into the DB."))
except Exception:
LOG.error(_LE("Default quota class data not inserted into the DB."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):

View File

@ -12,13 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Index, MetaData, Table from sqlalchemy import Index, MetaData, Table
from cinder.i18n import _LI
LOG = logging.getLogger(__name__)
def _get_deleted_expire_index(table): def _get_deleted_expire_index(table):
members = sorted(['deleted', 'expire']) members = sorted(['deleted', 'expire'])
@ -33,8 +28,6 @@ def upgrade(migrate_engine):
reservations = Table('reservations', meta, autoload=True) reservations = Table('reservations', meta, autoload=True)
if _get_deleted_expire_index(reservations): if _get_deleted_expire_index(reservations):
LOG.info(_LI('Skipped adding reservations_deleted_expire_idx '
'because an equivalent index already exists.'))
return return
# Based on expire_reservations query # Based on expire_reservations query
@ -54,6 +47,3 @@ def downgrade(migrate_engine):
index = _get_deleted_expire_index(reservations) index = _get_deleted_expire_index(reservations)
if index: if index:
index.drop(migrate_engine) index.drop(migrate_engine)
else:
LOG.info(_LI('Skipped removing reservations_deleted_expire_idx '
'because index does not exist.'))

View File

@ -12,12 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column from sqlalchemy import Column
from sqlalchemy import MetaData, String, Table from sqlalchemy import MetaData, String, Table
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
"""Add replication columns to volumes.""" """Add replication columns to volumes."""

View File

@ -14,14 +14,9 @@
# under the License. # under the License.
from migrate import ForeignKeyConstraint from migrate import ForeignKeyConstraint
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import ForeignKey, MetaData, String, Table from sqlalchemy import ForeignKey, MetaData, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -47,11 +42,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8', mysql_charset='utf8',
) )
try: consistencygroups.create()
consistencygroups.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(consistencygroups))
raise
# New table # New table
cgsnapshots = Table( cgsnapshots = Table(
@ -73,36 +64,22 @@ def upgrade(migrate_engine):
mysql_charset='utf8', mysql_charset='utf8',
) )
try: cgsnapshots.create()
cgsnapshots.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(cgsnapshots))
raise
# Add column to volumes table # Add column to volumes table
volumes = Table('volumes', meta, autoload=True) volumes = Table('volumes', meta, autoload=True)
consistencygroup_id = Column('consistencygroup_id', String(36), consistencygroup_id = Column('consistencygroup_id', String(36),
ForeignKey('consistencygroups.id')) ForeignKey('consistencygroups.id'))
try: volumes.create_column(consistencygroup_id)
volumes.create_column(consistencygroup_id) volumes.update().values(consistencygroup_id=None).execute()
volumes.update().values(consistencygroup_id=None).execute()
except Exception:
LOG.error(_LE("Adding consistencygroup_id column to volumes table"
" failed."))
raise
# Add column to snapshots table # Add column to snapshots table
snapshots = Table('snapshots', meta, autoload=True) snapshots = Table('snapshots', meta, autoload=True)
cgsnapshot_id = Column('cgsnapshot_id', String(36), cgsnapshot_id = Column('cgsnapshot_id', String(36),
ForeignKey('cgsnapshots.id')) ForeignKey('cgsnapshots.id'))
try: snapshots.create_column(cgsnapshot_id)
snapshots.create_column(cgsnapshot_id) snapshots.update().values(cgsnapshot_id=None).execute()
snapshots.update().values(cgsnapshot_id=None).execute()
except Exception:
LOG.error(_LE("Adding cgsnapshot_id column to snapshots table"
" failed."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -120,12 +97,8 @@ def downgrade(migrate_engine):
'refcolumns': [ref_table.c['id']], 'refcolumns': [ref_table.c['id']],
'name': 'snapshots_ibfk_1'} 'name': 'snapshots_ibfk_1'}
try: fkey = ForeignKeyConstraint(**params)
fkey = ForeignKeyConstraint(**params) fkey.drop()
fkey.drop()
except Exception:
LOG.error(_LE("Dropping foreign key 'cgsnapshot_id' in "
"the 'snapshots' table failed."))
snapshots = Table('snapshots', meta, autoload=True) snapshots = Table('snapshots', meta, autoload=True)
cgsnapshot_id = snapshots.columns.cgsnapshot_id cgsnapshot_id = snapshots.columns.cgsnapshot_id
@ -142,12 +115,8 @@ def downgrade(migrate_engine):
'refcolumns': [ref_table.c['id']], 'refcolumns': [ref_table.c['id']],
'name': 'volumes_ibfk_1'} 'name': 'volumes_ibfk_1'}
try: fkey = ForeignKeyConstraint(**params)
fkey = ForeignKeyConstraint(**params) fkey.drop()
fkey.drop()
except Exception:
LOG.error(_LE("Dropping foreign key 'consistencygroup_id' in "
"the 'volumes' table failed."))
volumes = Table('volumes', meta, autoload=True) volumes = Table('volumes', meta, autoload=True)
consistencygroup_id = volumes.columns.consistencygroup_id consistencygroup_id = volumes.columns.consistencygroup_id
@ -155,16 +124,8 @@ def downgrade(migrate_engine):
# Drop table # Drop table
cgsnapshots = Table('cgsnapshots', meta, autoload=True) cgsnapshots = Table('cgsnapshots', meta, autoload=True)
try: cgsnapshots.drop()
cgsnapshots.drop()
except Exception:
LOG.error(_LE("cgsnapshots table not dropped"))
raise
# Drop table # Drop table
consistencygroups = Table('consistencygroups', meta, autoload=True) consistencygroups = Table('consistencygroups', meta, autoload=True)
try: consistencygroups.drop()
consistencygroups.drop()
except Exception:
LOG.error(_LE("consistencygroups table not dropped"))
raise

View File

@ -15,18 +15,14 @@
import datetime import datetime
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from sqlalchemy import MetaData, Table from sqlalchemy import MetaData, Table
from cinder.i18n import _LE, _LI
# Get default values via config. The defaults will either # Get default values via config. The defaults will either
# come from the default values set in the quota option # come from the default values set in the quota option
# configuration or via cinder.conf if the user has configured # configuration or via cinder.conf if the user has configured
# default values for quotas there. # default values for quotas there.
CONF = cfg.CONF CONF = cfg.CONF
CONF.import_opt('quota_consistencygroups', 'cinder.quota') CONF.import_opt('quota_consistencygroups', 'cinder.quota')
LOG = logging.getLogger(__name__)
CLASS_NAME = 'default' CLASS_NAME = 'default'
CREATED_AT = datetime.datetime.now() # noqa CREATED_AT = datetime.datetime.now() # noqa
@ -45,24 +41,15 @@ def upgrade(migrate_engine):
# Do not add entries if there are already 'consistencygroups' entries. # Do not add entries if there are already 'consistencygroups' entries.
if rows: if rows:
LOG.info(_LI("Found existing 'consistencygroups' entries in the "
"quota_classes table. Skipping insertion."))
return return
try: # Set consistencygroups
# Set consistencygroups qci = quota_classes.insert()
qci = quota_classes.insert() qci.execute({'created_at': CREATED_AT,
qci.execute({'created_at': CREATED_AT, 'class_name': CLASS_NAME,
'class_name': CLASS_NAME, 'resource': 'consistencygroups',
'resource': 'consistencygroups', 'hard_limit': CONF.quota_consistencygroups,
'hard_limit': CONF.quota_consistencygroups, 'deleted': False, })
'deleted': False, })
LOG.info(_LI("Added default consistencygroups quota class data into "
"the DB."))
except Exception:
LOG.error(_LE("Default consistencygroups quota class data not "
"inserted into the DB."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Boolean, Column, DateTime, UniqueConstraint from sqlalchemy import Boolean, Column, DateTime, UniqueConstraint
from sqlalchemy import Integer, MetaData, String, Table, ForeignKey from sqlalchemy import Integer, MetaData, String, Table, ForeignKey
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -25,13 +20,9 @@ def upgrade(migrate_engine):
volume_types = Table('volume_types', meta, autoload=True) volume_types = Table('volume_types', meta, autoload=True)
is_public = Column('is_public', Boolean) is_public = Column('is_public', Boolean)
try: volume_types.create_column(is_public)
volume_types.create_column(is_public) # pylint: disable=E1120
# pylint: disable=E1120 volume_types.update().values(is_public=True).execute()
volume_types.update().values(is_public=True).execute()
except Exception:
LOG.error(_LE("Column |%s| not created!"), repr(is_public))
raise
volume_type_projects = Table( volume_type_projects = Table(
'volume_type_projects', meta, 'volume_type_projects', meta,
@ -47,11 +38,7 @@ def upgrade(migrate_engine):
mysql_engine='InnoDB', mysql_engine='InnoDB',
) )
try: volume_type_projects.create()
volume_type_projects.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(volume_type_projects))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -60,15 +47,7 @@ def downgrade(migrate_engine):
volume_types = Table('volume_types', meta, autoload=True) volume_types = Table('volume_types', meta, autoload=True)
is_public = volume_types.columns.is_public is_public = volume_types.columns.is_public
try: volume_types.drop_column(is_public)
volume_types.drop_column(is_public)
except Exception:
LOG.error(_LE("volume_types.is_public column not dropped"))
raise
volume_type_projects = Table('volume_type_projects', meta, autoload=True) volume_type_projects = Table('volume_type_projects', meta, autoload=True)
try: volume_type_projects.drop()
volume_type_projects.drop()
except Exception:
LOG.error(_LE("volume_type_projects table not dropped"))
raise

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column from sqlalchemy import Column
from sqlalchemy import MetaData, String, Table from sqlalchemy import MetaData, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
"""Add cgsnapshot_id column to consistencygroups.""" """Add cgsnapshot_id column to consistencygroups."""
@ -27,13 +22,8 @@ def upgrade(migrate_engine):
consistencygroups = Table('consistencygroups', meta, autoload=True) consistencygroups = Table('consistencygroups', meta, autoload=True)
cgsnapshot_id = Column('cgsnapshot_id', String(36)) cgsnapshot_id = Column('cgsnapshot_id', String(36))
try: consistencygroups.create_column(cgsnapshot_id)
consistencygroups.create_column(cgsnapshot_id) consistencygroups.update().values(cgsnapshot_id=None).execute()
consistencygroups.update().values(cgsnapshot_id=None).execute()
except Exception:
LOG.error(_LE("Adding cgsnapshot_id column to consistencygroups "
"table failed."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -44,9 +34,4 @@ def downgrade(migrate_engine):
consistencygroups = Table('consistencygroups', meta, autoload=True) consistencygroups = Table('consistencygroups', meta, autoload=True)
cgsnapshot_id = consistencygroups.columns.cgsnapshot_id cgsnapshot_id = consistencygroups.columns.cgsnapshot_id
try: consistencygroups.drop_column(cgsnapshot_id)
consistencygroups.drop_column(cgsnapshot_id)
except Exception:
LOG.error(_LE("Dropping cgsnapshot_id column from consistencygroups "
"table failed."))
raise

View File

@ -10,14 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column, DateTime, Integer from sqlalchemy import Column, DateTime, Integer
from sqlalchemy import MetaData, String, Table, UniqueConstraint from sqlalchemy import MetaData, String, Table, UniqueConstraint
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -38,11 +33,7 @@ def upgrade(migrate_engine):
mysql_charset='utf8' mysql_charset='utf8'
) )
try: initiator_data.create()
initiator_data.create()
except Exception:
LOG.error(_LE("Table |%s| not created!"), repr(initiator_data))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -50,9 +41,4 @@ def downgrade(migrate_engine):
meta.bind = migrate_engine meta.bind = migrate_engine
table_name = 'driver_initiator_data' table_name = 'driver_initiator_data'
initiator_data = Table(table_name, meta, autoload=True) initiator_data = Table(table_name, meta, autoload=True)
try: initiator_data.drop()
initiator_data.drop()
except Exception:
LOG.error(_LE("%(table_name)s table not dropped"),
{'table_name': table_name})
raise

View File

@ -14,13 +14,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column, MetaData, String, Table from sqlalchemy import Column, MetaData, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
@ -29,12 +24,8 @@ def upgrade(migrate_engine):
backups = Table('backups', meta, autoload=True) backups = Table('backups', meta, autoload=True)
parent_id = Column('parent_id', String(length=36)) parent_id = Column('parent_id', String(length=36))
try: backups.create_column(parent_id)
backups.create_column(parent_id) backups.update().values(parent_id=None).execute()
backups.update().values(parent_id=None).execute()
except Exception:
LOG.error(_LE("Adding parent_id column to backups table failed."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
@ -44,8 +35,4 @@ def downgrade(migrate_engine):
backups = Table('backups', meta, autoload=True) backups = Table('backups', meta, autoload=True)
parent_id = backups.columns.parent_id parent_id = backups.columns.parent_id
try: backups.drop_column(parent_id)
backups.drop_column(parent_id)
except Exception:
LOG.error(_LE("Dropping parent_id column from backups table failed."))
raise

View File

@ -16,15 +16,10 @@
import datetime import datetime
import uuid import uuid
from oslo_log import log as logging
import six import six
from sqlalchemy import Boolean, Column, DateTime from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import ForeignKey, MetaData, String, Table from sqlalchemy import ForeignKey, MetaData, String, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
CREATED_AT = datetime.datetime.now() # noqa CREATED_AT = datetime.datetime.now() # noqa
@ -59,11 +54,7 @@ def upgrade(migrate_engine):
mysql_engine='InnoDB' mysql_engine='InnoDB'
) )
try: volume_attachment.create()
volume_attachment.create()
except Exception:
LOG.error(_LE("Table volume_attachment not created!"))
raise
# now migrate existing volume attachment info into the # now migrate existing volume attachment info into the
# new volume_attachment table # new volume_attachment table
@ -139,9 +130,4 @@ def downgrade(migrate_engine):
attach_time=attachment.attach_time, attach_time=attachment.attach_time,
instance_uuid=attachment.instance_uuid).\ instance_uuid=attachment.instance_uuid).\
execute() execute()
try: volume_attachment.drop()
volume_attachment.drop()
except Exception:
LOG.error(_LE("Dropping volume_attachment table failed."))
raise

View File

@ -10,33 +10,19 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from sqlalchemy import Column, MetaData, DateTime, Table from sqlalchemy import Column, MetaData, DateTime, Table
from cinder.i18n import _LE
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
meta = MetaData() meta = MetaData()
meta.bind = migrate_engine meta.bind = migrate_engine
services = Table('services', meta, autoload=True) services = Table('services', meta, autoload=True)
modified_at = Column('modified_at', DateTime(timezone=False)) modified_at = Column('modified_at', DateTime(timezone=False))
try: services.create_column(modified_at)
services.create_column(modified_at)
except Exception:
LOG.error(_LE("Adding modified_at column to services table failed."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):
meta = MetaData() meta = MetaData()
meta.bind = migrate_engine meta.bind = migrate_engine
services = Table('services', meta, autoload=True) services = Table('services', meta, autoload=True)
try: services.drop_column('modified_at')
services.drop_column('modified_at')
except Exception:
LOG.error(_LE("Unable to drop modified_at column from services"
"table."))
raise

View File

@ -10,19 +10,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_log import log as logging
from oslo_utils import timeutils from oslo_utils import timeutils
from sqlalchemy import MetaData, Table from sqlalchemy import MetaData, Table
from cinder.i18n import _LE
# Get default value via config. The default will either # Get default value via config. The default will either
# come from the default value set in the quota configuration option # come from the default value set in the quota configuration option
# or via cinder.conf if the user has configured # or via cinder.conf if the user has configured
# default value for per volume size limit there. # default value for per volume size limit there.
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine): def upgrade(migrate_engine):
"""Add default "per_volume_gigabytes" row into DB.""" """Add default "per_volume_gigabytes" row into DB."""
@ -39,18 +35,13 @@ def upgrade(migrate_engine):
if row: if row:
return return
try: # Set default per_volume_gigabytes for per volume size
# Set default per_volume_gigabytes for per volume size qci = quota_classes.insert()
qci = quota_classes.insert() qci.execute({'created_at': timeutils.utcnow(),
qci.execute({'created_at': timeutils.utcnow(), 'class_name': 'default',
'class_name': 'default', 'resource': 'per_volume_gigabytes',
'resource': 'per_volume_gigabytes', 'hard_limit': -1,
'hard_limit': -1, 'deleted': False, })
'deleted': False, })
except Exception:
LOG.error(_LE("Default per_volume_gigabytes row not inserted "
"into the quota_classes."))
raise
def downgrade(migrate_engine): def downgrade(migrate_engine):