virtinst: disk: strip away file:// protocol

This commit is contained in:
scarf 2024-02-18 21:48:43 +09:00 committed by Pavel Hrdina
parent 5fcf506e08
commit ba3a098c3b
2 changed files with 6 additions and 0 deletions

View File

@ -929,6 +929,7 @@ c = vinst.add_category("storage", "--pxe --nographics --noautoconsole --hvm --os
c.add_valid("--disk %(COLLIDE)s --check path_in_use=off") # Colliding storage with --check
c.add_valid("--disk %(COLLIDE)s --force") # Colliding storage with --force
c.add_valid("--disk %(NEWIMG1)s,sparse=true,size=100000000 --check disk_size=off") # Don't warn about fully allocated file exceeding disk space
c.add_valid("--disk file://%(NEWIMG1)s,size=1") # Check that 'file://' prefix is removed correctly
c.add_invalid("--disk /dev/zero --nodisks", grep="Cannot specify storage and use --nodisks")
c.add_invalid("--file %(NEWIMG1)s --file-size 100000 --nonsparse", grep="There is not enough free space") # Nonexisting file, size too big
c.add_invalid("--file %(NEWIMG1)s --file-size 100000", grep="The requested volume capacity will exceed the") # Huge file, sparse, but no prompting

View File

@ -636,6 +636,11 @@ class DeviceDisk(Device):
return self._storage_backend.get_path()
def set_source_path(self, newpath):
# Some file managers use 'file://' when passing files to
# virt-manager, we need to strip it from the newpath.
if newpath is not None:
newpath = newpath.removeprefix("file://")
if self._storage_backend.will_create_storage():
raise xmlutil.DevError(
"Can't change disk path if storage creation info "