with test.nested(
mock.patch.object(os.path, 'exists'),
mock.patch.object(libvirt_utils, 'get_instance_path'),
- mock.patch.object(utils, 'execute')) as (
- mock_exists, mock_get_path, mock_exec):
+ mock.patch.object(utils, 'execute'),
+ mock.patch.object(shutil, 'rmtree')) as (
+ mock_exists, mock_get_path, mock_exec, mock_rmtree):
mock_exists.return_value = True
mock_get_path.return_value = '/fake/inst'
mock_get_path.assert_called_once_with(ins_ref)
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
+ mock_rmtree.assert_not_called()
def test_cleanup_resize_not_same_host(self):
CONF.set_override('policy_dirs', [], group='oslo_policy')
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
drvr.image_backend = mock.Mock()
drvr.image_backend.by_name.return_value = drvr.image_backend
+ drvr.image_backend.exists.return_value = False
with test.nested(
mock.patch.object(os.path, 'exists'),
mock.patch.object(libvirt_utils, 'get_instance_path'),
mock.patch.object(utils, 'execute'),
+ mock.patch.object(shutil, 'rmtree'),
mock.patch.object(drvr, '_undefine_domain'),
mock.patch.object(drvr, 'unplug_vifs'),
mock.patch.object(drvr, 'unfilter_instance')
- ) as (mock_exists, mock_get_path, mock_exec, mock_undef,
- mock_unplug, mock_unfilter):
+ ) as (mock_exists, mock_get_path, mock_exec, mock_rmtree,
+ mock_undef, mock_unplug, mock_unfilter):
mock_exists.return_value = True
mock_get_path.return_value = '/fake/inst'
mock_get_path.assert_called_once_with(ins_ref)
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
+ mock_rmtree.assert_called_once_with('/fake/inst')
mock_undef.assert_called_once_with(ins_ref)
mock_unplug.assert_called_once_with(ins_ref, fake_net)
mock_unfilter.assert_called_once_with(ins_ref, fake_net)
mock.patch.object(os.path, 'exists'),
mock.patch.object(libvirt_utils, 'get_instance_path'),
mock.patch.object(utils, 'execute'),
+ mock.patch.object(shutil, 'rmtree'),
mock.patch.object(drvr.image_backend, 'remove_snap')) as (
- mock_exists, mock_get_path, mock_exec, mock_remove):
+ mock_exists, mock_get_path, mock_exec, mock_rmtree,
+ mock_remove):
mock_exists.return_value = True
mock_get_path.return_value = '/fake/inst'
delay_on_retry=True, attempts=5)
mock_remove.assert_called_once_with(
libvirt_utils.RESIZE_SNAPSHOT_NAME, ignore_errors=True)
+ self.assertFalse(mock_rmtree.called)
def test_cleanup_resize_snap_backend_image_does_not_exist(self):
CONF.set_override('policy_dirs', [], group='oslo_policy')
mock.patch.object(os.path, 'exists'),
mock.patch.object(libvirt_utils, 'get_instance_path'),
mock.patch.object(utils, 'execute'),
+ mock.patch.object(shutil, 'rmtree'),
mock.patch.object(drvr.image_backend, 'remove_snap')) as (
- mock_exists, mock_get_path, mock_exec, mock_remove):
+ mock_exists, mock_get_path, mock_exec, mock_rmtree,
+ mock_remove):
mock_exists.return_value = True
mock_get_path.return_value = '/fake/inst'
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
self.assertFalse(mock_remove.called)
+ mock_rmtree.called_once_with('/fake/inst')
def test_get_instance_disk_info_exception(self):
instance = self._create_instance()