Merge "Warn the user about orphaned extra records during keypair migration"
This commit is contained in:
commit
cbce1beda0
@ -1384,6 +1384,12 @@ def _migrate_instance_keypairs(ctxt, count):
|
|||||||
count_all = len(db_extras)
|
count_all = len(db_extras)
|
||||||
count_hit = 0
|
count_hit = 0
|
||||||
for db_extra in db_extras:
|
for db_extra in db_extras:
|
||||||
|
if db_extra.instance is None:
|
||||||
|
LOG.error(
|
||||||
|
('Instance %(uuid)s has been purged, but an instance_extra '
|
||||||
|
'record remains for it. Unable to migrate.'),
|
||||||
|
{'uuid': db_extra.instance_uuid})
|
||||||
|
continue
|
||||||
key_name = db_extra.instance.key_name
|
key_name = db_extra.instance.key_name
|
||||||
keypairs = objects.KeyPairList(objects=[])
|
keypairs = objects.KeyPairList(objects=[])
|
||||||
if key_name:
|
if key_name:
|
||||||
|
@ -1973,8 +1973,20 @@ class TestInstanceObjectMisc(test.TestCase):
|
|||||||
key_name='missingkey')
|
key_name='missingkey')
|
||||||
inst3.create()
|
inst3.create()
|
||||||
|
|
||||||
|
inst4 = objects.Instance(context=ctxt,
|
||||||
|
user_id=ctxt.user_id,
|
||||||
|
project_id=ctxt.project_id,
|
||||||
|
key_name='missingkey')
|
||||||
|
inst4.create()
|
||||||
|
inst4.destroy()
|
||||||
|
|
||||||
|
# NOTE(danms): Add an orphaned instance_extra record for
|
||||||
|
# a totally invalid instance to make sure we don't explode.
|
||||||
|
# See bug 1684861 for more information.
|
||||||
|
db.instance_extra_update_by_uuid(ctxt, 'foo', {})
|
||||||
|
|
||||||
hit, done = instance.migrate_instance_keypairs(ctxt, 10)
|
hit, done = instance.migrate_instance_keypairs(ctxt, 10)
|
||||||
self.assertEqual(2, hit)
|
self.assertEqual(3, hit)
|
||||||
self.assertEqual(2, done)
|
self.assertEqual(2, done)
|
||||||
db_extra = db.instance_extra_get_by_instance_uuid(
|
db_extra = db.instance_extra_get_by_instance_uuid(
|
||||||
ctxt, inst1.uuid, ['keypairs'])
|
ctxt, inst1.uuid, ['keypairs'])
|
||||||
|
Loading…
Reference in New Issue
Block a user