Skip to content

Commit d4c857d

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "objects: Add MigrationTypeField"
2 parents d4d8ea1 + f203da3 commit d4c857d

File tree

14 files changed

+81
-49
lines changed

14 files changed

+81
-49
lines changed

nova/api/openstack/compute/migrations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from nova import exception
2424
from nova.i18n import _
2525
from nova.objects import base as obj_base
26+
from nova.objects import fields
2627
from nova.policies import migrations as migrations_policies
2728

2829

@@ -72,7 +73,9 @@ def _output(self, req, migrations_obj, add_link=False,
7273
# NOTE(Shaohe Feng) above version 2.23, add migration_type for all
7374
# kinds of migration, but we only add links just for in-progress
7475
# live-migration.
75-
if add_link and obj['migration_type'] == "live-migration" and (
76+
if (add_link and
77+
obj['migration_type'] ==
78+
fields.MigrationType.LIVE_MIGRATION and
7679
obj["status"] in live_migration_in_progress):
7780
obj["links"] = self._view_builder._get_links(
7881
req, obj["id"],

nova/api/openstack/compute/server_migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def show(self, req, server_id, id):
132132
" server %(uuid)s.") % {"id": id, "uuid": server_id}
133133
raise exc.HTTPNotFound(explanation=msg)
134134

135-
if migration.get("migration_type") != "live-migration":
135+
if not migration.is_live_migration:
136136
msg = _("Migration %(id)s for server %(uuid)s is not"
137137
" live-migration.") % {"id": id, "uuid": server_id}
138138
raise exc.HTTPNotFound(explanation=msg)

nova/compute/api.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,12 +5033,10 @@ def evacuate(self, context, instance, host, on_shared_storage,
50335033

50345034
# NOTE(danms): Create this as a tombstone for the source compute
50355035
# to find and cleanup. No need to pass it anywhere else.
5036-
migration = objects.Migration(context,
5037-
source_compute=instance.host,
5038-
source_node=instance.node,
5039-
instance_uuid=instance.uuid,
5040-
status='accepted',
5041-
migration_type='evacuation')
5036+
migration = objects.Migration(
5037+
context, source_compute=instance.host, source_node=instance.node,
5038+
instance_uuid=instance.uuid, status='accepted',
5039+
migration_type=fields_obj.MigrationType.EVACUATION)
50425040
if host:
50435041
migration.dest_compute = host
50445042
migration.create()

nova/compute/claims.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ def _test_pci(self):
194194
migration, all types of PCI requests are supported, so we just call up
195195
to normal Claim's _test_pci().
196196
"""
197-
if self.migration.migration_type != 'live-migration':
197+
if not self.migration.is_live_migration:
198198
return super(MoveClaim, self)._test_pci()
199-
elif self._pci_requests.requests:
199+
200+
if self._pci_requests.requests:
200201
for pci_request in self._pci_requests.requests:
201202
if (pci_request.source !=
202203
objects.InstancePCIRequest.NEUTRON_PORT):
@@ -225,7 +226,7 @@ def _test_live_migration_page_size(self):
225226
something we want to support, so fail the claim if the page sizes are
226227
different.
227228
"""
228-
if (self.migration.migration_type == 'live-migration' and
229+
if (self.migration.is_live_migration and
229230
self.instance.numa_topology and
230231
# NOTE(artom) We only support a single page size across all
231232
# cells, checking cell 0 is sufficient.

nova/compute/manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def _destroy_evacuated_instances(self, context, node_cache):
685685
# the user can rebuild the instance (in ERROR state) on the source
686686
# host.
687687
'status': ['accepted', 'pre-migrating', 'done'],
688-
'migration_type': 'evacuation',
688+
'migration_type': fields.MigrationType.EVACUATION,
689689
}
690690
with utils.temporary_mutation(context, read_deleted='yes'):
691691
evacuations = objects.MigrationList.get_by_filters(context,
@@ -8475,9 +8475,10 @@ def post_live_migration_at_destination(self, context, instance,
84758475
# NOTE(mriedem): This is a no-op for neutron.
84768476
self.network_api.setup_networks_on_host(context, instance,
84778477
self.host)
8478-
migration = objects.Migration(source_compute=instance.host,
8479-
dest_compute=self.host,
8480-
migration_type='live-migration')
8478+
migration = objects.Migration(
8479+
source_compute=instance.host,
8480+
dest_compute=self.host,
8481+
migration_type=fields.MigrationType.LIVE_MIGRATION)
84818482
self.network_api.migrate_instance_finish(
84828483
context, instance, migration, provider_mappings=None)
84838484

nova/compute/resource_tracker.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from nova.i18n import _
4040
from nova import objects
4141
from nova.objects import base as obj_base
42+
from nova.objects import fields
4243
from nova.objects import migration as migration_obj
4344
from nova.pci import manager as pci_manager
4445
from nova.pci import request as pci_request
@@ -191,9 +192,10 @@ def rebuild_claim(self, context, instance, nodename, allocations,
191192
limits=None, image_meta=None, migration=None):
192193
"""Create a claim for a rebuild operation."""
193194
instance_type = instance.flavor
194-
return self._move_claim(context, instance, instance_type, nodename,
195-
migration, allocations, move_type='evacuation',
196-
limits=limits, image_meta=image_meta)
195+
return self._move_claim(
196+
context, instance, instance_type, nodename, migration, allocations,
197+
move_type=fields.MigrationType.EVACUATION,
198+
image_meta=image_meta, limits=limits)
197199

198200
@utils.synchronized(COMPUTE_RESOURCE_SEMAPHORE, fair=True)
199201
def resize_claim(self, context, instance, instance_type, nodename,
@@ -225,9 +227,11 @@ def live_migration_claim(self, context, instance, nodename, migration,
225227
# Flavor and image cannot change during a live migration.
226228
instance_type = instance.flavor
227229
image_meta = instance.image_meta
228-
return self._move_claim(context, instance, instance_type, nodename,
229-
migration, allocs, move_type='live-migration',
230-
image_meta=image_meta, limits=limits)
230+
return self._move_claim(
231+
context, instance, instance_type, nodename, migration, allocs,
232+
move_type=fields.MigrationType.LIVE_MIGRATION,
233+
image_meta=image_meta, limits=limits,
234+
)
231235

232236
def _move_claim(self, context, instance, new_instance_type, nodename,
233237
migration, allocations, move_type=None,
@@ -293,7 +297,7 @@ def _move_claim(self, context, instance, new_instance_type, nodename,
293297
# migration to avoid stepping on that code's toes. Ideally,
294298
# MoveClaim/this method would be used for all live migration resource
295299
# claims.
296-
if self.pci_tracker and migration.migration_type != 'live-migration':
300+
if self.pci_tracker and not migration.is_live_migration:
297301
# NOTE(jaypipes): ComputeNode.pci_device_pools is set below
298302
# in _update_usage_from_instance().
299303
claimed_pci_devices_objs = self.pci_tracker.claim_instance(
@@ -369,7 +373,7 @@ def _claim_existing_migration(self, migration, nodename):
369373
# NOTE(artom) Migration objects for live migrations are created with
370374
# status 'accepted' by the conductor in live_migrate_instance() and do
371375
# not have a 'pre-migrating' status.
372-
if migration.migration_type != 'live-migration':
376+
if not migration.is_live_migration:
373377
migration.status = 'pre-migrating'
374378
migration.save()
375379

@@ -1637,8 +1641,7 @@ def _verify_resources(self, resources):
16371641

16381642
def _get_instance_type(self, instance, prefix, migration):
16391643
"""Get the instance type from instance."""
1640-
stashed_flavors = migration.migration_type in ('resize',)
1641-
if stashed_flavors:
1644+
if migration.is_resize:
16421645
return getattr(instance, '%sflavor' % prefix)
16431646
else:
16441647
# NOTE(ndipanov): Certain migration types (all but resize)

nova/conductor/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _set_vm_state(context, instance, ex, vm_state=None,
456456
migration.status = 'accepted'
457457
migration.instance_uuid = instance.uuid
458458
migration.source_compute = instance.host
459-
migration.migration_type = 'live-migration'
459+
migration.migration_type = fields.MigrationType.LIVE_MIGRATION
460460
if instance.obj_attr_is_set('flavor'):
461461
migration.old_instance_type_id = instance.flavor.id
462462
migration.new_instance_type_id = instance.flavor.id

nova/network/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
FIP_PORT_DETAILS = 'Floating IP Port Details Extension'
2222
SUBSTR_PORT_FILTERING = 'IP address substring filtering'
2323
PORT_BINDING_EXTENDED = 'Port Bindings Extended'
24-
LIVE_MIGRATION = 'live-migration'
2524
DEFAULT_SECGROUP = 'default'
2625
BINDING_PROFILE = 'binding:profile'
2726
BINDING_HOST_ID = 'binding:host_id'

nova/network/neutron.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,7 +3413,7 @@ def _update_port_binding_for_instance(
34133413
vnic_type = p.get('binding:vnic_type')
34143414
if (vnic_type in network_model.VNIC_TYPES_SRIOV and
34153415
migration is not None and
3416-
migration['migration_type'] != constants.LIVE_MIGRATION):
3416+
not migration.is_live_migration):
34173417
# Note(adrianc): for live migration binding profile was already
34183418
# updated in conductor when calling bind_ports_to_host()
34193419
if not pci_mapping:
@@ -3435,9 +3435,9 @@ def _update_port_binding_for_instance(
34353435
# allocation key in the port binding. However during resize, cold
34363436
# migrate, evacuate and unshelve we have to set the binding here.
34373437
# Also note that during unshelve no migration object is created.
3438-
if (p.get('resource_request') and
3439-
(migration is None or
3440-
migration['migration_type'] != constants.LIVE_MIGRATION)):
3438+
if p.get('resource_request') and (
3439+
migration is None or not migration.is_live_migration
3440+
):
34413441
if not provider_mappings:
34423442
# TODO(gibi): Remove this check when compute RPC API is
34433443
# bumped to 6.0

nova/objects/fields.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,16 @@ class ImageSignatureKeyType(BaseNovaEnum):
464464
)
465465

466466

467+
class MigrationType(BaseNovaEnum):
468+
469+
MIGRATION = 'migration' # cold migration
470+
RESIZE = 'resize'
471+
LIVE_MIGRATION = 'live-migration'
472+
EVACUATION = 'evacuation'
473+
474+
ALL = (MIGRATION, RESIZE, LIVE_MIGRATION, EVACUATION)
475+
476+
467477
class OSType(BaseNovaEnum):
468478

469479
LINUX = "linux"
@@ -1207,6 +1217,10 @@ class ImageSignatureKeyTypeField(BaseEnumField):
12071217
AUTO_TYPE = ImageSignatureKeyType()
12081218

12091219

1220+
class MigrationTypeField(BaseEnumField):
1221+
AUTO_TYPE = MigrationType()
1222+
1223+
12101224
class OSTypeField(BaseEnumField):
12111225
AUTO_TYPE = OSType()
12121226

0 commit comments

Comments
 (0)