Open tash opened 4 years ago
Reproduction steps:
# mkdir /pool/
# qemu-img create -f qcow2 /pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2 8G
# salt-call --local -l debug virt.init targethost1 2 4096 start=False disk=None disks="[{'name':'default','image':'/pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2','overlay_image': True,}]"
Output on default configuration is slightly different because virt:images
path is default value:
[ERROR ] Command '['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file="/pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2"', '"/srv/salt-images/targethost1_default.qcow2"']' failed with return code: 1
[ERROR ] stdout: qemu-img: "/srv/salt-images/targethost1_default.qcow2": Could not open '"/srv/salt-images/"/pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2"': No such file or directory
Could not open backing image to determine size.
[ERROR ] retcode: 1
[ERROR ] Command '['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file="/pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2"', '"/srv/salt-images/targethost1_default.qcow2"']' failed with return code: 1
[ERROR ] output: qemu-img: "/srv/salt-images/targethost1_default.qcow2": Could not open '"/srv/salt-images/"/pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2"': No such file or directory
Could not open backing image to determine size.
Reproducible on Salt >= 2019.2.1.
The fix mentioned by @tash resolves the issue but it's not a proper fix because it will break paths with spaces.
~~Yeah, my solution is just a bandaid. ~~
Similar call, can someone check this?
@DmitryKuzmenko Apparently providing " to account for spaces in given paths is superfluous. At some point a subprocess call is made. This does not work (same error as reported):
>>> subprocess.run(['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file="/pool/this is a test.qcow2"', '/pool/itworks.qcow2'])
qemu-img: /pool/itworks.qcow2: Could not open '/pool/"/pool/this is a test.qcow2"': No such file or directory
Could not open backing image to determine size.
CompletedProcess(args=['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file="/pool/this is a test.qcow2"', '/pool/itworks.qcow2'], returncode=1)
This does work:
>>> subprocess.run(['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file=/pool/this is a test.qcow2', '/pool/itworks.qcow2'])
Formatting '/pool/itworks.qcow2', fmt=qcow2 size=8589934592 backing_file=/pool/this is a test.qcow2 cluster_size=65536 lazy_refcounts=off refcount_bits=16
CompletedProcess(args=['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file=/pool/this is a test.qcow2', '/pool/itworks.qcow2'], returncode=0)
@tash I've just put a note for a person who will be fixing this issue. This PR #52160 introduced that quotes as a try to resolve some issues with spaces. Your issue shows that it's not enough and we still have to work on fixing this. Thank you for PR and analysis. Your issue will be fixed in one of future releases.
Description of Issue
On initializing a new VM image through
virt.init
and providing disks{..., 'overlay_image'=True, ...} an error is produced when the cmd is run internally with__salt__['cmd.run']()
:It appears that for whatever reason the formatting/escape of double quotes breaks:
https://github.com/saltstack/salt/blob/81eb15264380d82267ffc3c1930410baf1f3fbf1/salt/modules/virt.py#L808-L812
Also, backing files should be provided with. Possible fix, that returns no error:qemu-img create -b
Setup
salt-call -l debug virt.init targethost1 2 4096 start=False disk=None 'disks=[{'\''name'\'':'\''default'\'','\''image'\'':'\''/pool/mytestproject-Leap-15.1.x86_64-1.15.1.qcow2'\'','\''overlay_image'\'': True,}]' 'graphics={'\''type'\'':'\''spice'\'','\''port'\'':'\''-1'\'','\''tls_port'\'':'\''-1'\'',}' 'interfaces=[{'\''name'\'':'\''mytestproject-eth'\'','\''type'\'':'\''network'\'','\''source'\'':'\''mytestproject'\'','\''model'\'':'\''virtio'\'','\''mac'\'':'\''00:00:00:11:11:01'\''}]' nic=None
Steps to Reproduce Issue
salt minion with libvirt.
Versions Report
Note: This being openSUSE, the Salt Version might be misleading.