@@ -21765,6 +21765,7 @@ def test_migrate_disk_and_power_off_exception(
21765
21765
context.get_admin_context(), ins_ref, '10.0.0.2',
21766
21766
flavor_obj, None)
21767
21767
21768
+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs')
21768
21769
@mock.patch('nova.virt.libvirt.utils.save_and_migrate_vtpm_dir')
21769
21770
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21770
21771
'_get_instance_disk_info')
@@ -21779,8 +21780,8 @@ def test_migrate_disk_and_power_off_exception(
21779
21780
def _test_migrate_disk_and_power_off(
21780
21781
self, ctxt, flavor_obj, mock_execute, mock_exists, mock_rename,
21781
21782
mock_is_shared, mock_get_host_ip, mock_destroy,
21782
- mock_get_disk_info, mock_vtpm, block_device_info=None ,
21783
- params_for_instance=None):
21783
+ mock_get_disk_info, mock_vtpm, mock_unplug_vifs ,
21784
+ block_device_info=None, params_for_instance=None):
21784
21785
"""Test for nova.virt.libvirt.driver.LivirtConnection
21785
21786
.migrate_disk_and_power_off.
21786
21787
"""
@@ -21798,7 +21799,8 @@ def _test_migrate_disk_and_power_off(
21798
21799
self.assertEqual(out, disk_info_text)
21799
21800
mock_vtpm.assert_called_with(
21800
21801
instance.uuid, mock.ANY, mock.ANY, '10.0.0.2', mock.ANY, mock.ANY)
21801
-
21802
+ mock_unplug_vifs.assert_called_once()
21803
+ mock_unplug_vifs.reset_mock()
21802
21804
# dest is same host case
21803
21805
out = self.drvr.migrate_disk_and_power_off(
21804
21806
ctxt, instance, '10.0.0.1', flavor_obj, None,
@@ -21807,6 +21809,7 @@ def _test_migrate_disk_and_power_off(
21807
21809
self.assertEqual(out, disk_info_text)
21808
21810
mock_vtpm.assert_called_with(
21809
21811
instance.uuid, mock.ANY, mock.ANY, '10.0.0.1', mock.ANY, mock.ANY)
21812
+ mock_unplug_vifs.assert_called_once()
21810
21813
21811
21814
def test_migrate_disk_and_power_off(self):
21812
21815
flavor = {'root_gb': 10, 'ephemeral_gb': 20}
@@ -21863,6 +21866,8 @@ def test_migrate_disk_and_power_off_boot_from_volume_backed_snapshot(
21863
21866
disconnect_volume.assert_called_with(self.context,
21864
21867
mock.sentinel.conn_info_vda, mock.ANY)
21865
21868
21869
+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs',
21870
+ new=mock.Mock())
21866
21871
@mock.patch('os.rename')
21867
21872
@mock.patch('nova.virt.libvirt.utils.copy_image')
21868
21873
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._destroy')
@@ -21911,6 +21916,8 @@ def test_migrate_disk_and_power_off_swap(self, mock_get_disk_info,
21911
21916
for call in mock_copy_image.mock_calls:
21912
21917
self.assertFalse(call[0].endswith('.swap'))
21913
21918
21919
+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs',
21920
+ new=mock.Mock())
21914
21921
def _test_migrate_disk_and_power_off_resize_check(self, expected_exc):
21915
21922
"""Test for nova.virt.libvirt.libvirt_driver.LibvirtConnection
21916
21923
.migrate_disk_and_power_off.
@@ -21924,6 +21931,8 @@ def _test_migrate_disk_and_power_off_resize_check(self, expected_exc):
21924
21931
self.drvr.migrate_disk_and_power_off,
21925
21932
None, instance, '10.0.0.1', flavor_obj, None)
21926
21933
21934
+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs',
21935
+ new=mock.Mock())
21927
21936
@mock.patch('nova.virt.libvirt.utils.save_and_migrate_vtpm_dir')
21928
21937
@mock.patch('oslo_concurrency.processutils.execute')
21929
21938
@mock.patch('os.rename')
@@ -22105,6 +22114,8 @@ def test_migrate_disk_and_power_off_resize_error_eph(self, mock_get,
22105
22114
flavor_obj = objects.Flavor(**flavor)
22106
22115
self._test_migrate_disk_and_power_off(self.context, flavor_obj)
22107
22116
22117
+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.unplug_vifs',
22118
+ new=mock.Mock())
22108
22119
@mock.patch('os.rename')
22109
22120
@mock.patch('oslo_concurrency.processutils.execute')
22110
22121
@mock.patch('nova.virt.libvirt.utils.copy_image')
@@ -22794,6 +22805,44 @@ def test_cleanup_resize_not_same_host(self):
22794
22805
mock_undef.assert_called_once_with(instance)
22795
22806
mock_unplug.assert_called_once_with(instance, fake_net)
22796
22807
22808
+ @mock.patch('time.sleep', new=mock.Mock())
22809
+ def test_cleanup_resize_not_same_host_works_when_unplug_fails(self):
22810
+ CONF.set_override('policy_dirs', [], group='oslo_policy')
22811
+ host = 'not' + CONF.host
22812
+ instance = self._create_instance({'host': host})
22813
+ instance.old_flavor = instance.flavor
22814
+ instance.new_flavor = instance.flavor
22815
+ fake_net = _fake_network_info(self)
22816
+
22817
+ drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
22818
+
22819
+ with test.nested(
22820
+ mock.patch('nova.compute.utils.is_volume_backed_instance',
22821
+ return_value=False),
22822
+ mock.patch.object(os.path, 'exists'),
22823
+ mock.patch.object(libvirt_utils, 'get_instance_path'),
22824
+ mock.patch.object(shutil, 'rmtree'),
22825
+ mock.patch.object(drvr.image_backend, 'by_name',
22826
+ new_callable=mock.NonCallableMock),
22827
+ mock.patch.object(drvr, '_undefine_domain'),
22828
+ mock.patch.object(drvr, 'unplug_vifs'),
22829
+ mock.patch('nova.virt.libvirt.driver.LOG.debug')
22830
+ ) as (mock_volume_backed, mock_exists, mock_get_path,
22831
+ mock_rmtree, mock_image_by_name, mock_undef, mock_unplug,
22832
+ mock_log):
22833
+ mock_exists.return_value = True
22834
+ mock_get_path.return_value = '/fake/inst'
22835
+ error = exception.InternalError("fake error")
22836
+ mock_unplug.side_effect = error
22837
+
22838
+ drvr._cleanup_resize(self.context, instance, fake_net)
22839
+
22840
+ mock_get_path.assert_called_once_with(instance)
22841
+ self.assertEqual(5, mock_rmtree.call_count)
22842
+ mock_undef.assert_called_once_with(instance)
22843
+ mock_unplug.assert_called_once_with(instance, fake_net)
22844
+ mock_log.assert_called_once_with(error, instance=instance)
22845
+
22797
22846
@mock.patch('time.sleep', new=mock.Mock())
22798
22847
def test_cleanup_resize_not_same_host_volume_backed(self):
22799
22848
"""Tests cleaning up after a resize is confirmed with a volume-backed
0 commit comments