diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 73f9d7c0..7bba6f50 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -32,7 +32,7 @@ import gns3server import subprocess from gns3server.utils import parse_version -from gns3server.utils.asyncio import subprocess_check_output, wait_run_in_executor +from gns3server.utils.asyncio import subprocess_check_output, cancellable_wait_run_in_executor from .qemu_error import QemuError from ..adapters.ethernet_adapter import EthernetAdapter from ..nios.nio_udp import NIOUDP @@ -873,6 +873,22 @@ class QemuVM(BaseNode): except (OSError, subprocess.SubprocessError) as e: raise QemuError("Could not throttle CPU: {}".format(e)) + @asyncio.coroutine + def create(self): + """ + Creates QEMU VM and sets proper MD5 hashes + """ + + # In case user upload image manually we don't have md5 sums. + # We need generate hashes at this point, otherwise they will be generated + # at __json__ but not on separate thread. + yield from cancellable_wait_run_in_executor(md5sum, self._hda_disk_image) + yield from cancellable_wait_run_in_executor(md5sum, self._hdb_disk_image) + yield from cancellable_wait_run_in_executor(md5sum, self._hdc_disk_image) + yield from cancellable_wait_run_in_executor(md5sum, self._hdd_disk_image) + + super(QemuVM, self).create() + @asyncio.coroutine def start(self): """ diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 90347176..27dd2160 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -89,6 +89,21 @@ def test_vm(project, manager, fake_qemu_binary): assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f" +def test_vm_create(loop, tmpdir, project, manager, fake_qemu_binary): + fake_img = str(tmpdir / 'hello') + + with open(fake_img, 'w+') as f: + f.write('hello') + + vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path=fake_qemu_binary) + vm._hda_disk_image = fake_img + + loop.run_until_complete(asyncio.ensure_future(vm.create())) + + # tests if `create` created md5sums + assert os.path.exists(str(tmpdir / 'hello.md5sum')) + + def test_vm_invalid_qemu_with_platform(project, manager, fake_qemu_binary): vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path="/usr/fake/bin/qemu-system-64", platform="x86_64")