summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-12 16:19:34 +0000
committerGerrit Code Review <review@openstack.org>2017-06-12 16:19:34 +0000
commit14e7c9300daac2f4c40ec4fdd79986b35545edcf (patch)
tree91943802ec44f8cffe154002fd377987f5731acd
parent4b3424616f3e0b253ea9fb2430950cc1b554df69 (diff)
parent593e7081148b2b15f5923a8d7c609ae71dcbdbb6 (diff)
Merge "Warn the user about orphaned extra records during keypair migration" into stable/ocata
-rw-r--r--nova/objects/instance.py6
-rw-r--r--nova/tests/unit/objects/test_instance.py14
2 files changed, 19 insertions, 1 deletions
diff --git a/nova/objects/instance.py b/nova/objects/instance.py
index ca805b7..e0d79e2 100644
--- a/nova/objects/instance.py
+++ b/nova/objects/instance.py
@@ -1384,6 +1384,12 @@ def _migrate_instance_keypairs(ctxt, count):
1384 count_all = len(db_extras) 1384 count_all = len(db_extras)
1385 count_hit = 0 1385 count_hit = 0
1386 for db_extra in db_extras: 1386 for db_extra in db_extras:
1387 if db_extra.instance is None:
1388 LOG.error(
1389 ('Instance %(uuid)s has been purged, but an instance_extra '
1390 'record remains for it. Unable to migrate.'),
1391 {'uuid': db_extra.instance_uuid})
1392 continue
1387 key_name = db_extra.instance.key_name 1393 key_name = db_extra.instance.key_name
1388 keypairs = objects.KeyPairList(objects=[]) 1394 keypairs = objects.KeyPairList(objects=[])
1389 if key_name: 1395 if key_name:
diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py
index 13f59e9..e5f7026 100644
--- a/nova/tests/unit/objects/test_instance.py
+++ b/nova/tests/unit/objects/test_instance.py
@@ -1973,8 +1973,20 @@ class TestInstanceObjectMisc(test.TestCase):
1973 key_name='missingkey') 1973 key_name='missingkey')
1974 inst3.create() 1974 inst3.create()
1975 1975
1976 inst4 = objects.Instance(context=ctxt,
1977 user_id=ctxt.user_id,
1978 project_id=ctxt.project_id,
1979 key_name='missingkey')
1980 inst4.create()
1981 inst4.destroy()
1982
1983 # NOTE(danms): Add an orphaned instance_extra record for
1984 # a totally invalid instance to make sure we don't explode.
1985 # See bug 1684861 for more information.
1986 db.instance_extra_update_by_uuid(ctxt, 'foo', {})
1987
1976 hit, done = instance.migrate_instance_keypairs(ctxt, 10) 1988 hit, done = instance.migrate_instance_keypairs(ctxt, 10)
1977 self.assertEqual(2, hit) 1989 self.assertEqual(3, hit)
1978 self.assertEqual(2, done) 1990 self.assertEqual(2, done)
1979 db_extra = db.instance_extra_get_by_instance_uuid( 1991 db_extra = db.instance_extra_get_by_instance_uuid(
1980 ctxt, inst1.uuid, ['keypairs']) 1992 ctxt, inst1.uuid, ['keypairs'])