summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2013-02-26 00:47:49 +0000
committerRick Harris <rconradharris@gmail.com>2013-02-26 00:49:59 +0000
commite62d0cb93a4ac788f208982d5d24ced4bc7c4c8f (patch)
tree4aa6e46d159d14a384dbedcbbeccf415ea0601fe
parentd9bbcfb76646cb77d9dfc867f057917b3e059a4f (diff)
downloadnova-e62d0cb93a4ac788f208982d5d24ced4bc7c4c8f.tar.gz
nova-e62d0cb93a4ac788f208982d5d24ced4bc7c4c8f.tar.xz
nova-e62d0cb93a4ac788f208982d5d24ced4bc7c4c8f.zip
Migration 147: Prevent duplicate aggregate_hosts
If an aggregate_host record is already present, then the `upgrade` shouldn't attempt to add it again. Change-Id: Ib7ab10fa7c166ccaa3df6a96eb08c7ebcd0af38c
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py8
-rw-r--r--nova/tests/test_migrations.py25
2 files changed, 31 insertions, 2 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py b/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py
index d93cd1ead..5c079584d 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py
@@ -58,8 +58,12 @@ def upgrade(migrate_engine):
})
# add host to zone
agg_hosts = Table('aggregate_hosts', meta, autoload=True)
- row = agg_hosts.insert()
- row.execute({'host': rec['host'], 'aggregate_id': agg_id})
+ num_hosts = agg_hosts.count().where(
+ agg_hosts.c.host == rec['host']).where(
+ agg_hosts.c.aggregate_id == agg_id).execute().scalar()
+ if num_hosts == 0:
+ agg_hosts.insert().execute({'host': rec['host'],
+ 'aggregate_id': agg_id})
services.drop_column('availability_zone')
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index 55963a81b..60efcf34f 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -588,8 +588,24 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
services = get_table(engine, 'services')
engine.execute(services.insert(), data)
+ self._pre_upgrade_147_no_duplicate_aggregate_hosts(engine)
return data
+ def _pre_upgrade_147_no_duplicate_aggregate_hosts(self, engine):
+ engine.execute(get_table(engine, 'aggregate_metadata').insert(), [
+ {'aggregate_id': 1,
+ 'key': 'availability_zone',
+ 'value': 'custom_az'}])
+
+ engine.execute(get_table(engine, 'aggregate_hosts').insert(), [
+ {'aggregate_id': 1,
+ 'host': 'compute-host3'}])
+
+ engine.execute(get_table(engine, 'services').insert(), [
+ {'id': 99, 'host': 'compute-host3',
+ 'binary': 'nova-compute', 'topic': 'compute',
+ 'report_count': 0, 'availability_zone': 'custom_az'}])
+
def _check_147(self, engine, data):
aggregate_md = get_table(engine, 'aggregate_metadata')
aggregate_hosts = get_table(engine, 'aggregate_hosts')
@@ -612,6 +628,15 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
).execute().first()
self.assertEqual(host, None)
+ self._check_147_no_duplicate_aggregate_hosts(engine, data)
+
+ def _check_147_no_duplicate_aggregate_hosts(self, engine, data):
+ aggregate_hosts = get_table(engine, 'aggregate_hosts')
+ agg1_hosts = [h['host'] for h in aggregate_hosts.select(
+ aggregate_hosts.c.aggregate_id == 1
+ ).execute().fetchall()]
+ self.assertEqual(['compute-host3'], agg1_hosts)
+
# migration 149, changes IPAddr storage format
def _pre_upgrade_149(self, engine):
provider_fw_rules = get_table(engine, 'provider_fw_rules')