diff options
author | Morgan Fainberg <m@metacloud.com> | 2014-03-02 13:43:47 -0800 |
---|---|---|
committer | Morgan Fainberg <m@metacloud.com> | 2014-04-09 14:37:38 -0700 |
commit | dbdb938fc08452ea80379652ee101b6ebe006e3f (patch) | |
tree | e1b0f14eb7dec2e7b005b83102431fbd5119a419 /nova | |
parent | be0b03777530d94fd7b9d4bd29689f2561597247 (diff) | |
download | nova-dbdb938fc08452ea80379652ee101b6ebe006e3f.tar.gz |
Update user_id length to match Keystone schema in volume_usage_cache
Update the maximum length to match the Keystone schema for maximum
user_id length in volume_usage_cache. In the case that Keystone were
to leverage the full varchar 64, there would potentially be data loss
and/or collision of user_ids across records.
This change originates from the conversation about increasing the
length of user_ids in Keystone:
http://lists.openstack.org/pipermail/openstack-dev/2014-February/028125.html
Even with the length not changing, it is important to ensure there is no
loss of data/resolution when relying on user_id to identify users uniquely.
Closes-Bug: #1226171
Change-Id: I05a5644a29d6e2432311c2ee5331970d5e8b0683
Diffstat (limited to 'nova')
-rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/244_increase_user_id_length_volume_usage_cache.py | 31 | ||||
-rw-r--r-- | nova/db/sqlalchemy/models.py | 2 | ||||
-rw-r--r-- | nova/tests/db/test_migrations.py | 8 |
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.""" |