Merge "Remove instance.keypairs migration code"
This commit is contained in:
commit
da38050adf
|
@ -58,7 +58,6 @@ from nova.objects import aggregate as aggregate_obj
|
|||
from nova.objects import block_device as block_device_obj
|
||||
from nova.objects import build_request as build_request_obj
|
||||
from nova.objects import host_mapping as host_mapping_obj
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import instance_group as instance_group_obj
|
||||
from nova.objects import keypair as keypair_obj
|
||||
from nova.objects import quotas as quotas_obj
|
||||
|
@ -384,8 +383,6 @@ class DbCommands(object):
|
|||
"""Class for managing the main database."""
|
||||
|
||||
online_migrations = (
|
||||
# Added in Newton
|
||||
instance_obj.migrate_instance_keypairs,
|
||||
# Added in Newton
|
||||
request_spec.migrate_instances_add_request_spec,
|
||||
# Added in Newton
|
||||
|
|
|
@ -21,7 +21,6 @@ from oslo_serialization import jsonutils
|
|||
from oslo_utils import timeutils
|
||||
from oslo_utils import versionutils
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.sql import null
|
||||
|
||||
|
@ -964,24 +963,10 @@ class Instance(base.NovaPersistentObject, base.NovaObject,
|
|||
self.keypairs = inst.keypairs
|
||||
self.keypairs.obj_reset_changes(recursive=True)
|
||||
self.obj_reset_changes(['keypairs'])
|
||||
return
|
||||
|
||||
# NOTE(danms): We need to load from the old location by name
|
||||
# if we don't have them in extra. Only do this from the main
|
||||
# database as instances were created with keypairs in extra
|
||||
# before keypairs were moved to the api database.
|
||||
self.keypairs = objects.KeyPairList(objects=[])
|
||||
try:
|
||||
key = objects.KeyPair.get_by_name(self._context,
|
||||
self.user_id,
|
||||
self.key_name,
|
||||
localonly=True)
|
||||
self.keypairs.objects.append(key)
|
||||
except exception.KeypairNotFound:
|
||||
pass
|
||||
# NOTE(danms): If we loaded from legacy, we leave the keypairs
|
||||
# attribute dirty in hopes someone else will save it for us
|
||||
|
||||
else:
|
||||
self.keypairs = objects.KeyPairList(objects=[])
|
||||
# NOTE(danms): We leave the keypairs attribute dirty in hopes
|
||||
# someone else will save it for us
|
||||
elif db_keypairs:
|
||||
self.keypairs = objects.KeyPairList.obj_from_primitive(
|
||||
jsonutils.loads(db_keypairs))
|
||||
|
@ -1477,44 +1462,3 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
|||
'ram': <count across user>}}
|
||||
"""
|
||||
return cls._get_counts_in_db(context, project_id, user_id=user_id)
|
||||
|
||||
|
||||
@db_api.pick_context_manager_writer
|
||||
def _migrate_instance_keypairs(ctxt, count):
|
||||
db_extras = ctxt.session.query(models.InstanceExtra).\
|
||||
options(joinedload('instance')).\
|
||||
filter_by(keypairs=None).\
|
||||
filter_by(deleted=0).\
|
||||
limit(count).\
|
||||
all()
|
||||
|
||||
count_all = len(db_extras)
|
||||
count_hit = 0
|
||||
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
|
||||
keypairs = objects.KeyPairList(objects=[])
|
||||
if key_name:
|
||||
try:
|
||||
key = objects.KeyPair.get_by_name(ctxt,
|
||||
db_extra.instance.user_id,
|
||||
key_name)
|
||||
keypairs.objects.append(key)
|
||||
except exception.KeypairNotFound:
|
||||
LOG.warning(
|
||||
'Instance %(uuid)s keypair %(keyname)s not found',
|
||||
{'uuid': db_extra.instance_uuid, 'keyname': key_name})
|
||||
db_extra.keypairs = jsonutils.dumps(keypairs.obj_to_primitive())
|
||||
db_extra.save(ctxt.session)
|
||||
count_hit += 1
|
||||
|
||||
return count_all, count_hit
|
||||
|
||||
|
||||
def migrate_instance_keypairs(ctxt, count):
|
||||
return _migrate_instance_keypairs(ctxt, count)
|
||||
|
|
|
@ -24,7 +24,6 @@ from nova.cells import rpcapi as cells_rpcapi
|
|||
from nova.compute import flavors
|
||||
from nova.compute import task_states
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
|
@ -314,25 +313,6 @@ class _TestInstanceObject(object):
|
|||
self.assertEqual('foo', inst.keypairs[0].name)
|
||||
self.assertNotIn('keypairs', inst.obj_what_changed())
|
||||
|
||||
@mock.patch('nova.objects.KeyPair.get_by_name')
|
||||
def test_lazy_load_keypairs_from_legacy(self, mock_get):
|
||||
mock_get.return_value = objects.KeyPair(name='foo')
|
||||
|
||||
inst = objects.Instance(context=self.context,
|
||||
user_id=self.context.user_id,
|
||||
key_name='foo',
|
||||
project_id=self.context.project_id)
|
||||
inst.create()
|
||||
|
||||
inst = objects.Instance.get_by_uuid(self.context, inst.uuid)
|
||||
self.assertNotIn('keypairs', inst)
|
||||
self.assertEqual('foo', inst.keypairs[0].name)
|
||||
self.assertIn('keypairs', inst.obj_what_changed())
|
||||
mock_get.assert_called_once_with(self.context,
|
||||
inst.user_id,
|
||||
inst.key_name,
|
||||
localonly=True)
|
||||
|
||||
@mock.patch.object(db, 'instance_get_by_uuid')
|
||||
def test_get_remote(self, mock_get):
|
||||
# isotime doesn't have microseconds and is always UTC
|
||||
|
@ -1995,53 +1975,3 @@ class TestInstanceObjectMisc(test.TestCase):
|
|||
self.assertEqual(['metadata', 'system_metadata', 'info_cache',
|
||||
'security_groups', 'pci_devices', 'tags', 'extra',
|
||||
'extra.flavor'], result_list)
|
||||
|
||||
def test_migrate_instance_keypairs(self):
|
||||
ctxt = context.RequestContext('foo', 'bar')
|
||||
key = objects.KeyPair(context=ctxt,
|
||||
user_id=ctxt.user_id,
|
||||
name='testkey',
|
||||
public_key='keydata',
|
||||
type='ssh')
|
||||
key.create()
|
||||
inst1 = objects.Instance(context=ctxt,
|
||||
user_id=ctxt.user_id,
|
||||
project_id=ctxt.project_id,
|
||||
key_name='testkey')
|
||||
inst1.create()
|
||||
inst2 = objects.Instance(context=ctxt,
|
||||
user_id=ctxt.user_id,
|
||||
project_id=ctxt.project_id,
|
||||
key_name='testkey',
|
||||
keypairs=objects.KeyPairList(
|
||||
objects=[key]))
|
||||
inst2.create()
|
||||
inst3 = objects.Instance(context=ctxt,
|
||||
user_id=ctxt.user_id,
|
||||
project_id=ctxt.project_id,
|
||||
key_name='missingkey')
|
||||
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)
|
||||
self.assertEqual(3, hit)
|
||||
self.assertEqual(2, done)
|
||||
db_extra = db.instance_extra_get_by_instance_uuid(
|
||||
ctxt, inst1.uuid, ['keypairs'])
|
||||
self.assertIsNotNone(db_extra.keypairs)
|
||||
db_extra = db.instance_extra_get_by_instance_uuid(
|
||||
ctxt, inst3.uuid, ['keypairs'])
|
||||
obj = base.NovaObject.obj_from_primitive(
|
||||
jsonutils.loads(db_extra['keypairs']))
|
||||
self.assertEqual([], obj.objects)
|
||||
|
|
Loading…
Reference in New Issue