summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-05-12 04:46:12 +0000
committerGerrit Code Review <review@openstack.org>2018-05-12 04:46:12 +0000
commita0bcc6bda09c5dff4bf0ba57b80ebb94f01567f0 (patch)
tree4105ee1229c289f070a753fe1e8cf2a5a730857f
parentf569cfc59a92b520289421cb677e3f24c9b62276 (diff)
parenta16fa14ce47bd2d3a5189047e9bd330a607ef3cc (diff)
Merge "libvirt: check image type before removing snapshots in _cleanup_resize" into stable/ocata15.1.2stable/ocata
-rwxr-xr-xnova/tests/unit/virt/libvirt/test_driver.py11
-rw-r--r--nova/virt/libvirt/driver.py46
2 files changed, 25 insertions, 32 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index a3257ca..e58a213 100755
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -17014,9 +17014,6 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
17014 fake_net = _fake_network_info(self, 1) 17014 fake_net = _fake_network_info(self, 1)
17015 17015
17016 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 17016 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
17017 drvr.image_backend = mock.Mock()
17018 drvr.image_backend.by_name.return_value = drvr.image_backend
17019 drvr.image_backend.exists.return_value = False
17020 17017
17021 with test.nested( 17018 with test.nested(
17022 mock.patch('nova.compute.utils.is_volume_backed_instance', 17019 mock.patch('nova.compute.utils.is_volume_backed_instance',
@@ -17024,12 +17021,14 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
17024 mock.patch.object(os.path, 'exists'), 17021 mock.patch.object(os.path, 'exists'),
17025 mock.patch.object(libvirt_utils, 'get_instance_path'), 17022 mock.patch.object(libvirt_utils, 'get_instance_path'),
17026 mock.patch.object(utils, 'execute'), 17023 mock.patch.object(utils, 'execute'),
17027 mock.patch.object(shutil, 'rmtree'), 17024 mock.patch.object(drvr.image_backend, 'by_name',
17025 new_callable=mock.NonCallableMock),
17028 mock.patch.object(drvr, '_undefine_domain'), 17026 mock.patch.object(drvr, '_undefine_domain'),
17029 mock.patch.object(drvr, 'unplug_vifs'), 17027 mock.patch.object(drvr, 'unplug_vifs'),
17030 mock.patch.object(drvr, 'unfilter_instance') 17028 mock.patch.object(drvr, 'unfilter_instance')
17031 ) as (mock_volume_backed, mock_exists, mock_get_path, 17029 ) as (mock_volume_backed, mock_exists, mock_get_path,
17032 mock_exec, mock_rmtree, mock_undef, mock_unplug, mock_unfilter): 17030 mock_exec, mock_image_by_name, mock_undef, mock_unplug,
17031 mock_unfilter):
17033 mock_exists.return_value = True 17032 mock_exists.return_value = True
17034 mock_get_path.return_value = '/fake/inst' 17033 mock_get_path.return_value = '/fake/inst'
17035 17034
@@ -17037,7 +17036,6 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
17037 mock_get_path.assert_called_once_with(ins_ref) 17036 mock_get_path.assert_called_once_with(ins_ref)
17038 mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize', 17037 mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
17039 delay_on_retry=True, attempts=5) 17038 delay_on_retry=True, attempts=5)
17040 mock_rmtree.assert_called_once_with('/fake/inst')
17041 mock_undef.assert_called_once_with(ins_ref) 17039 mock_undef.assert_called_once_with(ins_ref)
17042 mock_unplug.assert_called_once_with(ins_ref, fake_net) 17040 mock_unplug.assert_called_once_with(ins_ref, fake_net)
17043 mock_unfilter.assert_called_once_with(ins_ref, fake_net) 17041 mock_unfilter.assert_called_once_with(ins_ref, fake_net)
@@ -17083,6 +17081,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
17083 17081
17084 def test_cleanup_resize_snap_backend(self): 17082 def test_cleanup_resize_snap_backend(self):
17085 CONF.set_override('policy_dirs', [], group='oslo_policy') 17083 CONF.set_override('policy_dirs', [], group='oslo_policy')
17084 self.flags(images_type='rbd', group='libvirt')
17086 ins_ref = self._create_instance({'host': CONF.host}) 17085 ins_ref = self._create_instance({'host': CONF.host})
17087 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 17086 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
17088 drvr.image_backend = mock.Mock() 17087 drvr.image_backend = mock.Mock()
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 7416bc3..34ea1ae 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -1143,32 +1143,26 @@ class LibvirtDriver(driver.ComputeDriver):
1143 utils.execute('rm', '-rf', target, delay_on_retry=True, 1143 utils.execute('rm', '-rf', target, delay_on_retry=True,
1144 attempts=5) 1144 attempts=5)
1145 1145
1146 root_disk = self.image_backend.by_name(instance, 'disk') 1146 # NOTE(mriedem): Some image backends will recreate the instance path
1147 # TODO(nic): Set ignore_errors=False in a future release. 1147 # and disk.info during init, and all we need the root disk for
1148 # It is set to True here to avoid any upgrade issues surrounding 1148 # here is removing cloned snapshots which is backend-specific, so
1149 # instances being in pending resize state when the software is updated; 1149 # check that first before initializing the image backend object. If
1150 # in that case there will be no snapshot to remove. Once it can be 1150 # there is ever an image type that supports clone *and* re-creates
1151 # reasonably assumed that no such instances exist in the wild 1151 # the instance directory and disk.info on init, this condition will
1152 # anymore, it should be set back to False (the default) so it will 1152 # need to be re-visited to make sure that backend doesn't re-create
1153 # throw errors, like it should. 1153 # the disk. Refer to bugs: 1666831 1728603 1769131
1154 if root_disk.exists(): 1154 if self.image_backend.backend(CONF.libvirt.images_type).SUPPORTS_CLONE:
1155 root_disk.remove_snap(libvirt_utils.RESIZE_SNAPSHOT_NAME, 1155 root_disk = self.image_backend.by_name(instance, 'disk')
1156 ignore_errors=True) 1156 # TODO(nic): Set ignore_errors=False in a future release.
1157 1157 # It is set to True here to avoid any upgrade issues surrounding
1158 # NOTE(mjozefcz): 1158 # instances being in pending resize state when the software is
1159 # self.image_backend.image for some backends recreates instance 1159 # updated; in that case there will be no snapshot to remove.
1160 # directory and image disk.info - remove it here if exists 1160 # Once it can be reasonably assumed that no such instances exist
1161 # Do not remove inst_base for volume-backed instances since that 1161 # in the wild anymore, it should be set back to False
1162 # could potentially remove the files on the destination host 1162 # (the default) so it will throw errors, like it should.
1163 # if using shared storage. 1163 if root_disk.exists():
1164 if (os.path.exists(inst_base) and not root_disk.exists() and 1164 root_disk.remove_snap(libvirt_utils.RESIZE_SNAPSHOT_NAME,
1165 not compute_utils.is_volume_backed_instance( 1165 ignore_errors=True)
1166 context, instance)):
1167 try:
1168 shutil.rmtree(inst_base)
1169 except OSError as e:
1170 if e.errno != errno.ENOENT:
1171 raise
1172 1166
1173 if instance.host != CONF.host: 1167 if instance.host != CONF.host:
1174 self._undefine_domain(instance) 1168 self._undefine_domain(instance)