Skip to content

Commit bdbeb34

Browse files
tobias-urdinMrStupnikov
authored andcommitted
Cleanup old resize instances dir before resize
If there is a failed resize that also failed the cleanup process performed by _cleanup_remote_migration() the retry of the resize will fail because it cannot rename the current instances directory to _resize. This renames the _cleanup_failed_migration() that does the same logic we want to _cleanup_failed_instance_base() and uses it for both migration and resize cleanup of directory. It then simply calls _cleanup_failed_instances_base() with the resize dir path before trying a resize. Closes-Bug: 1960230 Change-Id: I7412b16be310632da59a6139df9f0913281b5d77 (cherry picked from commit 9111b99) (cherry picked from commit 31179f6)
1 parent 33fa10f commit bdbeb34

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21471,6 +21471,8 @@ def test_migrate_disk_and_power_off_exception(
2147121471
context.get_admin_context(), ins_ref, '10.0.0.2',
2147221472
flavor_obj, None)
2147321473

21474+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21475+
'_cleanup_failed_instance_base')
2147421476
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs')
2147521477
@mock.patch('nova.virt.libvirt.utils.save_and_migrate_vtpm_dir')
2147621478
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
@@ -21487,7 +21489,7 @@ def _test_migrate_disk_and_power_off(
2148721489
self, ctxt, flavor_obj, mock_execute, mock_exists, mock_rename,
2148821490
mock_is_shared, mock_get_host_ip, mock_destroy,
2148921491
mock_get_disk_info, mock_vtpm, mock_unplug_vifs,
21490-
block_device_info=None, params_for_instance=None):
21492+
mock_cleanup, block_device_info=None, params_for_instance=None):
2149121493
"""Test for nova.virt.libvirt.driver.LivirtConnection
2149221494
.migrate_disk_and_power_off.
2149321495
"""
@@ -21502,6 +21504,8 @@ def _test_migrate_disk_and_power_off(
2150221504
ctxt, instance, '10.0.0.2', flavor_obj, None,
2150321505
block_device_info=block_device_info)
2150421506

21507+
mock_cleanup.assert_called_once()
21508+
mock_cleanup.reset_mock()
2150521509
self.assertEqual(out, disk_info_text)
2150621510
mock_vtpm.assert_called_with(
2150721511
instance.uuid, mock.ANY, mock.ANY, '10.0.0.2', mock.ANY, mock.ANY)
@@ -21512,6 +21516,7 @@ def _test_migrate_disk_and_power_off(
2151221516
ctxt, instance, '10.0.0.1', flavor_obj, None,
2151321517
block_device_info=block_device_info)
2151421518

21519+
mock_cleanup.assert_called_once()
2151521520
self.assertEqual(out, disk_info_text)
2151621521
mock_vtpm.assert_called_with(
2151721522
instance.uuid, mock.ANY, mock.ANY, '10.0.0.1', mock.ANY, mock.ANY)
@@ -22441,8 +22446,8 @@ def test_finish_revert_migration_snap_backend_image_does_not_exist(self):
2244122446
self.assertFalse(drvr.image_backend.remove_snap.called)
2244222447

2244322448
@mock.patch.object(shutil, 'rmtree')
22444-
def test_cleanup_failed_migration(self, mock_rmtree):
22445-
self.drvr._cleanup_failed_migration('/fake/inst')
22449+
def test_cleanup_failed_instance_base(self, mock_rmtree):
22450+
self.drvr._cleanup_failed_instance_base('/fake/inst')
2244622451
mock_rmtree.assert_called_once_with('/fake/inst')
2244722452

2244822453
@mock.patch.object(libvirt_driver.LibvirtDriver, '_cleanup_resize')

nova/virt/libvirt/driver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10851,6 +10851,9 @@ def migrate_disk_and_power_off(self, context, instance, dest,
1085110851
disk_info = self._get_instance_disk_info(instance, block_device_info)
1085210852

1085310853
try:
10854+
# If cleanup failed in previous resize attempts we try to remedy
10855+
# that before a resize is tried again
10856+
self._cleanup_failed_instance_base(inst_base_resize)
1085410857
os.rename(inst_base, inst_base_resize)
1085510858
# if we are migrating the instance with shared instance path then
1085610859
# create the directory. If it is a remote node the directory
@@ -11074,9 +11077,9 @@ def finish_migration(
1107411077

1107511078
LOG.debug("finish_migration finished successfully.", instance=instance)
1107611079

11077-
def _cleanup_failed_migration(self, inst_base):
11078-
"""Make sure that a failed migrate doesn't prevent us from rolling
11079-
back in a revert.
11080+
def _cleanup_failed_instance_base(self, inst_base):
11081+
"""Make sure that a failed migrate or resize doesn't prevent us from
11082+
rolling back in a revert or retrying a resize.
1108011083
"""
1108111084
try:
1108211085
shutil.rmtree(inst_base)
@@ -11132,7 +11135,7 @@ def finish_revert_migration(
1113211135
# that would conflict. Also, don't fail on the rename if the
1113311136
# failure happened early.
1113411137
if os.path.exists(inst_base_resize):
11135-
self._cleanup_failed_migration(inst_base)
11138+
self._cleanup_failed_instance_base(inst_base)
1113611139
os.rename(inst_base_resize, inst_base)
1113711140

1113811141
root_disk = self.image_backend.by_name(instance, 'disk')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed bug `1960230 <https://bugs.launchpad.net/nova/+bug/1960230>`_ that
5+
prevented resize of instances that had previously failed and not been
6+
cleaned up.

0 commit comments

Comments
 (0)