From cec1808050495aa43a2b67058077063bf3b6f4ed Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 3 Apr 2019 11:35:37 -0400 Subject: [PATCH] Drop migrate_keypairs_to_api_db data migration This was added in Newton: I97b72ae3e7e8ea3d6b596870d8da3aaa689fd6b5 And was meant to migrate keypairs from the cell (nova) DB to the API DB. Before that though, the keypairs per instance would be migrated to the instance_extra table in the cell DB. The migration to instance_extra was dropped in Queens with change: Ie83e7bd807c2c79e5cbe1337292c2d1989d4ac03 As the commit message on ^ mentions, the 345 cell DB schema migration required that the cell DB keypairs table was empty before you could upgrade to Ocata. The migrate_keypairs_to_api_db routine only migrates any keypairs to the API DB if there are entries in the keypairs table in the cell DB, but because of that blocker migration in Ocata that cannot be the case anymore, so really migrate_keypairs_to_api_db is just wasting time querying the database during the online_data_migrations routine without it actually migrating anything, so we should just remove it. Change-Id: Ie56bc411880c6d1c04599cf9521e12e8b4878e1e Closes-Bug: #1822613 --- doc/source/cli/nova-manage.rst | 1 - nova/cmd/manage.py | 3 -- nova/objects/keypair.py | 47 ------------------------ nova/tests/functional/db/test_keypair.py | 45 ----------------------- 4 files changed, 96 deletions(-) diff --git a/doc/source/cli/nova-manage.rst b/doc/source/cli/nova-manage.rst index 25d988ef1d7a..b12aef2cca69 100644 --- a/doc/source/cli/nova-manage.rst +++ b/doc/source/cli/nova-manage.rst @@ -119,7 +119,6 @@ Nova Database | create_incomplete_consumers | 0 | 0 | | delete_build_requests_with_no_instance_uuid | 0 | 0 | | migrate_instances_add_request_spec | 2 | 0 | - | migrate_keypairs_to_api_db | 0 | 0 | | migrate_quota_classes_to_api_db | 0 | 0 | | migrate_quota_limits_to_api_db | 0 | 0 | | migration_migrate_to_uuid | 0 | 0 | diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index dc28cf45efa7..2620c9d53bd3 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -64,7 +64,6 @@ from nova.objects import compute_node as compute_node_obj from nova.objects import host_mapping as host_mapping_obj from nova.objects import instance as instance_obj from nova.objects import instance_mapping as instance_mapping_obj -from nova.objects import keypair as keypair_obj from nova.objects import quotas as quotas_obj from nova.objects import virtual_interface as virtual_interface_obj from nova import quota @@ -389,8 +388,6 @@ class DbCommands(object): # not migratable (or don't need migrating), but all migrations that can # complete have finished. online_migrations = ( - # Added in Newton - keypair_obj.migrate_keypairs_to_api_db, # Added in Ocata # NOTE(mriedem): This online migration is going to be backported to # Newton also since it's an upgrade issue when upgrading from Mitaka. diff --git a/nova/objects/keypair.py b/nova/objects/keypair.py index 6c141140cd11..915c71a6c3fe 100644 --- a/nova/objects/keypair.py +++ b/nova/objects/keypair.py @@ -20,7 +20,6 @@ from oslo_utils import versionutils from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import api_models -from nova.db.sqlalchemy import models as main_models from nova import exception from nova import objects from nova.objects import base @@ -236,49 +235,3 @@ class KeyPairList(base.ObjectListBase, base.NovaObject): def get_count_by_user(cls, context, user_id): return (cls._get_count_from_db(context, user_id) + db.key_pair_count_by_user(context, user_id)) - - -@db_api.pick_context_manager_reader -def _count_unmigrated_instances(context): - return context.session.query(main_models.InstanceExtra).\ - filter_by(keypairs=None).\ - filter_by(deleted=0).\ - count() - - -@db_api.pick_context_manager_reader -def _get_main_keypairs(context, limit): - return context.session.query(main_models.KeyPair).\ - filter_by(deleted=0).\ - limit(limit).\ - all() - - -def migrate_keypairs_to_api_db(context, count): - bad_instances = _count_unmigrated_instances(context) - if bad_instances: - LOG.error('Some instances are still missing keypair ' - 'information. Unable to run keypair migration ' - 'at this time.') - return 0, 0 - - main_keypairs = _get_main_keypairs(context, count) - done = 0 - for db_keypair in main_keypairs: - kp = objects.KeyPair(context=context, - user_id=db_keypair.user_id, - name=db_keypair.name, - fingerprint=db_keypair.fingerprint, - public_key=db_keypair.public_key, - type=db_keypair.type) - try: - kp._create() - except exception.KeyPairExists: - # NOTE(danms): If this got created somehow in the API DB, - # then it's newer and we just continue on to destroy the - # old one in the cell DB. - pass - db_api.key_pair_destroy(context, db_keypair.user_id, db_keypair.name) - done += 1 - - return len(main_keypairs), done diff --git a/nova/tests/functional/db/test_keypair.py b/nova/tests/functional/db/test_keypair.py index ffa47e702c8a..109208ca5b3d 100644 --- a/nova/tests/functional/db/test_keypair.py +++ b/nova/tests/functional/db/test_keypair.py @@ -131,51 +131,6 @@ class KeyPairObjectTestCase(test.TestCase): self.context.user_id) self.assertEqual(2, count) - def test_migrate_keypairs(self): - self._api_kp(name='apikey') - self._main_kp(name='mainkey1') - self._main_kp(name='mainkey2') - self._main_kp(name='mainkey3') - total, done = keypair.migrate_keypairs_to_api_db(self.context, 2) - self.assertEqual(2, total) - self.assertEqual(2, done) - - # NOTE(danms): This only fetches from the API DB - api_keys = objects.KeyPairList._get_from_db(self.context, - self.context.user_id, - limit=None, - marker=None) - self.assertEqual(3, len(api_keys)) - - # NOTE(danms): This only fetches from the main DB - main_keys = db_api.key_pair_get_all_by_user(self.context, - self.context.user_id) - self.assertEqual(1, len(main_keys)) - - self.assertEqual((1, 1), - keypair.migrate_keypairs_to_api_db(self.context, 100)) - self.assertEqual((0, 0), - keypair.migrate_keypairs_to_api_db(self.context, 100)) - - def test_migrate_keypairs_bails_on_unmigrated_instances(self): - objects.Instance(context=self.context, user_id=self.context.user_id, - project_id=self.context.project_id).create() - self._api_kp(name='apikey') - self._main_kp(name='mainkey1') - total, done = keypair.migrate_keypairs_to_api_db(self.context, 100) - self.assertEqual(0, total) - self.assertEqual(0, done) - - def test_migrate_keypairs_skips_existing(self): - self._api_kp(name='mykey') - self._main_kp(name='mykey') - total, done = keypair.migrate_keypairs_to_api_db(self.context, 100) - self.assertEqual(1, total) - self.assertEqual(1, done) - total, done = keypair.migrate_keypairs_to_api_db(self.context, 100) - self.assertEqual(0, total) - self.assertEqual(0, done) - def test_get_by_user_limit_and_marker(self): self._api_kp(name='apikey1') self._api_kp(name='apikey2')