Merge "Drop migrate_keypairs_to_api_db data migration"
This commit is contained in:
@@ -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 |
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user