Merge "Ensure that instance directory is removed after success migration/resize" into stable/ocata
This commit is contained in:
commit
423a9f0c80
|
@ -16304,8 +16304,9 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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'
|
||||
|
||||
|
@ -16313,6 +16314,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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')
|
||||
|
@ -16323,16 +16325,18 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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'
|
||||
|
||||
|
@ -16340,6 +16344,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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)
|
||||
|
@ -16355,8 +16360,10 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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'
|
||||
|
||||
|
@ -16366,6 +16373,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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')
|
||||
|
@ -16379,8 +16387,10 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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'
|
||||
|
||||
|
@ -16389,6 +16399,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
|
|||
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()
|
||||
|
|
|
@ -1110,7 +1110,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
host=CONF.host)
|
||||
|
||||
def _cleanup_resize(self, instance, network_info):
|
||||
target = libvirt_utils.get_instance_path(instance) + '_resize'
|
||||
inst_base = libvirt_utils.get_instance_path(instance)
|
||||
target = inst_base + '_resize'
|
||||
|
||||
if os.path.exists(target):
|
||||
# Deletion can fail over NFS, so retry the deletion as required.
|
||||
|
@ -1131,6 +1132,16 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
root_disk.remove_snap(libvirt_utils.RESIZE_SNAPSHOT_NAME,
|
||||
ignore_errors=True)
|
||||
|
||||
# NOTE(mjozefcz):
|
||||
# self.image_backend.image for some backends recreates instance
|
||||
# directory and image disk.info - remove it here if exists
|
||||
if os.path.exists(inst_base) and not root_disk.exists():
|
||||
try:
|
||||
shutil.rmtree(inst_base)
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
|
||||
if instance.host != CONF.host:
|
||||
self._undefine_domain(instance)
|
||||
self.unplug_vifs(instance, network_info)
|
||||
|
|
Loading…
Reference in New Issue