From 818676ce5ed8348925c1bf57323a0806b625ab80 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 25 Feb 2015 16:26:17 +0100 Subject: [PATCH] Support relative path in iou --- gns3server/modules/iou/iou_vm.py | 5 +++++ tests/modules/iou/test_iou_vm.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index 79682479..e2f3ea80 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -39,6 +39,7 @@ from ..nios.nio_tap import NIOTAP from ..nios.nio_generic_ethernet import NIOGenericEthernet from ..base_vm import BaseVM from .ioucon import start_ioucon +from ...config import Config import gns3server.utils.asyncio @@ -131,6 +132,10 @@ class IOUVM(BaseVM): :params path: Path to the binary """ + if path[0] != "/": + server_config = Config.instance().get_section_config("Server") + path = os.path.join(os.path.expanduser(server_config.get("images_path", "~/GNS3/images")), path) + self._path = path if not os.path.isfile(self._path) or not os.path.exists(self._path): if os.path.islink(self._path): diff --git a/tests/modules/iou/test_iou_vm.py b/tests/modules/iou/test_iou_vm.py index 4ee16327..90d59759 100644 --- a/tests/modules/iou/test_iou_vm.py +++ b/tests/modules/iou/test_iou_vm.py @@ -175,6 +175,14 @@ def test_path(vm, fake_iou_bin): assert vm.path == fake_iou_bin + +def test_path_relative(vm, fake_iou_bin, tmpdir): + + with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): + vm.path = "iou.bin" + assert vm.path == fake_iou_bin + + def test_path_invalid_bin(vm, tmpdir): path = str(tmpdir / "test.bin")