Skip to content

Commit 9111b99

Browse files
committed
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
1 parent b0633ac commit 9111b99

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
@@ -21544,6 +21544,8 @@ def test_migrate_disk_and_power_off_exception(
2154421544
context.get_admin_context(), ins_ref, '10.0.0.2',
2154521545
flavor_obj, None)
2154621546

21547+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21548+
'_cleanup_failed_instance_base')
2154721549
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs')
2154821550
@mock.patch('nova.virt.libvirt.utils.save_and_migrate_vtpm_dir')
2154921551
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
@@ -21560,7 +21562,7 @@ def _test_migrate_disk_and_power_off(
2156021562
self, ctxt, flavor_obj, mock_execute, mock_exists, mock_rename,
2156121563
mock_is_shared, mock_get_host_ip, mock_destroy,
2156221564
mock_get_disk_info, mock_vtpm, mock_unplug_vifs,
21563-
block_device_info=None, params_for_instance=None):
21565+
mock_cleanup, block_device_info=None, params_for_instance=None):
2156421566
"""Test for nova.virt.libvirt.driver.LivirtConnection
2156521567
.migrate_disk_and_power_off.
2156621568
"""
@@ -21575,6 +21577,8 @@ def _test_migrate_disk_and_power_off(
2157521577
ctxt, instance, '10.0.0.2', flavor_obj, None,
2157621578
block_device_info=block_device_info)
2157721579

21580+
mock_cleanup.assert_called_once()
21581+
mock_cleanup.reset_mock()
2157821582
self.assertEqual(out, disk_info_text)
2157921583
mock_vtpm.assert_called_with(
2158021584
instance.uuid, mock.ANY, mock.ANY, '10.0.0.2', mock.ANY, mock.ANY)
@@ -21585,6 +21589,7 @@ def _test_migrate_disk_and_power_off(
2158521589
ctxt, instance, '10.0.0.1', flavor_obj, None,
2158621590
block_device_info=block_device_info)
2158721591

21592+
mock_cleanup.assert_called_once()
2158821593
self.assertEqual(out, disk_info_text)
2158921594
mock_vtpm.assert_called_with(
2159021595
instance.uuid, mock.ANY, mock.ANY, '10.0.0.1', mock.ANY, mock.ANY)
@@ -22514,8 +22519,8 @@ def test_finish_revert_migration_snap_backend_image_does_not_exist(self):
2251422519
self.assertFalse(drvr.image_backend.remove_snap.called)
2251522520

2251622521
@mock.patch.object(shutil, 'rmtree')
22517-
def test_cleanup_failed_migration(self, mock_rmtree):
22518-
self.drvr._cleanup_failed_migration('/fake/inst')
22522+
def test_cleanup_failed_instance_base(self, mock_rmtree):
22523+
self.drvr._cleanup_failed_instance_base('/fake/inst')
2251922524
mock_rmtree.assert_called_once_with('/fake/inst')
2252022525

2252122526
@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
@@ -10973,6 +10973,9 @@ def migrate_disk_and_power_off(self, context, instance, dest,
1097310973
disk_info = self._get_instance_disk_info(instance, block_device_info)
1097410974

1097510975
try:
10976+
# If cleanup failed in previous resize attempts we try to remedy
10977+
# that before a resize is tried again
10978+
self._cleanup_failed_instance_base(inst_base_resize)
1097610979
os.rename(inst_base, inst_base_resize)
1097710980
# if we are migrating the instance with shared instance path then
1097810981
# create the directory. If it is a remote node the directory
@@ -11196,9 +11199,9 @@ def finish_migration(
1119611199

1119711200
LOG.debug("finish_migration finished successfully.", instance=instance)
1119811201

11199-
def _cleanup_failed_migration(self, inst_base):
11200-
"""Make sure that a failed migrate doesn't prevent us from rolling
11201-
back in a revert.
11202+
def _cleanup_failed_instance_base(self, inst_base):
11203+
"""Make sure that a failed migrate or resize doesn't prevent us from
11204+
rolling back in a revert or retrying a resize.
1120211205
"""
1120311206
try:
1120411207
shutil.rmtree(inst_base)
@@ -11254,7 +11257,7 @@ def finish_revert_migration(
1125411257
# that would conflict. Also, don't fail on the rename if the
1125511258
# failure happened early.
1125611259
if os.path.exists(inst_base_resize):
11257-
self._cleanup_failed_migration(inst_base)
11260+
self._cleanup_failed_instance_base(inst_base)
1125811261
os.rename(inst_base_resize, inst_base)
1125911262

1126011263
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)