From 44a2d41797aaf575a3e4b8c9c0bbf4f94bee3aca Mon Sep 17 00:00:00 2001 From: Marc Koderer Date: Tue, 21 Jun 2016 16:56:06 +0200 Subject: [PATCH] Change user_id and project_id to 255 length In case keystone is used with LDAP the user_id/project_id can be more than 60 characters. This will cause the issue that users cannot create any share-network or security_service. Change-Id: I2e2ccce32bf31850c9ffd74d9612cf5237d782fe Closes-bug: #1594824 (cherry picked from commit 33ebd2742c9434ca1e196200d2389dba71f2d2d3) --- ...a83cfd85b_change_user_project_id_length.py | 62 +++++++++++++++++++ manila/db/sqlalchemy/models.py | 6 +- .../alembic/migrations_data_checks.py | 49 +++++++++++++++ ..._user_project_length-93cc8d1c32926e75.yaml | 3 + 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 manila/db/migrations/alembic/versions/221a83cfd85b_change_user_project_id_length.py create mode 100644 releasenotes/notes/change_user_project_length-93cc8d1c32926e75.yaml diff --git a/manila/db/migrations/alembic/versions/221a83cfd85b_change_user_project_id_length.py b/manila/db/migrations/alembic/versions/221a83cfd85b_change_user_project_id_length.py new file mode 100644 index 0000000000..062c48502e --- /dev/null +++ b/manila/db/migrations/alembic/versions/221a83cfd85b_change_user_project_id_length.py @@ -0,0 +1,62 @@ +# Copyright 2016 SAP SE +# +# 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. + +"""change_user_id_length + +Revision ID: 221a83cfd85b +Revises: eb6d5544cbbd +Create Date: 2016-06-21 14:22:48.314501 + +""" + +# revision identifiers, used by Alembic. +revision = '221a83cfd85b' +down_revision = 'eb6d5544cbbd' + +from alembic import op +from oslo_log import log +import sqlalchemy as sa + +from manila.i18n import _LI + + +LOG = log.getLogger(__name__) + + +def upgrade(): + LOG.info(_LI("Changing user_id length for share_networks")) + op.alter_column("share_networks", "user_id", + type_=sa.String(length=255)) + + LOG.info(_LI("Changing project_id length for share_networks")) + op.alter_column("share_networks", "project_id", + type_=sa.String(length=255)) + + LOG.info(_LI("Changing project_id length for security_services")) + op.alter_column("security_services", "project_id", + type_=sa.String(length=255)) + + +def downgrade(): + LOG.info(_LI("Changing back user_id length for share_networks")) + op.alter_column("share_networks", "user_id", + type_=sa.String(length=36)) + + LOG.info(_LI("Changing back project_id length for share_networks")) + op.alter_column("share_networks", "project_id", + type_=sa.String(length=36)) + + LOG.info(_LI("Changing back project_id length for security_services")) + op.alter_column("security_services", "project_id", + type_=sa.String(length=36)) diff --git a/manila/db/sqlalchemy/models.py b/manila/db/sqlalchemy/models.py index 835bbaee5b..0e92764701 100644 --- a/manila/db/sqlalchemy/models.py +++ b/manila/db/sqlalchemy/models.py @@ -730,7 +730,7 @@ class SecurityService(BASE, ManilaBase): __tablename__ = 'security_services' id = Column(String(36), primary_key=True) deleted = Column(String(36), default='False') - project_id = Column(String(36), nullable=False) + project_id = Column(String(255), nullable=False) type = Column(String(32), nullable=False) dns_ip = Column(String(64), nullable=True) server = Column(String(255), nullable=True) @@ -746,8 +746,8 @@ class ShareNetwork(BASE, ManilaBase): __tablename__ = 'share_networks' id = Column(String(36), primary_key=True, nullable=False) deleted = Column(String(36), default='False') - project_id = Column(String(36), nullable=False) - user_id = Column(String(36), nullable=False) + project_id = Column(String(255), nullable=False) + user_id = Column(String(255), nullable=False) nova_net_id = Column(String(36), nullable=True) neutron_net_id = Column(String(36), nullable=True) neutron_subnet_id = Column(String(36), nullable=True) diff --git a/manila/tests/db/migrations/alembic/migrations_data_checks.py b/manila/tests/db/migrations/alembic/migrations_data_checks.py index 3a3098cfbe..87e2813aff 100644 --- a/manila/tests/db/migrations/alembic/migrations_data_checks.py +++ b/manila/tests/db/migrations/alembic/migrations_data_checks.py @@ -606,3 +606,52 @@ class ShareSnapshotInstanceNewProviderLocationColumnChecks( self.test_case.assertFalse(hasattr(ss, 'provider_location')) self.test_case.assertEqual('new_snapshot_instance_id', ss.id) self.test_case.assertEqual('new_snapshot_id', ss.snapshot_id) + + +@map_to_migration('221a83cfd85b') +class ShareNetwoksFieldLengthChecks(BaseMigrationChecks): + def setup_upgrade_data(self, engine): + user_id = '123456789123456789' + project_id = 'project_id' + + # Create share network data + share_network_data = { + 'id': 'foo_share_network_id_2', + 'user_id': user_id, + 'project_id': project_id, + } + sn_table = utils.load_table('share_networks', engine) + engine.execute(sn_table.insert(share_network_data)) + + # Create security_service data + security_services_data = { + 'id': 'foo_security_services_id', + 'type': 'foo_type', + 'project_id': project_id + } + ss_table = utils.load_table('security_services', engine) + engine.execute(ss_table.insert(security_services_data)) + + def _check_length_for_table_columns(self, table_name, engine, + cols, length): + table = utils.load_table(table_name, engine) + db_result = engine.execute(table.select()) + self.test_case.assertTrue(db_result.rowcount > 0) + + for col in cols: + self.test_case.assertEqual(table.columns.get(col).type.length, + length) + + def check_upgrade(self, engine, data): + self._check_length_for_table_columns('share_networks', engine, + ('user_id', 'project_id'), 255) + + self._check_length_for_table_columns('security_services', engine, + ('project_id',), 255) + + def check_downgrade(self, engine): + self._check_length_for_table_columns('share_networks', engine, + ('user_id', 'project_id'), 36) + + self._check_length_for_table_columns('security_services', engine, + ('project_id',), 36) diff --git a/releasenotes/notes/change_user_project_length-93cc8d1c32926e75.yaml b/releasenotes/notes/change_user_project_length-93cc8d1c32926e75.yaml new file mode 100644 index 0000000000..6423db6467 --- /dev/null +++ b/releasenotes/notes/change_user_project_length-93cc8d1c32926e75.yaml @@ -0,0 +1,3 @@ +--- +fixes: + - User_id and project_id DB fields are extended to also support LDAP setups.