[SOLVED] Deleting non-existent storage doesn't return an error code

joshcorreia

New Member
Nov 8, 2023
11
0
1
When I attempt to delete non-existent storage, the command line doesn't return a non-zero exit code. Is this a bug?

Code:
$ sudo qm set 148 --delete scsi0
update VM 148: -delete scsi0
cannot delete 'scsi0' - not set in current configuration!
$ echo $?
0

How can I check that the storage is successfully removed? I'm running this in a pipeline and want to be able to tell when it fails.

Thanks
 
Hi,
IMHO it's debatable if it's a bug, because if the command finishes successfully, the option won't be set in the config anymore. Changing the return value might trip up existing users expecting the current behavior. You can check the configuration if you need to ensure the option is set before trying to delete it.

If removing actually fails, the command will throw an error, e.g.
Code:
root@pve8a1 ~ # qm set 120 --delete scsi0
update VM 120: -delete scsi0
400 Parameter verification failed.
scsi0: hotplug problem - can't unplug bootdisk 'scsi0'

qm set <vmid> [OPTIONS]
root@pve8a1 ~ # echo $?
25
 
Thanks, I'm glad to know that if removing actually fails then an error will be thrown. That was my main concern :)