Refactor rebuild_instance
This patch moves the creation of the rebuild_claim from rebuild_instance to _do_rebuild_instance_with_claim() helper so that in later patches more code can be added to _do_rebuild_instance_with_claim right before the rebuild_claim is created without dealing with deep nesting in rebuild_instance. Change-Id: Icf445ed185086e7add31bc921fd3d3a45344a887
This commit is contained in:
parent
578b6ea58c
commit
05c60fe70e
|
@ -3326,15 +3326,12 @@ class ComputeManager(manager.Manager):
|
||||||
|
|
||||||
with self._error_out_instance_on_exception(context, instance):
|
with self._error_out_instance_on_exception(context, instance):
|
||||||
try:
|
try:
|
||||||
claim_ctxt = rebuild_claim(
|
|
||||||
context, instance, scheduled_node, allocs,
|
|
||||||
limits=limits, image_meta=image_meta,
|
|
||||||
migration=migration)
|
|
||||||
self._do_rebuild_instance_with_claim(
|
self._do_rebuild_instance_with_claim(
|
||||||
claim_ctxt, context, instance, orig_image_ref,
|
context, instance, orig_image_ref,
|
||||||
image_meta, injected_files, new_pass, orig_sys_metadata,
|
image_meta, injected_files, new_pass, orig_sys_metadata,
|
||||||
bdms, evacuate, on_shared_storage, preserve_ephemeral,
|
bdms, evacuate, on_shared_storage, preserve_ephemeral,
|
||||||
migration, request_spec, allocs)
|
migration, request_spec, allocs, rebuild_claim,
|
||||||
|
scheduled_node, limits)
|
||||||
except (exception.ComputeResourcesUnavailable,
|
except (exception.ComputeResourcesUnavailable,
|
||||||
exception.RescheduledException) as e:
|
exception.RescheduledException) as e:
|
||||||
if isinstance(e, exception.ComputeResourcesUnavailable):
|
if isinstance(e, exception.ComputeResourcesUnavailable):
|
||||||
|
@ -3392,11 +3389,22 @@ class ComputeManager(manager.Manager):
|
||||||
# mark the instance as belonging to this host.
|
# mark the instance as belonging to this host.
|
||||||
self._set_migration_status(migration, 'done')
|
self._set_migration_status(migration, 'done')
|
||||||
|
|
||||||
def _do_rebuild_instance_with_claim(self, claim_context, *args, **kwargs):
|
def _do_rebuild_instance_with_claim(
|
||||||
|
self, context, instance, orig_image_ref, image_meta,
|
||||||
|
injected_files, new_pass, orig_sys_metadata, bdms, evacuate,
|
||||||
|
on_shared_storage, preserve_ephemeral, migration, request_spec,
|
||||||
|
allocations, rebuild_claim, scheduled_node, limits):
|
||||||
"""Helper to avoid deep nesting in the top-level method."""
|
"""Helper to avoid deep nesting in the top-level method."""
|
||||||
|
|
||||||
|
claim_context = rebuild_claim(
|
||||||
|
context, instance, scheduled_node, allocations,
|
||||||
|
limits=limits, image_meta=image_meta, migration=migration)
|
||||||
|
|
||||||
with claim_context:
|
with claim_context:
|
||||||
self._do_rebuild_instance(*args, **kwargs)
|
self._do_rebuild_instance(
|
||||||
|
context, instance, orig_image_ref, image_meta, injected_files,
|
||||||
|
new_pass, orig_sys_metadata, bdms, evacuate, on_shared_storage,
|
||||||
|
preserve_ephemeral, migration, request_spec, allocations)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_image_name(image_meta):
|
def _get_image_name(image_meta):
|
||||||
|
|
|
@ -5119,7 +5119,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
||||||
mock_rt = self._mock_rt()
|
mock_rt = self._mock_rt()
|
||||||
with test.nested(
|
with test.nested(
|
||||||
mock.patch.object(self.compute, '_get_compute_info'),
|
mock.patch.object(self.compute, '_get_compute_info'),
|
||||||
mock.patch.object(self.compute, '_do_rebuild_instance_with_claim'),
|
mock.patch.object(self.compute, '_do_rebuild_instance'),
|
||||||
mock.patch.object(objects.Instance, 'save'),
|
mock.patch.object(objects.Instance, 'save'),
|
||||||
mock.patch.object(self.compute, '_set_migration_status'),
|
mock.patch.object(self.compute, '_set_migration_status'),
|
||||||
) as (mock_get, mock_rebuild, mock_save, mock_set):
|
) as (mock_get, mock_rebuild, mock_save, mock_set):
|
||||||
|
|
Loading…
Reference in New Issue