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
This commit is contained in:
Marc Koderer 2016-06-21 16:56:06 +02:00
parent 62e01f076a
commit 33ebd2742c
4 changed files with 117 additions and 3 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,3 @@
---
fixes:
- User_id and project_id DB fields are extended to also support LDAP setups.