Skip to content

Commit

Permalink
Change the way we look for Qemu path
Browse files Browse the repository at this point in the history
Fix #302
  • Loading branch information
julien-duponchelle committed Aug 27, 2015
1 parent c361d27 commit d853ffe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gns3server/modules/qemu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def paths_list():
if "PROGRAMFILES" in os.environ and os.path.exists(os.environ["PROGRAMFILES"]):
paths.add(os.path.join(os.environ["PROGRAMFILES"], "qemu"))
elif sys.platform.startswith("darwin"):
# add specific locations on Mac OS X regardless of what's in $PATH
paths.update(["/usr/bin", "/usr/local/bin", "/opt/local/bin"])
if hasattr(sys, "frozen"):
# add specific locations on Mac OS X regardless of what's in $PATH
paths.update(["/usr/bin", "/usr/local/bin", "/opt/local/bin"])
try:
exec_dir = os.path.dirname(os.path.abspath(sys.executable))
paths.add(os.path.abspath(os.path.join(exec_dir, "../Resources/qemu/bin/")))
Expand Down
7 changes: 5 additions & 2 deletions gns3server/modules/qemu/qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def qemu_path(self, qemu_path):
"""

if qemu_path and os.pathsep not in qemu_path:
qemu_path = shutil.which(qemu_path)
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))
qemu_path = new_qemu_path

self._check_qemu_path(qemu_path)
self._qemu_path = qemu_path
Expand All @@ -161,7 +164,7 @@ def qemu_path(self, qemu_path):

def _check_qemu_path(self, qemu_path):
if qemu_path is None:
raise QemuError("QEMU binary path is not set or not found in the path")
raise QemuError("QEMU binary path is not set")
if not os.path.exists(qemu_path):
raise QemuError("QEMU binary '{}' is not accessible".format(qemu_path))
if not os.access(qemu_path, os.X_OK):
Expand Down
6 changes: 4 additions & 2 deletions tests/modules/qemu/test_qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from tests.utils import asyncio_patch


from unittest import mock
from unittest.mock import patch, MagicMock

from gns3server.modules.qemu.qemu_vm import QemuVM
from gns3server.modules.qemu.qemu_error import QemuError
from gns3server.modules.qemu import Qemu
Expand Down Expand Up @@ -276,9 +278,9 @@ def test_set_platform(project, manager):
with patch("gns3server.modules.qemu.QemuVM._check_qemu_path"):
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, platform="x86_64")
if sys.platform.startswith("win"):
which_mock.assert_called_with("qemu-system-x86_64w.exe")
which_mock.assert_called_with("qemu-system-x86_64w.exe", path=mock.ANY)
else:
which_mock.assert_called_with("qemu-system-x86_64")
which_mock.assert_called_with("qemu-system-x86_64", path=mock.ANY)
assert vm.platform == "x86_64"
assert vm.qemu_path == "/bin/qemu-system-x86_64"

Expand Down

0 comments on commit d853ffe

Please sign in to comment.