Qemu fixes for windows

pull/712/head
Julien Duponchelle 8 years ago
parent 20772a310b
commit fd3ac65eb5
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -148,6 +148,8 @@ class QemuVM(BaseNode):
"""
if qemu_path and os.pathsep not in qemu_path:
if sys.platform.startswith("win") and ".exe" not in qemu_path.lower():
qemu_path += "w.exe"
new_qemu_path = shutil.which(qemu_path, path=os.pathsep.join(self._manager.paths_list()))
if new_qemu_path is None:
raise QemuError("QEMU binary path {} is not found in the path".format(qemu_path))
@ -692,9 +694,7 @@ class QemuVM(BaseNode):
:param initrd: QEMU initrd path
"""
if not os.path.isabs(initrd):
server_config = self.manager.config.get_section_config("Server")
initrd = os.path.join(os.path.expanduser(server_config.get("images_path", "~/GNS3/images")), "QEMU", initrd)
initrd = self.manager.get_abs_image_path(initrd)
log.info('QEMU VM "{name}" [{id}] has set the QEMU initrd path to {initrd}'.format(name=self._name,
id=self._id,
@ -721,10 +721,7 @@ class QemuVM(BaseNode):
:param kernel_image: QEMU kernel image path
"""
if not os.path.isabs(kernel_image):
server_config = self.manager.config.get_section_config("Server")
kernel_image = os.path.join(os.path.expanduser(server_config.get("images_path", "~/GNS3/images")), "QEMU", kernel_image)
kernel_image = self.manager.get_abs_image_path(kernel_image)
log.info('QEMU VM "{name}" [{id}] has set the QEMU kernel image path to {kernel_image}'.format(name=self._name,
id=self._id,
kernel_image=kernel_image))

@ -15,9 +15,10 @@
# 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 asyncio
import pytest
import uuid
import asyncio
import sys
import os
from tests.utils import asyncio_patch, AsyncioMagicMock
@ -871,7 +872,7 @@ def test_get_image_informations(project, manager, loop):
loop.run_until_complete(asyncio.async(vm._get_image_information()))
mock.assert_called_with("GET", "images/ubuntu:latest/json")
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_mount_binds(vm, tmpdir):
image_infos = {
"ContainerConfig": {
@ -929,7 +930,7 @@ def test_create_network_interfaces(vm):
assert "eth4" in content
assert "eth5" not in content
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_fix_permission(vm, loop):
vm._volumes = ["/etc"]
process = MagicMock()

@ -185,7 +185,7 @@ def test_get_kvm_archs_kvm_ok(loop):
if platform.machine() == 'x86_64':
assert archs == ['x86_64', 'i386']
else:
assert archs == platform.machine()
assert archs == [ platform.machine() ]
with patch("os.path.exists", return_value=False):
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))

@ -56,7 +56,7 @@ def fake_qemu_img_binary():
def fake_qemu_binary():
if sys.platform.startswith("win"):
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64.EXE")
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.exe")
else:
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64")
with open(bin_path, "w+") as f:
@ -233,7 +233,10 @@ def test_set_qemu_path(vm, tmpdir, fake_qemu_binary):
vm.qemu_path = None
# Should not crash with unicode characters
path = str(tmpdir / "\u62FF" / "qemu-system-mips")
if sys.platform.startswith("win"):
path = str(tmpdir / "\u62FF" / "qemu-system-mipsw.exe")
else:
path = str(tmpdir / "\u62FF" / "qemu-system-mips")
os.makedirs(str(tmpdir / "\u62FF"))
@ -248,8 +251,7 @@ def test_set_qemu_path(vm, tmpdir, fake_qemu_binary):
if not sys.platform.startswith("win"):
with pytest.raises(QemuError):
vm.qemu_path = path
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
vm.qemu_path = path
assert vm.qemu_path == path
@ -269,7 +271,8 @@ def test_set_qemu_path_windows(vm, tmpdir):
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.EXE")
open(bin_path, "w+").close()
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if not sys.platform.startswith("win"):
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
vm.qemu_path = bin_path
@ -281,7 +284,8 @@ def test_set_qemu_path_old_windows(vm, tmpdir):
bin_path = os.path.join(os.environ["PATH"], "qemu.exe")
open(bin_path, "w+").close()
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if not sys.platform.startswith("win"):
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
vm.qemu_path = bin_path
@ -614,27 +618,22 @@ def test_hdd_disk_image(vm, images_dir):
assert vm.hdd_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
def test_initrd(vm, tmpdir):
vm.manager.config.set("Server", "images_path", str(tmpdir))
with patch("gns3server.compute.project.Project.emit") as mock:
vm.initrd = str(tmpdir / "test")
assert vm.initrd == force_unix_path(str(tmpdir / "test"))
vm.initrd = "test"
assert vm.initrd == force_unix_path(str(tmpdir / "QEMU" / "test"))
assert not mock.called
def test_initrd(vm, images_dir):
open(os.path.join(images_dir, "test1"), "w+").close()
vm.initrd = os.path.join(images_dir, "test1")
assert vm.initrd == force_unix_path(os.path.join(images_dir, "test1"))
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
vm.initrd = "test2"
assert vm.initrd == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
def test_initrd_asa(vm, tmpdir):
vm.manager.config.set("Server", "images_path", str(tmpdir))
def test_initrd_asa(vm, images_dir):
with patch("gns3server.compute.project.Project.emit") as mock:
vm.initrd = str(tmpdir / "asa842-initrd.gz")
assert vm.initrd == force_unix_path(str(tmpdir / "asa842-initrd.gz"))
vm.initrd = "asa842-initrd.gz"
assert vm.initrd == force_unix_path(str(tmpdir / "QEMU" / "asa842-initrd.gz"))
open(os.path.join(images_dir, "asa842-initrd.gz"), "w+").close()
vm.initrd = os.path.join(images_dir, "asa842-initrd.gz")
assert vm.initrd == force_unix_path(os.path.join(images_dir, "asa842-initrd.gz"))
assert mock.called

Loading…
Cancel
Save