Add code for creating qemu image on server side

Ref https://github.com/GNS3/gns3-gui/issues/558
This commit is contained in:
Julien Duponchelle committed 2015-07-27 16:27:14 +02:00
1 parent fcd4fda68e
commit b94a4e2308
3 files changed
+90 -3

No files matched your search

+47
View File
@@ -408,3 +408,50 @@ def test_options(vm):
vm.options = "-usb"
assert vm.options == "-usb"
assert vm.kvm is False
def test_get_qemu_img(vm, tmpdir):
open(str(tmpdir / "qemu-sytem-x86_64"), "w+").close()
open(str(tmpdir / "qemu-img"), "w+").close()
vm._qemu_path = str(tmpdir / "qemu-sytem-x86_64")
assert vm._get_qemu_img() == str(tmpdir / "qemu-img")
def test_get_qemu_img_not_exist(vm, tmpdir):
open(str(tmpdir / "qemu-sytem-x86_64"), "w+").close()
vm._qemu_path = str(tmpdir / "qemu-sytem-x86_64")
with pytest.raises(QemuError):
vm._get_qemu_img()
def test_create_image(vm, loop, fake_qemu_img_binary):
options = {
"type": "qcow2",
"preallocation": "metadata",
"cluster_size": 64,
"refcount_bits": 12,
"lazy_refcounts": "off",
"size": 100
}
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
filename = loop.run_until_complete(asyncio.async(vm._create_disk("hda", options)))
args, kwargs = process.call_args
assert args == (
fake_qemu_img_binary,
"create",
"-f",
"qcow2",
"-o",
"cluster_size=64",
"-o",
"lazy_refcounts=off",
"-o",
"preallocation=metadata",
"-o",
"refcount_bits=12",
os.path.join(vm.working_dir, "hda.qcow2"),
"100M"
)
assert filename == "hda.qcow2"