Skip to content

Commit c78f091

Browse files
authored
Merge pull request #32 from stackhpc/upstream/wallaby-2023-02-13
Synchronise wallaby with upstream
2 parents 7b9f83a + 797c5fa commit c78f091

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
@@ -21476,6 +21476,8 @@ def test_migrate_disk_and_power_off_exception(
2147621476
context.get_admin_context(), ins_ref, '10.0.0.2',
2147721477
flavor_obj, None)
2147821478

21479+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21480+
'_cleanup_failed_instance_base')
2147921481
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs')
2148021482
@mock.patch('nova.virt.libvirt.utils.save_and_migrate_vtpm_dir')
2148121483
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
@@ -21492,7 +21494,7 @@ def _test_migrate_disk_and_power_off(
2149221494
self, ctxt, flavor_obj, mock_execute, mock_exists, mock_rename,
2149321495
mock_is_shared, mock_get_host_ip, mock_destroy,
2149421496
mock_get_disk_info, mock_vtpm, mock_unplug_vifs,
21495-
block_device_info=None, params_for_instance=None):
21497+
mock_cleanup, block_device_info=None, params_for_instance=None):
2149621498
"""Test for nova.virt.libvirt.driver.LivirtConnection
2149721499
.migrate_disk_and_power_off.
2149821500
"""
@@ -21507,6 +21509,8 @@ def _test_migrate_disk_and_power_off(
2150721509
ctxt, instance, '10.0.0.2', flavor_obj, None,
2150821510
block_device_info=block_device_info)
2150921511

21512+
mock_cleanup.assert_called_once()
21513+
mock_cleanup.reset_mock()
2151021514
self.assertEqual(out, disk_info_text)
2151121515
mock_vtpm.assert_called_with(
2151221516
instance.uuid, mock.ANY, mock.ANY, '10.0.0.2', mock.ANY, mock.ANY)
@@ -21517,6 +21521,7 @@ def _test_migrate_disk_and_power_off(
2151721521
ctxt, instance, '10.0.0.1', flavor_obj, None,
2151821522
block_device_info=block_device_info)
2151921523

21524+
mock_cleanup.assert_called_once()
2152021525
self.assertEqual(out, disk_info_text)
2152121526
mock_vtpm.assert_called_with(
2152221527
instance.uuid, mock.ANY, mock.ANY, '10.0.0.1', mock.ANY, mock.ANY)
@@ -22414,8 +22419,8 @@ def test_finish_revert_migration_snap_backend_image_does_not_exist(self):
2241422419
self.assertFalse(drvr.image_backend.remove_snap.called)
2241522420

2241622421
@mock.patch.object(shutil, 'rmtree')
22417-
def test_cleanup_failed_migration(self, mock_rmtree):
22418-
self.drvr._cleanup_failed_migration('/fake/inst')
22422+
def test_cleanup_failed_instance_base(self, mock_rmtree):
22423+
self.drvr._cleanup_failed_instance_base('/fake/inst')
2241922424
mock_rmtree.assert_called_once_with('/fake/inst')
2242022425

2242122426
@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
@@ -10852,6 +10852,9 @@ def migrate_disk_and_power_off(self, context, instance, dest,
1085210852
disk_info = self._get_instance_disk_info(instance, block_device_info)
1085310853

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

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

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

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