diff options
author | Yang Yu <yuyangbj@cn.ibm.com> | 2013-11-06 08:30:33 -0600 |
---|---|---|
committer | Aaron Rosen <aaronorosen@gmail.com> | 2014-03-21 15:56:03 -0700 |
commit | 44c60c6be51f0de187fe51f7f3d0d3bf6ed57f94 (patch) | |
tree | bf9adf74417c653bb7f1b9cbc32544e0936e59fa | |
parent | efd628c9d604759adc11564bbea0e1ea082876ce (diff) | |
download | nova-44c60c6be51f0de187fe51f7f3d0d3bf6ed57f94.tar.gz |
Grizzly to Havana Upgrade wipes out Nova quota_usages
Migration script 216 will wipe out all data in quota_usages table
when user_id is null. After the upgrade from Grizzly to Havana is
completed, the migration script 203 adds a new column user_id, so
user_id is null for all data in quota_usages. So the correct
behaviour should be sync quota_usages table first and then delete
data if user_id is still null.
Fixing the existing migrate script is because we can not find
the quota_usages data after migration script 216.
Closes-bug:1245746
Change-Id: I4db62884785a4eb6e1db2c5b114b9c6e1b4882ad
-rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/216_sync_quota_usages.py | 8 | ||||
-rw-r--r-- | nova/tests/db/test_migrations.py | 20 |
2 files changed, 22 insertions, 6 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/216_sync_quota_usages.py b/nova/db/sqlalchemy/migrate_repo/versions/216_sync_quota_usages.py index 9a11150c42..f4d50946f9 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/216_sync_quota_usages.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/216_sync_quota_usages.py @@ -29,16 +29,16 @@ def upgrade(migrate_engine): quota_usages = Table('quota_usages', meta, autoload=True) reservations = Table('reservations', meta, autoload=True) + resource_tuples = select(columns=[quota_usages.c.resource], + distinct=True).execute().fetchall() + resources = [resource[0] for resource in resource_tuples] + for resource in ['instances', 'cores', 'ram', 'security_groups']: delete_null_rows(resource, quota_usages, reservations) for resource in ['fixed_ips', 'floating_ips', 'networks']: delete_per_user_rows(resource, quota_usages, reservations) - resource_tuples = select(columns=[quota_usages.c.resource], - distinct=True).execute().fetchall() - resources = [resource[0] for resource in resource_tuples] - if 'instances' in resources: sync_instances(meta, quota_usages) diff --git a/nova/tests/db/test_migrations.py b/nova/tests/db/test_migrations.py index fa33aec863..89796b1c2b 100644 --- a/nova/tests/db/test_migrations.py +++ b/nova/tests/db/test_migrations.py @@ -3088,12 +3088,16 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn): 'vcpus': 2, 'memory_mb': 256, 'uuid': 'uuid1', 'deleted': 0}, {'user_id': '234', 'project_id': '5678', - 'vcpus': 1, 'memory_mb': 256, 'deleted': 0}], + 'vcpus': 1, 'memory_mb': 256, 'deleted': 0}, + {'user_id': '4321', 'project_id': '1234', + 'vcpus': 1, 'memory_mb': 512, 'deleted': 0}], 'security_groups': [{'user_id': '1234', 'project_id': '5678', 'deleted': 0}, {'user_id': '234', 'project_id': '5678', 'deleted': 0}, {'user_id': '234', 'project_id': '5678', + 'deleted': 0}, + {'user_id': '4321', 'project_id': '1234', 'deleted': 0}], 'floating_ips': [{'deleted': 0, 'project_id': '5678', 'auto_assigned': False}, @@ -3107,10 +3111,14 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn): 'resource': 'instances', 'in_use': 1, 'reserved': 0}, {'user_id': None, 'project_id': '5678', 'resource': 'instances', 'in_use': 1, 'reserved': 0}, + {'user_id': None, 'project_id': '1234', + 'resource': 'instances', 'in_use': 1, 'reserved': 0}, {'user_id': '1234', 'project_id': '5678', 'resource': 'security_groups', 'in_use': 1, 'reserved': 0}, {'user_id': '234', 'project_id': '5678', 'resource': 'security_groups', 'in_use': 2, 'reserved': 0}, + {'user_id': None, 'project_id': '1234', + 'resource': 'security_groups', 'in_use': 1, 'reserved': 0}, {'user_id': None, 'project_id': '5678', 'resource': 'security_groups', 'in_use': 1, 'reserved': 0}, {'user_id': '1234', 'project_id': '5678', @@ -3157,7 +3165,9 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn): per_user = {'1234': {'instances': 1, 'cores': 2, 'ram': 256, 'security_groups': 1}, '234': {'instances': 1, 'cores': 1, 'ram': 256, - 'security_groups': 2}} + 'security_groups': 2}, + '4321': {'instances': 1, 'cores': 1, 'ram': 512, + 'security_groups': 1}} per_project = {'floating_ips': 2, 'fixed_ips': 1, 'networks': 1} @@ -3168,6 +3178,12 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn): ).fetchall() self.assertEqual(0, len(rows)) + rows = quota_usages.select().where( + quota_usages.c.user_id == '4321').where( + quota_usages.c.resource == resource).execute( + ).fetchall() + self.assertEqual(1, len(rows)) + for user in per_user.keys(): rows = quota_usages.select().where( quota_usages.c.user_id == user).where( |