2015-02-20 13:39:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import stat
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from gns3server.modules.qemu import Qemu
|
|
|
|
from tests.utils import asyncio_patch
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_qemu_version(loop):
|
|
|
|
|
2015-02-20 16:45:27 +00:00
|
|
|
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
2015-02-20 13:39:13 +00:00
|
|
|
version = loop.run_until_complete(asyncio.async(Qemu._get_qemu_version("/tmp/qemu-test")))
|
|
|
|
assert version == "2.2.0"
|
|
|
|
|
|
|
|
|
|
|
|
def test_binary_list(loop):
|
|
|
|
|
2015-04-20 08:12:17 +00:00
|
|
|
files_to_create = ["qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"]
|
2015-02-20 13:39:13 +00:00
|
|
|
|
|
|
|
for file_to_create in files_to_create:
|
|
|
|
path = os.path.join(os.environ["PATH"], file_to_create)
|
|
|
|
with open(path, "w+") as f:
|
|
|
|
f.write("1")
|
|
|
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
|
|
|
|
2015-02-20 16:45:27 +00:00
|
|
|
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
2015-02-20 13:39:13 +00:00
|
|
|
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list()))
|
|
|
|
|
|
|
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": "2.2.0"} in qemus
|
2015-04-20 08:12:17 +00:00
|
|
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": "2.2.0"} in qemus
|
2015-02-20 13:39:13 +00:00
|
|
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": "2.2.0"} in qemus
|
|
|
|
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": "2.2.0"} not in qemus
|
|
|
|
|
|
|
|
|
2015-02-26 01:55:35 +00:00
|
|
|
def test_get_legacy_vm_workdir():
|
2015-02-20 13:39:13 +00:00
|
|
|
|
2015-02-26 09:45:37 +00:00
|
|
|
assert Qemu.get_legacy_vm_workdir(42, "bla") == "qemu/vm-42"
|