From 963e2c53be33533884146aede36df1698d9041a1 Mon Sep 17 00:00:00 2001 From: Egor Lazarchuk Date: Fri, 1 Dec 2023 14:43:54 +0000 Subject: [PATCH] refactor(block): update errors formatting Error formatting has been updated to use `Display`. Signed-off-by: Egor Lazarchuk --- src/vmm/src/devices/virtio/block/device.rs | 2 +- src/vmm/src/lib.rs | 4 ++-- tests/integration_tests/functional/test_api.py | 9 ++------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/vmm/src/devices/virtio/block/device.rs b/src/vmm/src/devices/virtio/block/device.rs index 17df1bbf1a9..c4c77a746b3 100644 --- a/src/vmm/src/devices/virtio/block/device.rs +++ b/src/vmm/src/devices/virtio/block/device.rs @@ -75,7 +75,7 @@ impl Block { pub fn update_config(&mut self) -> Result<(), BlockError> { match self { Self::Virtio(_) => Err(BlockError::InvalidBlockBackend), - Self::VhostUser(ref mut b) => b.config_update().map_err(BlockError::VhostUserBackend), + Self::VhostUser(b) => b.config_update().map_err(BlockError::VhostUserBackend), } } diff --git a/src/vmm/src/lib.rs b/src/vmm/src/lib.rs index 1a643ab733d..83d1607e1c6 100644 --- a/src/vmm/src/lib.rs +++ b/src/vmm/src/lib.rs @@ -622,7 +622,7 @@ impl Vmm { .with_virtio_device_with_id(TYPE_BLOCK, drive_id, |block: &mut Block| { block .update_disk_image(path_on_host) - .map_err(|err| format!("{:?}", err)) + .map_err(|err| err.to_string()) }) .map_err(VmmError::DeviceManager) } @@ -647,7 +647,7 @@ impl Vmm { pub fn update_vhost_user_block_config(&mut self, drive_id: &str) -> Result<(), VmmError> { self.mmio_device_manager .with_virtio_device_with_id(TYPE_BLOCK, drive_id, |block: &mut Block| { - block.update_config().map_err(|err| format!("{:?}", err)) + block.update_config().map_err(|err| err.to_string()) }) .map_err(VmmError::DeviceManager) } diff --git a/tests/integration_tests/functional/test_api.py b/tests/integration_tests/functional/test_api.py index 5d56599ef6f..95086b5cd43 100644 --- a/tests/integration_tests/functional/test_api.py +++ b/tests/integration_tests/functional/test_api.py @@ -804,12 +804,11 @@ def test_send_ctrl_alt_del(uvm_plain): def _drive_patch(test_microvm): """Exercise drive patch test scenarios.""" # Patches without mandatory fields for virtio block are not allowed. - expected_msg = "Invalid device type found on the MMIO bus. Please verify the request arguments." + expected_msg = "Unable to patch the block device: Device manager error: Running method expected different backend. Please verify the request arguments" with pytest.raises(RuntimeError, match=expected_msg): test_microvm.api.drive.patch(drive_id="scratch") # Patches with any fields for vhost-user block are not allowed. - expected_msg = "Invalid device type found on the MMIO bus. Please verify the request arguments." with pytest.raises(RuntimeError, match=expected_msg): test_microvm.api.drive.patch( drive_id="scratch_vub", @@ -817,7 +816,6 @@ def _drive_patch(test_microvm): ) # Patches with any fields for vhost-user block are not allowed. - expected_msg = "Invalid device type found on the MMIO bus. Please verify the request arguments." with pytest.raises(RuntimeError, match=expected_msg): test_microvm.api.drive.patch( drive_id="scratch_vub", @@ -848,10 +846,7 @@ def _drive_patch(test_microvm): ) # Updates to `path_on_host` with an invalid path are not allowed. - expected_msg = ( - "Unable to patch the block device: Device manager error: BackingFile(Os { code: 2, " - f'kind: NotFound, message: "No such file or directory" }}, "{drive_path}") Please verify the request arguments.' - ) + expected_msg = f"Unable to patch the block device: Device manager error: Virtio backend error: Error manipulating the backing file: No such file or directory (os error 2) {drive_path} Please verify the request arguments" with pytest.raises(RuntimeError, match=re.escape(expected_msg)): test_microvm.api.drive.patch(drive_id="scratch", path_on_host=drive_path)