mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Calculate MD5 on thread and before json response, Ref. gui#2239
This commit is contained in:
parent
1582ac3195
commit
bb26e8acdd
@ -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):
|
||||
"""
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user