diff options
-rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py | 8 | ||||
-rw-r--r-- | nova/tests/test_migrations.py | 25 |
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') |