Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.2' into 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Nov 7, 2024
2 parents f3749e8 + c2db4e8 commit aeae9de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 0 additions & 5 deletions gns3server/compute/qemu/qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,11 +1915,6 @@ async def _disk_options(self):
continue

interface = getattr(self, "hd{}_disk_interface".format(drive))
# fail-safe: use "ide" if there is a disk image and no interface type has been explicitly configured
if interface == "none":
interface = "ide"
setattr(self, "hd{}_disk_interface".format(drive), interface)

disk_name = "hd" + drive
if not os.path.isfile(disk_image) or not os.path.exists(disk_image):
if os.path.islink(disk_image):
Expand Down
17 changes: 14 additions & 3 deletions tests/compute/qemu/test_qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,23 @@ async def test_set_platform(compute_project, manager):
async def test_disk_options(vm, tmpdir, fake_qemu_img_binary):

vm._hda_disk_image = str(tmpdir / "test.qcow2")
vm._hda_disk_interface = "ide"
vm._hdb_disk_image = str(tmpdir / "test2.qcow2")
open(vm._hda_disk_image, "w+").close()
open(vm._hdb_disk_image, "w+").close()

with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM._find_disk_file_format", return_value="qcow2"):
with (asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM._find_disk_file_format", return_value="qcow2")):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
options = await vm._disk_options()
assert process.called
args, kwargs = process.call_args
assert args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hda_disk_image), "-F", "qcow2", "-f", "qcow2", os.path.join(vm.working_dir, "hda_disk.qcow2"))
assert args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hda_disk_image), "-F", "qcow2", "-f", "qcow2", os.path.join(vm.working_dir, "hda_disk.qcow2")) or \
args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hdb_disk_image), "-F", "qcow2", "-f", "qcow2", os.path.join(vm.working_dir, "hdb_disk.qcow2"))

assert options == ['-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk,id=drive0']
assert options == [
'-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk,id=drive0',
'-drive', 'file=' + os.path.join(vm.working_dir, "hdb_disk.qcow2") + ',if=none,index=1,media=disk,id=drive1',
]


async def test_cdrom_option(vm, tmpdir, fake_qemu_img_binary):
Expand Down Expand Up @@ -440,9 +447,13 @@ async def test_tpm_option(vm, tmpdir, fake_qemu_img_binary):
async def test_disk_options_multiple_disk(vm, tmpdir, fake_qemu_img_binary):

vm._hda_disk_image = str(tmpdir / "test0.qcow2")
vm._hda_disk_interface = "ide"
vm._hdb_disk_image = str(tmpdir / "test1.qcow2")
vm._hdb_disk_interface = "ide"
vm._hdc_disk_image = str(tmpdir / "test2.qcow2")
vm._hdc_disk_interface = "ide"
vm._hdd_disk_image = str(tmpdir / "test3.qcow2")
vm._hdd_disk_interface = "ide"
open(vm._hda_disk_image, "w+").close()
open(vm._hdb_disk_image, "w+").close()
open(vm._hdc_disk_image, "w+").close()
Expand Down

0 comments on commit aeae9de

Please sign in to comment.