]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add a provider_id column to Volumes and Snapshots
authorJohn Griffith <john.griffith8@gmail.com>
Fri, 19 Dec 2014 22:14:22 +0000 (15:14 -0700)
committerJohn Griffith <john.griffith8@gmail.com>
Sat, 20 Dec 2014 00:06:01 +0000 (17:06 -0700)
There are a number of cases where there's some really ugly mapping
work in drivers to try and map the backend device-id to the
Cinder ID of a Volume or Snapshot.  Most drivers seem to work around this in
their own creative ways using their own mechanisms (metadata,
naming schemes etc).

It seems like it would be useful for a number of reasons however to
go ahead and add a simple column to the Volumes table that could be
used for storing a backend ID for the Volume and Snapshot.

Change-Id: Id07cdd1e03feac71ff34325d5abc68c5adc48266

cinder/db/sqlalchemy/migrate_repo/versions/035_add_provider_id_column.py [new file with mode: 0644]
cinder/db/sqlalchemy/migrate_repo/versions/036_add_provider_id_column_to_snapshots.py [new file with mode: 0644]
cinder/db/sqlalchemy/models.py
cinder/tests/test_migrations.py

diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/035_add_provider_id_column.py b/cinder/db/sqlalchemy/migrate_repo/versions/035_add_provider_id_column.py
new file mode 100644 (file)
index 0000000..e0a1ce8
--- /dev/null
@@ -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)
diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/036_add_provider_id_column_to_snapshots.py b/cinder/db/sqlalchemy/migrate_repo/versions/036_add_provider_id_column_to_snapshots.py
new file mode 100644 (file)
index 0000000..7698ec8
--- /dev/null
@@ -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)
index 5667f119e9fcd496083899979b16be389c2ef6ca..73f960a33eb3d5a00809b786409eae78c5569478 100644 (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,
index 1cd8c42d7d3948d8fbb58d8d852c57b1612218cf..739090c1206dc764d81ad74b4424281c0fe59795 100644 (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)