summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorBoris Pavlovic <boris@pavlovic.me>2013-02-18 23:51:57 +0400
committerBoris Pavlovic <boris@pavlovic.me>2013-03-26 09:05:59 +0400
commit7f185dff87a939f7a8ae8248528d0957dce7bc81 (patch)
treec99152795ad8354bb8fe47baf284867283abf9e4 /nova/tests
parent338714c0dbe5db5cda70069ba2abf15887ba5079 (diff)
Remove race condition (in InstanceTypes)
Soft delete all duplicate rows with the same name except one with the biggest value in `id` column. Soft delete all duplicate rows with the same flavorid except one with the biggest value in `id` column. Create UC on columns (name, deleted) and (flavorid, deleted) Replace Select then Insert -> Try to Insert. blueprint db-enforce-unique-keys Change-Id: If66d2f1387c2b2748784bf7ac9746b8d755b70a9
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_migrations.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index 8a8dc93f4..98c50aaa7 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -1106,6 +1106,51 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
self.assertEqual(result['value'], original['value'])
self.assertEqual(result['created_at'], None)
+ def _pre_upgrade_172(self, engine):
+ instance_types = get_table(engine, 'instance_types')
+ data = [
+ dict(id=21, name='uc_name0', memory_mb=128, vcpus=1,
+ root_gb=10, ephemeral_gb=0, flavorid="uc_flavor1", swap=0,
+ rxtx_factor=1.0, vcpu_weight=1, disabled=False,
+ is_public=True, deleted=0),
+ dict(id=22, name='uc_name1', memory_mb=128, vcpus=1,
+ root_gb=10, ephemeral_gb=0, flavorid="uc_flavor1", swap=0,
+ rxtx_factor=1.0, vcpu_weight=1, disabled=False,
+ is_public=True, deleted=0),
+ dict(id=23, name='uc_name2', memory_mb=128, vcpus=1,
+ root_gb=10, ephemeral_gb=0, flavorid="uc_flavor2", swap=0,
+ rxtx_factor=1.0, vcpu_weight=1, disabled=False,
+ is_public=True, deleted=0),
+ dict(id=24, name='uc_name2', memory_mb=128, vcpus=1,
+ root_gb=10, ephemeral_gb=0, flavorid="uc_flavor3", swap=0,
+ rxtx_factor=1.0, vcpu_weight=1, disabled=False,
+ is_public=True, deleted=0),
+ ]
+ engine.execute(instance_types.insert(), data)
+ return data
+
+ def _check_172(self, engine, data):
+ instance_types = get_table(engine, 'instance_types')
+
+ not_deleted = instance_types.c.deleted != instance_types.c.id
+
+ # There is only one instance_type with flavor `uc_flavor1`
+ uc_flavor1_rows = instance_types.select().\
+ where(instance_types.c.flavorid == 'uc_flavor1').\
+ where(not_deleted).\
+ execute().\
+ fetchall()
+
+ self.assertEqual(1, len(uc_flavor1_rows))
+
+ # There is only one instance_type with name `uc_name2`
+ uc_name2_rows = instance_types.select().\
+ where(instance_types.c.name == 'uc_name2').\
+ where(not_deleted).\
+ execute().\
+ fetchall()
+ self.assertEqual(1, len(uc_name2_rows))
+
class TestBaremetalMigrations(BaseMigrationTestCase, CommonTestsMixIn):
"""Test sqlalchemy-migrate migrations."""