From a853e87fa537bc3ecabb74885169b500cdf405ae Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 21 Nov 2016 18:16:50 +0100 Subject: [PATCH] IOURC is a text box instead of a file path Fix https://github.com/GNS3/gns3-gui/issues/1662 --- gns3server/compute/iou/iou_vm.py | 8 ++++---- gns3server/controller/node.py | 10 +++++++++- tests/controller/test_node.py | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/gns3server/compute/iou/iou_vm.py b/gns3server/compute/iou/iou_vm.py index b697f088..ef533e51 100644 --- a/gns3server/compute/iou/iou_vm.py +++ b/gns3server/compute/iou/iou_vm.py @@ -224,6 +224,10 @@ class IOUVM(BaseNode): iourc_path = self._config().get("iourc_path") if not iourc_path: + # look for the iourc file in the temporary dir. + path = os.path.join(self.temporary_directory, "iourc") + if os.path.exists(path): + return path # look for the iourc file in the user home dir. path = os.path.join(os.path.expanduser("~/"), ".iourc") if os.path.exists(path): @@ -232,10 +236,6 @@ class IOUVM(BaseNode): path = os.path.join(self.working_dir, "iourc") if os.path.exists(path): return path - # look for the iourc file in the temporary dir. - path = os.path.join(self.temporary_directory, "iourc") - if os.path.exists(path): - return path return iourc_path @property diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index a7dd6de1..98cf5759 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -387,7 +387,15 @@ class Node: Start a node """ try: - yield from self.post("/start", timeout=240) + # For IOU we need to send the licence everytime + if self.node_type == "iou": + try: + licence = self._project.controller.settings["IOU"]["iourc_content"] + except KeyError: + raise aiohttp.web.HTTPConflict(text="IOU licence is not configured") + yield from self.post("/start", timeout=240, data={"iourc_content": licence}) + else: + yield from self.post("/start", timeout=240) except asyncio.TimeoutError: raise aiohttp.web.HTTPRequestTimeout(text="Timeout when starting {}".format(self._name)) diff --git a/tests/controller/test_node.py b/tests/controller/test_node.py index 0b16edd1..0624cdf5 100644 --- a/tests/controller/test_node.py +++ b/tests/controller/test_node.py @@ -346,6 +346,21 @@ def test_start(node, compute, project, async_run): compute.post.assert_called_with("/projects/{}/vpcs/nodes/{}/start".format(node.project.id, node.id), timeout=240) +def test_start_iou(compute, project, async_run, controller): + node = Node(project, compute, "demo", + node_id=str(uuid.uuid4()), + node_type="iou") + compute.post = AsyncioMagicMock() + + # Without licence configured it should raise an error + with pytest.raises(aiohttp.web.HTTPConflict): + async_run(node.start()) + + controller.settings["IOU"] = {"iourc_content": "aa"} + async_run(node.start()) + compute.post.assert_called_with("/projects/{}/iou/nodes/{}/start".format(node.project.id, node.id), timeout=240, data={"iourc_content": "aa"}) + + def test_stop(node, compute, project, async_run): compute.post = AsyncioMagicMock()