From 4c3bfde97e00b9f9fca2c06cdc6acfb1993a5b43 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 23 Jun 2016 12:10:18 +0200 Subject: [PATCH] Fix test suite after VPCS changes for using ubridge --- gns3server/compute/vpcs/vpcs_vm.py | 3 +++ .../handlers/api/controller/drawing_handler.py | 1 - tests/compute/vpcs/test_vpcs_vm.py | 15 ++++++++------- tests/conftest.py | 12 ++++++++++++ tests/controller/test_udp_link.py | 8 ++------ tests/handlers/api/controller/test_shape.py | 1 - 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/gns3server/compute/vpcs/vpcs_vm.py b/gns3server/compute/vpcs/vpcs_vm.py index 3a0f6bb4..054d8382 100644 --- a/gns3server/compute/vpcs/vpcs_vm.py +++ b/gns3server/compute/vpcs/vpcs_vm.py @@ -108,6 +108,9 @@ class VPCSVM(BaseNode): if not path: raise VPCSError("No path to a VPCS executable has been set") + # This raise an error if ubridge is not available + ubridge_path = self.ubridge_path + if not os.path.isfile(path): raise VPCSError("VPCS program '{}' is not accessible".format(path)) diff --git a/gns3server/handlers/api/controller/drawing_handler.py b/gns3server/handlers/api/controller/drawing_handler.py index 49f18763..da44fde4 100644 --- a/gns3server/handlers/api/controller/drawing_handler.py +++ b/gns3server/handlers/api/controller/drawing_handler.py @@ -104,4 +104,3 @@ class DrawingHandler: project = controller.get_project(request.match_info["project_id"]) yield from project.delete_drawing(request.match_info["drawing_id"]) response.set_status(204) - diff --git a/tests/compute/vpcs/test_vpcs_vm.py b/tests/compute/vpcs/test_vpcs_vm.py index 2e3cb2d7..6d13277e 100644 --- a/tests/compute/vpcs/test_vpcs_vm.py +++ b/tests/compute/vpcs/test_vpcs_vm.py @@ -21,9 +21,9 @@ import asyncio import os import sys -from tests.utils import asyncio_patch +from tests.utils import asyncio_patch, AsyncioMagicMock from gns3server.utils import parse_version -from unittest.mock import patch, MagicMock +from unittest.mock import patch, MagicMock, ANY from gns3server.compute.vpcs.vpcs_vm import VPCSVM from gns3server.compute.vpcs.vpcs_error import VPCSError @@ -39,9 +39,10 @@ def manager(port_manager): @pytest.fixture(scope="function") -def vm(project, manager): +def vm(project, manager, ubridge_path): vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager) vm._vpcs_version = parse_version("0.9") + vm._start_ubridge = AsyncioMagicMock() return vm @@ -104,9 +105,9 @@ def test_start(loop, vm, async_run): '-F', '-R', '-s', - '4242', + ANY, '-c', - '4243', + ANY, '-t', '127.0.0.1') assert vm.is_running() @@ -138,9 +139,9 @@ def test_start_0_6_1(loop, vm): '1', '-F', '-s', - '4242', + ANY, '-c', - '4243', + ANY, '-t', '127.0.0.1') assert vm.is_running() diff --git a/tests/conftest.py b/tests/conftest.py index 7231ae27..16708fb3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -205,6 +205,7 @@ def run_around_tests(monkeypatch, port_manager, controller, config): os.makedirs(os.path.join(tmppath, 'projects')) config.set("Server", "projects_path", os.path.join(tmppath, 'projects')) config.set("Server", "images_path", os.path.join(tmppath, 'images')) + config.set("Server", "ubridge_path", os.path.join(tmppath, 'bin', 'ubridge')) config.set("Server", "auth", False) config.set("Server", "controller", True) @@ -252,6 +253,17 @@ def projects_dir(config): return path +@pytest.fixture +def ubridge_path(config): + """ + Get the location of a fake ubridge + """ + path = config.get_section_config("Server").get("ubridge_path") + os.makedirs(os.path.dirname(path), exist_ok=True) + open(path, 'w+').close() + return path + + @pytest.yield_fixture def darwin_platform(): """ diff --git a/tests/controller/test_udp_link.py b/tests/controller/test_udp_link.py index d83c3fb7..2d7cff66 100644 --- a/tests/controller/test_udp_link.py +++ b/tests/controller/test_udp_link.py @@ -123,10 +123,6 @@ def test_choose_capture_side(async_run, project): async_run(link.add_node(node_vpcs, 0, 4)) async_run(link.add_node(node_vpcs2, 3, 1)) - # VPCS doesn't support capture - with pytest.raises(aiohttp.web.HTTPConflict): - link._choose_capture_side()["node"] - # Capture should run on the local node node_iou = Node(project, compute1, "node1", node_type="iou") node_iou2 = Node(project, compute2, "node2", node_type="iou") @@ -151,7 +147,7 @@ def test_capture(async_run, project): capture = async_run(link.start_capture()) assert link.capturing - compute1.post.assert_any_call("/projects/{}/iou/nodes/{}/adapters/3/ports/1/start_capture".format(project.id, node_iou.id), data={ + compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/start_capture".format(project.id, node_vpcs.id), data={ "capture_file_name": link.default_capture_file_name(), "data_link_type": "DLT_EN10MB" }) @@ -159,7 +155,7 @@ def test_capture(async_run, project): capture = async_run(link.stop_capture()) assert link.capturing is False - compute1.post.assert_any_call("/projects/{}/iou/nodes/{}/adapters/3/ports/1/stop_capture".format(project.id, node_iou.id)) + compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/stop_capture".format(project.id, node_vpcs.id)) def test_read_pcap_from_source(project, async_run): diff --git a/tests/handlers/api/controller/test_shape.py b/tests/handlers/api/controller/test_shape.py index b0ab9e11..3f0c02e5 100644 --- a/tests/handlers/api/controller/test_shape.py +++ b/tests/handlers/api/controller/test_shape.py @@ -33,7 +33,6 @@ from gns3server.controller import Controller from gns3server.controller.drawing import Drawing - @pytest.fixture def project(http_controller, async_run): return async_run(Controller.instance().add_project())