Skip to content

Commit 6e12686

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Cleanup old resize instances dir before resize"
2 parents f7fa3bf + 9111b99 commit 6e12686

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
@@ -21530,6 +21530,8 @@ def test_migrate_disk_and_power_off_exception(
2153021530
context.get_admin_context(), ins_ref, '10.0.0.2',
2153121531
flavor_obj, None)
2153221532

21533+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21534+
'_cleanup_failed_instance_base')
2153321535
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs')
2153421536
@mock.patch('nova.virt.libvirt.utils.save_and_migrate_vtpm_dir')
2153521537
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
@@ -21546,7 +21548,7 @@ def _test_migrate_disk_and_power_off(
2154621548
self, ctxt, flavor_obj, mock_execute, mock_exists, mock_rename,
2154721549
mock_is_shared, mock_get_host_ip, mock_destroy,
2154821550
mock_get_disk_info, mock_vtpm, mock_unplug_vifs,
21549-
block_device_info=None, params_for_instance=None):
21551+
mock_cleanup, block_device_info=None, params_for_instance=None):
2155021552
"""Test for nova.virt.libvirt.driver.LivirtConnection
2155121553
.migrate_disk_and_power_off.
2155221554
"""
@@ -21561,6 +21563,8 @@ def _test_migrate_disk_and_power_off(
2156121563
ctxt, instance, '10.0.0.2', flavor_obj, None,
2156221564
block_device_info=block_device_info)
2156321565

21566+
mock_cleanup.assert_called_once()
21567+
mock_cleanup.reset_mock()
2156421568
self.assertEqual(out, disk_info_text)
2156521569
mock_vtpm.assert_called_with(
2156621570
instance.uuid, mock.ANY, mock.ANY, '10.0.0.2', mock.ANY, mock.ANY)
@@ -21571,6 +21575,7 @@ def _test_migrate_disk_and_power_off(
2157121575
ctxt, instance, '10.0.0.1', flavor_obj, None,
2157221576
block_device_info=block_device_info)
2157321577

21578+
mock_cleanup.assert_called_once()
2157421579
self.assertEqual(out, disk_info_text)
2157521580
mock_vtpm.assert_called_with(
2157621581
instance.uuid, mock.ANY, mock.ANY, '10.0.0.1', mock.ANY, mock.ANY)
@@ -22468,8 +22473,8 @@ def test_finish_revert_migration_snap_backend_image_does_not_exist(self):
2246822473
self.assertFalse(drvr.image_backend.remove_snap.called)
2246922474

2247022475
@mock.patch.object(shutil, 'rmtree')
22471-
def test_cleanup_failed_migration(self, mock_rmtree):
22472-
self.drvr._cleanup_failed_migration('/fake/inst')
22476+
def test_cleanup_failed_instance_base(self, mock_rmtree):
22477+
self.drvr._cleanup_failed_instance_base('/fake/inst')
2247322478
mock_rmtree.assert_called_once_with('/fake/inst')
2247422479

2247522480
@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
@@ -10979,6 +10979,9 @@ def migrate_disk_and_power_off(self, context, instance, dest,
1097910979
disk_info = self._get_instance_disk_info(instance, block_device_info)
1098010980

1098110981
try:
10982+
# If cleanup failed in previous resize attempts we try to remedy
10983+
# that before a resize is tried again
10984+
self._cleanup_failed_instance_base(inst_base_resize)
1098210985
os.rename(inst_base, inst_base_resize)
1098310986
# if we are migrating the instance with shared instance path then
1098410987
# create the directory. If it is a remote node the directory
@@ -11202,9 +11205,9 @@ def finish_migration(
1120211205

1120311206
LOG.debug("finish_migration finished successfully.", instance=instance)
1120411207

11205-
def _cleanup_failed_migration(self, inst_base):
11206-
"""Make sure that a failed migrate doesn't prevent us from rolling
11207-
back in a revert.
11208+
def _cleanup_failed_instance_base(self, inst_base):
11209+
"""Make sure that a failed migrate or resize doesn't prevent us from
11210+
rolling back in a revert or retrying a resize.
1120811211
"""
1120911212
try:
1121011213
shutil.rmtree(inst_base)
@@ -11260,7 +11263,7 @@ def finish_revert_migration(
1126011263
# that would conflict. Also, don't fail on the rename if the
1126111264
# failure happened early.
1126211265
if os.path.exists(inst_base_resize):
11263-
self._cleanup_failed_migration(inst_base)
11266+
self._cleanup_failed_instance_base(inst_base)
1126411267
os.rename(inst_base_resize, inst_base)
1126511268

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