diff --git a/cinder/db/migration.py b/cinder/db/migration.py index 6b16ae7071d..5806b517172 100644 --- a/cinder/db/migration.py +++ b/cinder/db/migration.py @@ -26,7 +26,7 @@ from cinder.db.sqlalchemy import api as db_api options.set_defaults(cfg.CONF) -INIT_VERSION = 122 +INIT_VERSION = 134 MIGRATE_REPO_PATH = os.path.join( os.path.abspath(os.path.dirname(__file__)), 'sqlalchemy', diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/124_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/124_placeholder.py deleted file mode 100644 index ba8618d991b..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/124_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Rocky backports. -# Do not use this number for new Stein work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/125_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/125_placeholder.py deleted file mode 100644 index ba8618d991b..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/125_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Rocky backports. -# Do not use this number for new Stein work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/126_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/126_placeholder.py deleted file mode 100644 index ba8618d991b..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/126_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Rocky backports. -# Do not use this number for new Stein work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/127_change_project_resource_attribute_for_quota_usages.py b/cinder/db/sqlalchemy/migrate_repo/versions/127_change_project_resource_attribute_for_quota_usages.py deleted file mode 100644 index 46ea597a8fe..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/127_change_project_resource_attribute_for_quota_usages.py +++ /dev/null @@ -1,38 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from sqlalchemy import MetaData, String, Table - - -def upgrade(migrate_engine): - """Increase the resource column size to the quota_usages table. - - The resource value is constructed from (prefix + volume_type_name), - but the length of volume_type_name is limited to 255, if we add a - prefix such as 'volumes_' or 'gigabytes_' to volume_type_name it - will exceed the db length limit. - """ - # On MariaDB, max length varies depending on the version and the InnoDB - # page size [1], so it is possible to have error 1071 ('Specified key was - # too long; max key length is 767 bytes"). Since this migration is to - # resolve a corner case, deployments with those DB versions won't be - # covered. - # [1]: https://mariadb.com/kb/en/library/innodb-limitations/#page-sizes - hide_failure = migrate_engine.name.startswith('mysql') - meta = MetaData(bind=migrate_engine) - - quota_usages = Table('quota_usages', meta, autoload=True) - try: - quota_usages.c.resource.alter(type=String(300)) - except Exception: - if not hide_failure: - raise diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/128_add_project_id_and_accepted_to_transfer.py b/cinder/db/sqlalchemy/migrate_repo/versions/128_add_project_id_and_accepted_to_transfer.py deleted file mode 100644 index 2ef539031a3..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/128_add_project_id_and_accepted_to_transfer.py +++ /dev/null @@ -1,34 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from sqlalchemy import Boolean, Column, MetaData, Table, String - - -def upgrade(migrate_engine): - """Add columns to the transfers table. - - Add source_project_id, destination_project_id and accepted columns to the - transfers table to improve volume transfer records. - """ - meta = MetaData(bind=migrate_engine) - transfers = Table('transfers', meta, autoload=True) - - if not hasattr(transfers.c, 'source_project_id'): - transfers.create_column(Column('source_project_id', String(255), - nullable=True)) - - if not hasattr(transfers.c, 'destination_project_id'): - transfers.create_column(Column('destination_project_id', String(255), - nullable=True)) - - if not hasattr(transfers.c, 'accepted'): - transfers.create_column(Column('accepted', Boolean, default=False)) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/129_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/129_placeholder.py deleted file mode 100644 index 81347f0cfd2..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/129_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Stein backports. -# Do not use this number for new Train work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/130_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/130_placeholder.py deleted file mode 100644 index 81347f0cfd2..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/130_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Stein backports. -# Do not use this number for new Train work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/131_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/131_placeholder.py deleted file mode 100644 index 81347f0cfd2..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/131_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Stein backports. -# Do not use this number for new Train work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/132_create_default_volume_type.py b/cinder/db/sqlalchemy/migrate_repo/versions/132_create_default_volume_type.py deleted file mode 100644 index 5cb097219d7..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/132_create_default_volume_type.py +++ /dev/null @@ -1,44 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import uuid - -from oslo_utils import timeutils -from sqlalchemy import MetaData, Table - -from cinder.volume import volume_types - - -def upgrade(migrate_engine): - """Create default volume type""" - - meta = MetaData(bind=migrate_engine) - now = timeutils.utcnow() - - # create a default volume type during cinder DB migration - vtypes = Table("volume_types", meta, autoload=True) - results = list(vtypes.select().where( - vtypes.c.name == volume_types.DEFAULT_VOLUME_TYPE and - vtypes.c.deleted is False).execute()) - if not results: - vtype_id = str(uuid.uuid4()) - volume_type_dict = { - 'id': vtype_id, - 'name': volume_types.DEFAULT_VOLUME_TYPE, - 'description': 'Default Volume Type', - 'created_at': now, - 'updated_at': now, - 'deleted': False, - 'is_public': True, - } - vtype = vtypes.insert() - vtype.execute(volume_type_dict) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/133_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/133_placeholder.py deleted file mode 100644 index 60508611f1c..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/133_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Train backports. -# Do not use this number for new Ussuri work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/134_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/134_placeholder.py deleted file mode 100644 index 60508611f1c..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/134_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Train backports. -# Do not use this number for new Ussuri work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/123_cinder_init.py b/cinder/db/sqlalchemy/migrate_repo/versions/135_cinder_init.py similarity index 95% rename from cinder/db/sqlalchemy/migrate_repo/versions/123_cinder_init.py rename to cinder/db/sqlalchemy/migrate_repo/versions/135_cinder_init.py index bdca01dc19c..565ee4e1edd 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/123_cinder_init.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/135_cinder_init.py @@ -23,6 +23,7 @@ from sqlalchemy import MetaData, String, Table, Text, UniqueConstraint, text from sqlalchemy.sql import expression from cinder.volume import group_types as volume_group_types +from cinder.volume import volume_types # Get default values via config. The defaults will either # come from the default values set in the quota option @@ -524,6 +525,9 @@ def define_tables(meta): Column('crypt_hash', String(255)), Column('expires_at', DateTime(timezone=False)), Column('no_snapshots', Boolean, default=False), + Column('source_project_id', String(255), nullable=True), + Column('destination_project_id', String(255), nullable=True), + Column('accepted', Boolean, default=False), mysql_engine='InnoDB', mysql_charset='utf8' ) @@ -904,3 +908,37 @@ def upgrade(migrate_engine): } grp_spec = group_type_specs.insert() grp_spec.execute(group_spec_dicts) + + # Increase the resource column size to the quota_usages table. + # + # The resource value is constructed from (prefix + volume_type_name), + # but the length of volume_type_name is limited to 255, if we add a + # prefix such as 'volumes_' or 'gigabytes_' to volume_type_name it + # will exceed the db length limit. + + quota_usages = Table('quota_usages', meta, autoload=True) + try: + quota_usages.c.resource.alter(type=String(300)) + except Exception: + # On MariaDB, max length varies depending on the version and the InnoDB + # page size [1], so it is possible to have error 1071 ('Specified key + # was too long; max key length is 767 bytes"). Since this migration is + # to resolve a corner case, deployments with those DB versions won't be + # covered. + # [1]: https://mariadb.com/kb/en/library/innodb-limitations/#page-sizes + if not migrate_engine.name.startswith('mysql'): + raise + + # Create default volume type + vol_types = Table("volume_types", meta, autoload=True) + volume_type_dict = { + 'id': str(uuid.uuid4()), + 'name': volume_types.DEFAULT_VOLUME_TYPE, + 'description': 'Default Volume Type', + 'created_at': now, + 'updated_at': now, + 'deleted': False, + 'is_public': True, + } + vol_type = vol_types.insert() + vol_type.execute(volume_type_dict) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/135_placeholder.py b/cinder/db/sqlalchemy/migrate_repo/versions/135_placeholder.py deleted file mode 100644 index 60508611f1c..00000000000 --- a/cinder/db/sqlalchemy/migrate_repo/versions/135_placeholder.py +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# This is a placeholder for Train backports. -# Do not use this number for new Ussuri work. New work starts after all the -# placeholders. -# -# See this for more information: -# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html - - -def upgrade(migrate_engine): - pass diff --git a/cinder/tests/unit/db/test_migrations.py b/cinder/tests/unit/db/test_migrations.py index f74fc902c93..a3720927461 100644 --- a/cinder/tests/unit/db/test_migrations.py +++ b/cinder/tests/unit/db/test_migrations.py @@ -108,12 +108,12 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin): # manner is provided in Cinder's developer documentation. # Reviewers: DO NOT ALLOW THINGS TO BE ADDED HERE WITHOUT CARE exceptions = [ - # NOTE(brinzhang): 127 changes size of quota_usage.resource + # NOTE(brinzhang): 135 changes size of quota_usage.resource # to 300. This should be safe for the 'quota_usage' db table, # because of the 255 is the length limit of volume_type_name, # it should be add the additional prefix before volume_type_name, # which we of course allow *this* size to 300. - 127, + 135, # 136 modifies the the tables having volume_type_id field to set # as non nullable 136,