summaryrefslogtreecommitdiff
path: root/nova
diff options
context:
space:
mode:
Diffstat (limited to 'nova')
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/244_increase_user_id_length_volume_usage_cache.py31
-rw-r--r--nova/db/sqlalchemy/models.py2
-rw-r--r--nova/tests/db/test_migrations.py8
3 files changed, 40 insertions, 1 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/244_increase_user_id_length_volume_usage_cache.py b/nova/db/sqlalchemy/migrate_repo/versions/244_increase_user_id_length_volume_usage_cache.py
new file mode 100644
index 0000000000..079003d733
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/244_increase_user_id_length_volume_usage_cache.py
@@ -0,0 +1,31 @@
+# All Rights Reserved.
+#
+# 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):
+ meta = MetaData(bind=migrate_engine)
+ table = Table('volume_usage_cache', meta, autoload=True)
+ col_resource = getattr(table.c, 'user_id')
+ # Match the maximum length of user_id in Keystone here instead of
+ # assuming explicitly a single UUID length.
+ col_resource.alter(type=String(64))
+
+
+def downgrade(migrate_engine):
+ meta = MetaData(bind=migrate_engine)
+ table = Table('volume_usage_cache', meta, autoload=True)
+ col_resource = getattr(table.c, 'user_id')
+ col_resource.alter(type=String(36))
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 9f8043cc7c..ae4a1c3bb0 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -1144,7 +1144,7 @@ class VolumeUsage(BASE, NovaBase):
volume_id = Column(String(36), nullable=False)
instance_uuid = Column(String(36))
project_id = Column(String(36))
- user_id = Column(String(36))
+ user_id = Column(String(64))
availability_zone = Column(String(255))
tot_last_refreshed = Column(DateTime)
tot_reads = Column(BigInteger, default=0)
diff --git a/nova/tests/db/test_migrations.py b/nova/tests/db/test_migrations.py
index 73531b986b..199aa5590c 100644
--- a/nova/tests/db/test_migrations.py
+++ b/nova/tests/db/test_migrations.py
@@ -695,6 +695,14 @@ class TestNovaMigrations(BaseWalkMigrationTestCase, CommonTestsMixIn):
# confirm compute_node_stats exists
db_utils.get_table(engine, 'compute_node_stats')
+ def _check_244(self, engine, data):
+ volume_usage_cache = db_utils.get_table(engine, 'volume_usage_cache')
+ self.assertEqual(64, volume_usage_cache.c.user_id.type.length)
+
+ def _post_downgrade_244(self, engine):
+ volume_usage_cache = db_utils.get_table(engine, 'volume_usage_cache')
+ self.assertEqual(36, volume_usage_cache.c.user_id.type.length)
+
class TestBaremetalMigrations(BaseWalkMigrationTestCase, CommonTestsMixIn):
"""Test sqlalchemy-migrate migrations."""