Merge "Adds check for VM snapshot fail while quiesce"

This commit is contained in:
Zuul 2022-12-03 13:11:20 +00:00 committed by Gerrit Code Review
commit bee679751b
5 changed files with 36 additions and 2 deletions

View File

@ -1353,6 +1353,8 @@ class ServersController(wsgi.Controller):
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'createImage', id)
except exception.InstanceQuiesceFailed as err:
raise exc.HTTPConflict(explanation=err.format_message())
except exception.Invalid as err:
raise exc.HTTPBadRequest(explanation=err.format_message())
except exception.OverQuota as e:

View File

@ -217,6 +217,11 @@ class InvalidVIOMMUArchitecture(Invalid):
"but given architecture %(arch)s.")
class InstanceQuiesceFailed(Invalid):
msg_fmt = _("Failed to quiesce instance: %(reason)s")
code = 409
class InvalidConfiguration(Invalid):
msg_fmt = _("Configuration is Invalid.")

View File

@ -58,10 +58,11 @@ class LibvirtDriverTests(
nova_fixtures.libvirt.Domain, 'fsFreeze'
) as mock_obj:
ex = nova_fixtures.libvirt.libvirtError("Error")
ex.err = (nova_fixtures.libvirt.VIR_ERR_AGENT_UNRESPONSIVE,)
mock_obj.side_effect = ex
excep = self.assertRaises(
client.OpenStackApiException,
self._snapshot_server, server, "snapshot-1"
)
self.assertEqual(500, excep.response.status_code)
self.assertEqual(409, excep.response.status_code)

View File

@ -9244,6 +9244,26 @@ class LibvirtConnTestCase(test.NoDBTestCase,
image_meta))
mock_fsthaw.assert_called_once_with()
def test_set_quiesced_agent_connection_fails(self):
# This is require to mock guest host
self.create_fake_libvirt_mock(lookupByUUIDString=self.fake_lookup)
with mock.patch.object(FakeVirtDomain, "fsFreeze") as mock_fsfreeze:
error = fakelibvirt.make_libvirtError(
fakelibvirt.libvirtError,
"QEMU guest agent is not connected",
error_code=fakelibvirt.VIR_ERR_AGENT_UNRESPONSIVE)
mock_fsfreeze.side_effect = error
mock_fsfreeze.error_code = error.get_error_code()
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI())
instance = objects.Instance(**self.test_instance)
image_meta = objects.ImageMeta.from_dict(
{"properties": {"hw_qemu_guest_agent": "yes", }})
self.assertRaises(exception.InstanceQuiesceFailed,
drvr._set_quiesced, self.context, instance, image_meta, True)
def test_create_snapshot_metadata(self):
base = objects.ImageMeta.from_dict(
{'disk_format': 'raw'})

View File

@ -3250,7 +3250,13 @@ class LibvirtDriver(driver.ComputeDriver):
'[Error Code %(error_code)s] %(ex)s')
% {'instance_name': instance.name,
'error_code': error_code, 'ex': err_msg})
raise exception.InternalError(msg)
if error_code == libvirt.VIR_ERR_AGENT_UNRESPONSIVE:
msg += (", libvirt cannot connect to the qemu-guest-agent"
" inside the instance.")
raise exception.InstanceQuiesceFailed(reason=msg)
else:
raise exception.InternalError(msg)
def quiesce(self, context, instance, image_meta):
"""Freeze the guest filesystems to prepare for snapshot.