Merge "Add a provider_id column to Volumes and Snapshots"

This commit is contained in:
Jenkins 2014-12-21 01:20:29 +00:00 committed by Gerrit Code Review
commit 9712c818d6
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# 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 Column
from sqlalchemy import MetaData, String, Table
def upgrade(migrate_engine):
"""Add provider_id column to volumes."""
meta = MetaData()
meta.bind = migrate_engine
volumes = Table('volumes', meta, autoload=True)
provider_id = Column('provider_id', String(255))
volumes.create_column(provider_id)
volumes.update().values(provider_id=None).execute()
def downgrade(migrate_engine):
"""Remove provider_id column from volumes."""
meta = MetaData()
meta.bind = migrate_engine
volumes = Table('volumes', meta, autoload=True)
provider_id = volumes.columns.provider_id
volumes.drop_column(provider_id)

View File

@ -0,0 +1,35 @@
# 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 Column
from sqlalchemy import MetaData, String, Table
def upgrade(migrate_engine):
"""Add provider_id column to snapshots."""
meta = MetaData()
meta.bind = migrate_engine
snapshots = Table('snapshots', meta, autoload=True)
provider_id = Column('provider_id', String(255))
snapshots.create_column(provider_id)
snapshots.update().values(provider_id=None).execute()
def downgrade(migrate_engine):
"""Remove provider_id column from snapshots."""
meta = MetaData()
meta.bind = migrate_engine
snapshots = Table('snapshots', meta, autoload=True)
provider_id = snapshots.columns.provider_id
snapshots.drop_column(provider_id)

View File

@ -146,6 +146,7 @@ class Volume(BASE, CinderBase):
provider_location = Column(String(255))
provider_auth = Column(String(255))
provider_geometry = Column(String(255))
provider_id = Column(String(255))
volume_type_id = Column(String(36))
source_volid = Column(String(36))
@ -431,6 +432,7 @@ class Snapshot(BASE, CinderBase):
volume_type_id = Column(String(36))
provider_location = Column(String(255))
provider_id = Column(String(255))
volume = relationship(Volume, backref="snapshots",
foreign_keys=volume_id,

View File

@ -704,6 +704,24 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
volume_types = db_utils.get_table(engine, 'volume_types')
self.assertNotIn('description', volume_types.c)
def _check_035(self, engine, data):
volumes = db_utils.get_table(engine, 'volumes')
self.assertIsInstance(volumes.c.provider_id.type,
sqlalchemy.types.VARCHAR)
def _post_downgrade_035(self, engine):
volumes = db_utils.get_table(engine, 'volumes')
self.assertNotIn('provider_id', volumes.c)
def _check_036(self, engine, data):
snapshots = db_utils.get_table(engine, 'snapshots')
self.assertIsInstance(snapshots.c.provider_id.type,
sqlalchemy.types.VARCHAR)
def _post_downgrade_036(self, engine):
snapshots = db_utils.get_table(engine, 'snapshots')
self.assertNotIn('provider_id', snapshots.c)
def test_walk_versions(self):
self.walk_versions(True, False)