objects: Remove 'NovaObjectDictCompat' from 'Migration'
Addresses a long-standing TODO. Change-Id: I57a1c4ca2ab23ca991344e73fb4ab5fbb2922723 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
d2b2516122
commit
028b3bca16
@ -139,7 +139,7 @@ class ServerMigrationsController(wsgi.Controller):
|
||||
|
||||
# TODO(Shaohe Feng) we should share the in-progress list.
|
||||
in_progress = ['queued', 'preparing', 'running', 'post-migrating']
|
||||
if migration.get("status") not in in_progress:
|
||||
if migration.status not in in_progress:
|
||||
msg = _("Live migration %(id)s for server %(uuid)s is not in"
|
||||
" progress.") % {"id": id, "uuid": server_id}
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
@ -1759,8 +1759,7 @@ class ComputeManager(manager.Manager):
|
||||
migrations = (
|
||||
objects.MigrationList.get_in_progress_by_host_and_node(
|
||||
context, self.host, nodename))
|
||||
migration_vm_uuids = set([mig['instance_uuid']
|
||||
for mig in migrations])
|
||||
migration_vm_uuids = {mig.instance_uuid for mig in migrations}
|
||||
|
||||
total_instances = migration_vm_uuids | ins_on_host
|
||||
|
||||
@ -5814,8 +5813,8 @@ class ComputeManager(manager.Manager):
|
||||
def _finish_resize(self, context, instance, migration, disk_info,
|
||||
image_meta, bdms, request_spec):
|
||||
resize_instance = False # indicates disks have been resized
|
||||
old_instance_type_id = migration['old_instance_type_id']
|
||||
new_instance_type_id = migration['new_instance_type_id']
|
||||
old_instance_type_id = migration.old_instance_type_id
|
||||
new_instance_type_id = migration.new_instance_type_id
|
||||
old_flavor = instance.flavor # the current flavor is now old
|
||||
# NOTE(mriedem): Get the old_vm_state so we know if we should
|
||||
# power on the instance. If old_vm_state is not set we need to default
|
||||
@ -8895,8 +8894,9 @@ class ComputeManager(manager.Manager):
|
||||
action=fields.NotificationAction.LIVE_MIGRATION_POST,
|
||||
phase=fields.NotificationPhase.START)
|
||||
|
||||
migration = {'source_compute': self.host,
|
||||
'dest_compute': dest, }
|
||||
migration = objects.Migration(
|
||||
source_compute=self.host, dest_compute=dest,
|
||||
)
|
||||
# For neutron, migrate_instance_start will activate the destination
|
||||
# host port bindings, if there are any created by conductor before live
|
||||
# migration started.
|
||||
@ -9587,7 +9587,7 @@ class ComputeManager(manager.Manager):
|
||||
def _set_migration_to_error(migration, reason, **kwargs):
|
||||
LOG.warning("Setting migration %(migration_id)s to error: "
|
||||
"%(reason)s",
|
||||
{'migration_id': migration['id'], 'reason': reason},
|
||||
{'migration_id': migration.id, 'reason': reason},
|
||||
**kwargs)
|
||||
migration.status = 'error'
|
||||
migration.save()
|
||||
|
@ -3124,7 +3124,7 @@ class API:
|
||||
return
|
||||
|
||||
client = get_client(context, admin=True)
|
||||
dest_host = migration['dest_compute']
|
||||
dest_host = migration.dest_compute
|
||||
for vif in instance.get_network_info():
|
||||
# Not all compute migration flows use the port binding-extended
|
||||
# API yet, so first check to see if there is a binding for the
|
||||
@ -3659,8 +3659,7 @@ class API:
|
||||
return {}
|
||||
# In case of revert, swap old and new devices to
|
||||
# update the ports back to the original devices.
|
||||
revert = (migration and
|
||||
migration.get('status') == 'reverted')
|
||||
revert = migration and migration.status == 'reverted'
|
||||
return instance.migration_context.get_pci_mapping_for_migration(revert)
|
||||
|
||||
def _get_port_pci_dev(self, context, instance, port):
|
||||
|
@ -25,16 +25,21 @@ from nova.objects import fields
|
||||
|
||||
|
||||
def determine_migration_type(migration):
|
||||
if migration['old_instance_type_id'] != migration['new_instance_type_id']:
|
||||
return 'resize'
|
||||
if isinstance(migration, dict):
|
||||
old_instance_type_id = migration['old_instance_type_id']
|
||||
new_instance_type_id = migration['new_instance_type_id']
|
||||
else:
|
||||
return 'migration'
|
||||
old_instance_type_id = migration.old_instance_type_id
|
||||
new_instance_type_id = migration.new_instance_type_id
|
||||
|
||||
if old_instance_type_id != new_instance_type_id:
|
||||
return 'resize'
|
||||
|
||||
return 'migration'
|
||||
|
||||
|
||||
# TODO(berrange): Remove NovaObjectDictCompat
|
||||
@base.NovaObjectRegistry.register
|
||||
class Migration(base.NovaPersistentObject, base.NovaObject,
|
||||
base.NovaObjectDictCompat):
|
||||
class Migration(base.NovaPersistentObject, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: String attributes updated to support unicode
|
||||
# Version 1.2: Added migration_type and hidden
|
||||
@ -82,7 +87,7 @@ class Migration(base.NovaPersistentObject, base.NovaObject,
|
||||
value = determine_migration_type(db_migration)
|
||||
elif key == 'uuid' and value is None:
|
||||
continue
|
||||
migration[key] = value
|
||||
setattr(migration, key, value)
|
||||
|
||||
migration._context = context
|
||||
migration.obj_reset_changes()
|
||||
|
@ -459,8 +459,8 @@ class PciDevTracker(object):
|
||||
|
||||
The caller should hold the COMPUTE_RESOURCE_SEMAPHORE lock
|
||||
"""
|
||||
existed = set(inst['uuid'] for inst in instances)
|
||||
existed |= set(mig['instance_uuid'] for mig in migrations)
|
||||
existed = set(inst.uuid for inst in instances)
|
||||
existed |= set(mig.instance_uuid for mig in migrations)
|
||||
|
||||
# need to copy keys, because the dict is modified in the loop body
|
||||
for uuid in list(self.claims):
|
||||
|
@ -64,7 +64,7 @@ class TestMigrationListObjects(test.TestCase):
|
||||
self.context, filters, limit, marker,
|
||||
sort_keys, sort_dirs)
|
||||
found_uuids = [x.uuid for x in migs]
|
||||
had_uuids = sorted([x['uuid'] for x in self.migrations])
|
||||
had_uuids = sorted([x.uuid for x in self.migrations])
|
||||
self.assertEqual(had_uuids, found_uuids)
|
||||
|
||||
def test_get_instance_objects_sorted_paged(self):
|
||||
@ -80,7 +80,7 @@ class TestMigrationListObjects(test.TestCase):
|
||||
['created_at'], ['asc'])
|
||||
self.assertEqual(len(self.migrations), len(migp1))
|
||||
migp2 = migration_list.get_migration_objects_sorted(
|
||||
self.context, {}, None, migp1[-1]['uuid'],
|
||||
self.context, {}, None, migp1[-1].uuid,
|
||||
['created_at'], ['asc'])
|
||||
self.assertEqual(0, len(migp2))
|
||||
|
||||
@ -93,7 +93,7 @@ class TestMigrationListObjects(test.TestCase):
|
||||
def test_get_sorted_with_limit(self):
|
||||
migs = migration_list.get_migration_objects_sorted(
|
||||
self.context, {}, 2, None, ['uuid'], ['asc'])
|
||||
uuids = [mig['uuid'] for mig in migs]
|
||||
uuids = [mig.uuid for mig in migs]
|
||||
had_uuids = [mig.uuid for mig in self.migrations]
|
||||
self.assertEqual(sorted(had_uuids)[:2], uuids)
|
||||
self.assertEqual(2, len(uuids))
|
||||
|
@ -1118,7 +1118,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||
mock_mig_get.assert_called_once_with(
|
||||
self.context, instance_uuid, 'finished')
|
||||
mock_confirm.assert_called_once_with(
|
||||
self.context, inst, migration, migration['source_compute'],
|
||||
self.context, inst, migration, migration.source_compute,
|
||||
cast=False)
|
||||
if instance_host is not None:
|
||||
mock_get_cn.assert_called_once_with(self.context,
|
||||
|
@ -6303,9 +6303,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual('completed', migration.status)
|
||||
mock_pre.assert_called_once_with(c, instance, False, None,
|
||||
dest, migrate_data)
|
||||
mock_migrate.assert_called_once_with(c, instance,
|
||||
{'source_compute': instance[
|
||||
'host'], 'dest_compute': dest})
|
||||
mock_migrate.assert_called_once_with(c, instance, mock.ANY)
|
||||
mock_post.assert_called_once_with(c, instance, False, dest)
|
||||
mock_clear.assert_called_once_with(mock.ANY)
|
||||
|
||||
@ -6388,7 +6386,6 @@ class ComputeTestCase(BaseTestCase,
|
||||
migration_obj = objects.Migration(uuid=uuids.migration,
|
||||
source_node=instance.node,
|
||||
status='completed')
|
||||
migration = {'source_compute': srchost, 'dest_compute': dest, }
|
||||
migrate_data = objects.LibvirtLiveMigrateData(
|
||||
is_shared_instance_path=False,
|
||||
is_shared_block_storage=False,
|
||||
@ -6411,7 +6408,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
|
||||
self.assertIn('cleanup', result)
|
||||
self.assertTrue(result['cleanup'])
|
||||
mock_migrate.assert_called_once_with(c, instance, migration)
|
||||
mock_migrate.assert_called_once_with(c, instance, mock.ANY)
|
||||
mock_post.assert_called_once_with(c, instance, False, dest)
|
||||
mock_clear.assert_called_once_with(mock.ANY)
|
||||
|
||||
@ -6478,10 +6475,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
'root_device_name': None,
|
||||
'block_device_mapping': []},
|
||||
migrate_data)])
|
||||
migration = {'source_compute': srchost,
|
||||
'dest_compute': dest, }
|
||||
migrate_instance_start.assert_has_calls([
|
||||
mock.call(c, instance, migration)])
|
||||
mock.call(c, instance, mock.ANY)])
|
||||
post_live_migration_at_destination.assert_has_calls([
|
||||
mock.call(c, instance, False, dest)])
|
||||
post_live_migration_at_source.assert_has_calls(
|
||||
@ -7441,12 +7436,11 @@ class ComputeTestCase(BaseTestCase,
|
||||
# raise exception for uuids.migration_instance_4 to check
|
||||
# migration status does not get set to 'error' on confirm_resize
|
||||
# failure.
|
||||
if instance['uuid'] == uuids.migration_instance_4:
|
||||
if instance.uuid == uuids.migration_instance_4:
|
||||
raise test.TestingException('bomb')
|
||||
self.assertIsNotNone(migration)
|
||||
for migration2 in migrations:
|
||||
if (migration2['instance_uuid'] ==
|
||||
migration['instance_uuid']):
|
||||
if migration2['instance_uuid'] == migration.instance_uuid:
|
||||
migration2['status'] = 'confirmed'
|
||||
|
||||
self.stub_out(
|
||||
|
@ -503,7 +503,10 @@ class PciDevTrackerTestCase(test.NoDBTestCase):
|
||||
def test_clean_usage(self):
|
||||
inst_2 = copy.copy(self.inst)
|
||||
inst_2.uuid = uuidsentinel.instance2
|
||||
migr = {'instance_uuid': 'uuid2', 'vm_state': vm_states.BUILDING}
|
||||
migr = objects.Migration(
|
||||
instance_uuid='uuid2',
|
||||
vm_state=vm_states.BUILDING,
|
||||
)
|
||||
|
||||
pci_requests_obj = self._create_pci_requests_object(
|
||||
[{'count': 1, 'spec': [{'vendor_id': 'v'}]}])
|
||||
|
Loading…
Reference in New Issue
Block a user