From e62d0cb93a4ac788f208982d5d24ced4bc7c4c8f Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 26 Feb 2013 00:47:49 +0000 Subject: 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 --- nova/tests/test_migrations.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'nova/tests') 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') -- cgit