diff --git a/src/vmm/src/devices/virtio/block/device.rs b/src/vmm/src/devices/virtio/block/device.rs index b8ba1f428502..c4c77a746b3c 100644 --- a/src/vmm/src/devices/virtio/block/device.rs +++ b/src/vmm/src/devices/virtio/block/device.rs @@ -58,19 +58,24 @@ impl Block { } } - pub fn update_rate_limiter(&mut self, bytes: BucketUpdate, ops: BucketUpdate) { + pub fn update_rate_limiter( + &mut self, + bytes: BucketUpdate, + ops: BucketUpdate, + ) -> Result<(), BlockError> { match self { - Self::Virtio(b) => b.update_rate_limiter(bytes, ops), - Self::VhostUser(_) => {} + Self::Virtio(b) => { + b.update_rate_limiter(bytes, ops); + Ok(()) + } + Self::VhostUser(_) => Err(BlockError::InvalidBlockBackend), } } pub fn update_config(&mut self) -> Result<(), BlockError> { - match self.backend { - BlockBackend::Virtio(_) => Err(BlockError::InvalidBlockBackend), - BlockBackend::VhostUser(ref mut b) => { - b.config_update().map_err(BlockError::VhostUserBackend) - } + match self { + Self::Virtio(_) => Err(BlockError::InvalidBlockBackend), + 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 25d22db1bf99..83d1607e1c6d 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) } @@ -636,8 +636,9 @@ impl Vmm { ) -> Result<(), VmmError> { self.mmio_device_manager .with_virtio_device_with_id(TYPE_BLOCK, drive_id, |block: &mut Block| { - block.update_rate_limiter(rl_bytes, rl_ops); - Ok(()) + block + .update_rate_limiter(rl_bytes, rl_ops) + .map_err(|err| err.to_string()) }) .map_err(VmmError::DeviceManager) } @@ -646,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 b50c717df8b4..18f1622fbece 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(test_microvm_with_api): 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)