Skip to content

Commit

Permalink
virt.init: cdrom format default to raw
Browse files Browse the repository at this point in the history
cdrom sources can't be of format qcow2. Force raw as the default if
needed when creating VM with source_file set for the cdrom.
  • Loading branch information
cbosdo committed Jun 4, 2020
1 parent 5ff04dc commit bc892fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,9 @@ def _disk_profile(conn, profile, hypervisor, disks, vm_name):
if disk.get("source_file") and os.path.exists(disk["source_file"]):
disk["filename"] = os.path.basename(disk["source_file"])
if not disk.get("format"):
disk["format"] = "qcow2"
disk["format"] = (
"qcow2" if disk.get("device", "disk") != "cdrom" else "raw"
)
elif disk.get("device", "disk") == "disk":
_fill_disk_filename(conn, vm_name, disk, hypervisor, pool_caps)

Expand Down
9 changes: 8 additions & 1 deletion tests/unit/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,12 +868,19 @@ def test_disk_profile_cdrom_default(self):
self.mock_conn,
None,
"kvm",
[{"name": "mydisk", "device": "cdrom"}],
[
{
"name": "mydisk",
"device": "cdrom",
"source_file": "/path/to/my.iso",
}
],
"hello",
)

self.assertEqual(len(diskp), 1)
self.assertEqual(diskp[0]["model"], "ide")
self.assertEqual(diskp[0]["format"], "raw")

def test_disk_profile_pool_disk_type(self):
"""
Expand Down

0 comments on commit bc892fb

Please sign in to comment.