From 578bb5741d89381cb45b72da1211360c99467263 Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Wed, 6 Aug 2014 22:43:37 +0100 Subject: [PATCH 01/10] Override check_origin from tornado.websocket --- gns3server/handlers/jsonrpc_websocket.py | 3 +++ gns3server/version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gns3server/handlers/jsonrpc_websocket.py b/gns3server/handlers/jsonrpc_websocket.py index 5b18496c..26c96e6a 100644 --- a/gns3server/handlers/jsonrpc_websocket.py +++ b/gns3server/handlers/jsonrpc_websocket.py @@ -52,6 +52,9 @@ class JSONRPCWebSocket(tornado.websocket.WebSocketHandler): self._session_id = str(uuid.uuid4()) self.zmq_router = zmq_router + def check_origin(self, origin): + return True + @property def session_id(self): """ diff --git a/gns3server/version.py b/gns3server/version.py index c206840a..118c2a4c 100644 --- a/gns3server/version.py +++ b/gns3server/version.py @@ -23,5 +23,5 @@ # or negative for a release candidate or beta (after the base version # number has been incremented) -__version__ = "1.0beta1" +__version__ = "1.0beta2-dev1" __version_info__ = (1, 0, 0, -99) From 7cbce0f81b7d4e7e8e493f38cd95728f1b9e2d61 Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 14:32:32 +0100 Subject: [PATCH 02/10] Fix test suite + Install VPCS and dynamips from GNS3 PPA + Drop netifaces-py3 from requirements.txt + Fix/update tests to use installed VPCS and dynamips --- .travis.yml | 5 +++++ requirements.txt | 1 - tests/dynamips/conftest.py | 5 ++--- tests/dynamips/test_c7200.py | 6 +++--- tests/dynamips/test_hypervisor.py | 5 ++--- tests/dynamips/test_hypervisor_manager.py | 5 ++--- tests/dynamips/test_router.py | 12 ++++++------ tests/iou/test_iou_device.py | 6 +++++- tests/vpcs/test_vpcs_device.py | 10 +++++++--- 9 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2440f1dc..b52cdc35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,14 @@ python: - "3.3" - "3.4" +before_install: + - "sudo add-apt-repository ppa:gns3/ppa -y" + - "sudo apt-get update -q" + install: - "pip install -r requirements.txt --use-mirrors" - "pip install tox" + - "sudo apt-get install vpcs dynamips" script: "python setup.py test" diff --git a/requirements.txt b/requirements.txt index ae4f8b0a..e7e14a4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ netifaces tornado pyzmq -netifaces-py3 jsonschema diff --git a/tests/dynamips/conftest.py b/tests/dynamips/conftest.py index fce9f54b..ff70cd58 100644 --- a/tests/dynamips/conftest.py +++ b/tests/dynamips/conftest.py @@ -6,10 +6,9 @@ import os @pytest.fixture(scope="module") def hypervisor(request): - cwd = os.path.dirname(os.path.abspath(__file__)) - dynamips_path = os.path.join(cwd, "dynamips.stable") + dynamips_path = '/usr/bin/dynamips' print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path)) - manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1", 9000) + manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1") hypervisor = manager.start_new_hypervisor() def stop(): diff --git a/tests/dynamips/test_c7200.py b/tests/dynamips/test_c7200.py index 7b74cc7f..ed5df69e 100644 --- a/tests/dynamips/test_c7200.py +++ b/tests/dynamips/test_c7200.py @@ -29,9 +29,9 @@ def test_router_exists(router_c7200): def test_npe(router_c7200): - assert router_c7200.npe == "npe-400" # default value - router_c7200.npe = "npe-200" - assert router_c7200.npe == "npe-200" + assert router_c7200.npe == "npe-200" # default value + router_c7200.npe = "npe-400" + assert router_c7200.npe == "npe-400" def test_midplane(router_c7200): diff --git a/tests/dynamips/test_hypervisor.py b/tests/dynamips/test_hypervisor.py index ed0ee2ab..ce7b2575 100644 --- a/tests/dynamips/test_hypervisor.py +++ b/tests/dynamips/test_hypervisor.py @@ -10,7 +10,7 @@ def test_is_started(hypervisor): def test_port(hypervisor): - assert hypervisor.port == 9000 + assert hypervisor.port == 7200 def test_host(hypervisor): @@ -25,8 +25,7 @@ def test_working_dir(hypervisor): def test_path(hypervisor): - cwd = os.path.dirname(os.path.abspath(__file__)) - dynamips_path = os.path.join(cwd, "dynamips.stable") + dynamips_path = '/usr/bin/dynamips' assert hypervisor.path == dynamips_path diff --git a/tests/dynamips/test_hypervisor_manager.py b/tests/dynamips/test_hypervisor_manager.py index f670641c..adaa79a2 100644 --- a/tests/dynamips/test_hypervisor_manager.py +++ b/tests/dynamips/test_hypervisor_manager.py @@ -7,10 +7,9 @@ import os @pytest.fixture(scope="module") def hypervisor_manager(request): - cwd = os.path.dirname(os.path.abspath(__file__)) - dynamips_path = os.path.join(cwd, "dynamips.stable") + dynamips_path = '/usr/bin/dynamips' print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path)) - manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1", 9000) + manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1") #manager.start_new_hypervisor() diff --git a/tests/dynamips/test_router.py b/tests/dynamips/test_router.py index 1affa539..ebf9835c 100644 --- a/tests/dynamips/test_router.py +++ b/tests/dynamips/test_router.py @@ -9,7 +9,7 @@ import base64 @pytest.fixture def router(request, hypervisor): - router = Router(hypervisor, "router", "c3725") + router = Router(hypervisor, "router", platform="c3725") request.addfinalizer(router.delete) return router @@ -127,9 +127,9 @@ def test_idlepc(router): def test_idlemax(router): - assert router.idlemax == 1500 # default value - router.idlemax = 500 - assert router.idlemax == 500 + assert router.idlemax == 500 # default value + router.idlemax = 1500 + assert router.idlemax == 1500 def test_idlesleep(router): @@ -172,7 +172,7 @@ def test_confreg(router): def test_console(router): - assert router.console == router.hypervisor.baseconsole + router.id + assert router.console == 2001 new_console_port = router.console + 100 router.console = new_console_port assert router.console == new_console_port @@ -180,7 +180,7 @@ def test_console(router): def test_aux(router): - assert router.aux == router.hypervisor.baseaux + router.id + assert router.aux == 2501 new_aux_port = router.aux + 100 router.aux = new_aux_port assert router.aux == new_aux_port diff --git a/tests/iou/test_iou_device.py b/tests/iou/test_iou_device.py index 0749c97f..ecf6d0ac 100644 --- a/tests/iou/test_iou_device.py +++ b/tests/iou/test_iou_device.py @@ -8,12 +8,14 @@ def iou(request): cwd = os.path.dirname(os.path.abspath(__file__)) iou_path = os.path.join(cwd, "i86bi_linux-ipbase-ms-12.4.bin") - iou_device = IOUDevice(iou_path, "/tmp") + iou_device = IOUDevice("IOU1", iou_path, "/tmp") iou_device.start() request.addfinalizer(iou_device.delete) return iou_device +@pytest.mark.skipif(os.environ["TRAVIS"] == "TRUE", + reason="IOU Image not available on Travis") def test_iou_is_started(iou): print(iou.command()) @@ -21,6 +23,8 @@ def test_iou_is_started(iou): assert iou.is_running() +@pytest.mark.skipif(os.environ["TRAVIS"] == "TRUE", + reason="IOU Image not available on Travis") def test_iou_restart(iou): iou.stop() diff --git a/tests/vpcs/test_vpcs_device.py b/tests/vpcs/test_vpcs_device.py index 13609506..781166b4 100644 --- a/tests/vpcs/test_vpcs_device.py +++ b/tests/vpcs/test_vpcs_device.py @@ -6,9 +6,13 @@ import pytest @pytest.fixture(scope="session") def vpcs(request): - cwd = os.path.dirname(os.path.abspath(__file__)) - vpcs_path = os.path.join(cwd, "vpcs") - vpcs_device = VPCSDevice(vpcs_path, "/tmp") + if os.path.isfile("/usr/bin/vpcs"): + vpcs_path = "/usr/bin/vpcs" + else: + cwd = os.path.dirname(os.path.abspath(__file__)) + vpcs_path = os.path.join(cwd, "vpcs") + vpcs_device = VPCSDevice("VPCS1", vpcs_path, "/tmp") + vpcs_device.port_add_nio_binding(0, 'nio_tap:tap0') vpcs_device.start() request.addfinalizer(vpcs_device.delete) return vpcs_device From 8fc4667d2c38e51aaa031c56efb537d8bc4436b5 Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 14:49:10 +0100 Subject: [PATCH 03/10] Modify the TRAVIS environment check --- tests/iou/test_iou_device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/iou/test_iou_device.py b/tests/iou/test_iou_device.py index ecf6d0ac..c40a7cf9 100644 --- a/tests/iou/test_iou_device.py +++ b/tests/iou/test_iou_device.py @@ -14,7 +14,7 @@ def iou(request): return iou_device -@pytest.mark.skipif(os.environ["TRAVIS"] == "TRUE", +@pytest.mark.skipif(os.environ["TRAVIS"] == 'true', reason="IOU Image not available on Travis") def test_iou_is_started(iou): @@ -23,7 +23,7 @@ def test_iou_is_started(iou): assert iou.is_running() -@pytest.mark.skipif(os.environ["TRAVIS"] == "TRUE", +@pytest.mark.skipif(os.environ["TRAVIS"] == 'true', reason="IOU Image not available on Travis") def test_iou_restart(iou): From 9b010d6388a649b52cfa116a109e9964f24590fa Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 15:00:44 +0100 Subject: [PATCH 04/10] Update test_hypervisor.py + test_stdout: use system dynamips + test_stdout: correct host address to start dynamips on --- tests/dynamips/test_hypervisor.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/dynamips/test_hypervisor.py b/tests/dynamips/test_hypervisor.py index ce7b2575..0ee5a422 100644 --- a/tests/dynamips/test_hypervisor.py +++ b/tests/dynamips/test_hypervisor.py @@ -33,9 +33,8 @@ def test_stdout(): # try to launch Dynamips on the same port # this will fail so that we can read its stdout/stderr - cwd = os.path.dirname(os.path.abspath(__file__)) - dynamips_path = os.path.join(cwd, "dynamips.stable") - hypervisor = Hypervisor(dynamips_path, "/tmp", "172.0.0.1", 7200) + dynamips_path = '/usr/bin/dynamips' + hypervisor = Hypervisor(dynamips_path, "/tmp", "127.0.0.1", 7200) hypervisor.start() # give some time for Dynamips to start time.sleep(0.01) From 4a4a57e1a3c5a219e11e050ff4d83b0527d9b62e Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 17:54:30 +0100 Subject: [PATCH 05/10] Further test fixes + tests/dynamips/test_hypervisor.py: Increase sleep time to prevent random test failures + tests/iou/test_iou_device.py: Rework test skipping based on presence of IOU image rather than environment variable --- tests/dynamips/test_hypervisor.py | 3 ++- tests/iou/test_iou_device.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/dynamips/test_hypervisor.py b/tests/dynamips/test_hypervisor.py index 0ee5a422..36a2dafa 100644 --- a/tests/dynamips/test_hypervisor.py +++ b/tests/dynamips/test_hypervisor.py @@ -1,6 +1,7 @@ from gns3server.modules.dynamips import Hypervisor import time import os +import pytest def test_is_started(hypervisor): @@ -37,6 +38,6 @@ def test_stdout(): hypervisor = Hypervisor(dynamips_path, "/tmp", "127.0.0.1", 7200) hypervisor.start() # give some time for Dynamips to start - time.sleep(0.01) + time.sleep(0.1) output = hypervisor.read_stdout() assert output diff --git a/tests/iou/test_iou_device.py b/tests/iou/test_iou_device.py index c40a7cf9..58581de9 100644 --- a/tests/iou/test_iou_device.py +++ b/tests/iou/test_iou_device.py @@ -3,6 +3,16 @@ import os import pytest +def no_iou(): + cwd = os.path.dirname(os.path.abspath(__file__)) + iou_path = os.path.join(cwd, "i86bi_linux-ipbase-ms-12.4.bin") + + if os.path.isfile(iou_path): + return False + else: + return True + + @pytest.fixture(scope="session") def iou(request): @@ -14,8 +24,7 @@ def iou(request): return iou_device -@pytest.mark.skipif(os.environ["TRAVIS"] == 'true', - reason="IOU Image not available on Travis") +@pytest.mark.skipif(no_iou(), reason="IOU Image not available") def test_iou_is_started(iou): print(iou.command()) @@ -23,8 +32,7 @@ def test_iou_is_started(iou): assert iou.is_running() -@pytest.mark.skipif(os.environ["TRAVIS"] == 'true', - reason="IOU Image not available on Travis") +@pytest.mark.skipif(no_iou(), reason="IOU Image not available") def test_iou_restart(iou): iou.stop() From ad287d34349926de2dd026f6c51e357ff8ae9436 Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 19:14:36 +0100 Subject: [PATCH 06/10] Remove un-needed imports --- tests/dynamips/test_hypervisor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/dynamips/test_hypervisor.py b/tests/dynamips/test_hypervisor.py index 36a2dafa..e6c096b8 100644 --- a/tests/dynamips/test_hypervisor.py +++ b/tests/dynamips/test_hypervisor.py @@ -1,7 +1,5 @@ from gns3server.modules.dynamips import Hypervisor import time -import os -import pytest def test_is_started(hypervisor): From d8f622d438b1b4550dc98b1e4be19ceed3233e4e Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 19:15:26 +0100 Subject: [PATCH 07/10] Streamline TravisCI build + As we use Tox there's no need to run seperate builds for python3.3 and python3.4 + There's no need to install the requirements in main environment as all dependencies are handled in the Tox virtualenv's --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b52cdc35..baf4ca1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,10 @@ language: python -python: - - "3.3" - - "3.4" - before_install: - "sudo add-apt-repository ppa:gns3/ppa -y" - "sudo apt-get update -q" install: - - "pip install -r requirements.txt --use-mirrors" - "pip install tox" - "sudo apt-get install vpcs dynamips" From a4bc96af285f95e07f8eca83281c7cea944b63ce Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Fri, 8 Aug 2014 19:20:20 +0100 Subject: [PATCH 08/10] revert not installing requirements outside of tox --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index baf4ca1c..3a03c5fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ before_install: - "sudo apt-get update -q" install: + - "pip install -r requirements.txt --use-mirrors" - "pip install tox" - "sudo apt-get install vpcs dynamips" From 4a33b2021ca61644981009a127ccb567c36bf193 Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Sat, 9 Aug 2014 12:05:31 +0100 Subject: [PATCH 09/10] Further optimise the Travis testing and improve running tests for a user + Convert setup.py test to run py.test instead of tox + Tox should now run setup.py test + TravisCI will create a job for each TOX_ENV and then execute tox to run the tests for that TOX_ENV --- .travis.yml | 16 ++++++++++------ setup.py | 11 ++++++----- tox.ini | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a03c5fb..883004a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,19 @@ language: python +env: + - TOX_ENV=py33 + - TOX_ENV=py34 + before_install: - - "sudo add-apt-repository ppa:gns3/ppa -y" - - "sudo apt-get update -q" + - sudo add-apt-repository ppa:gns3/ppa -y + - sudo apt-get update -q install: - - "pip install -r requirements.txt --use-mirrors" - - "pip install tox" - - "sudo apt-get install vpcs dynamips" + - pip install tox + - sudo apt-get install vpcs dynamips -script: "python setup.py test" +script: + - tox -e $TOX_ENV branches: only: diff --git a/setup.py b/setup.py index e64cfa3d..7e437d4d 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand -class Tox(TestCommand): +class PyTest(TestCommand): def finalize_options(self): TestCommand.finalize_options(self) @@ -29,8 +29,9 @@ class Tox(TestCommand): def run_tests(self): #import here, cause outside the eggs aren't loaded - import tox - errcode = tox.cmdline(self.test_args) + import pytest + #errcode = tox.cmdline(self.test_args) + errcode = pytest.main(self.test_args) sys.exit(errcode) setup( @@ -38,8 +39,8 @@ setup( version=__import__("gns3server").__version__, url="http://github.com/GNS3/gns3-server", license="GNU General Public License v3 (GPLv3)", - tests_require=["tox"], - cmdclass={"test": Tox}, + tests_require=["pytest"], + cmdclass={"test": PyTest}, author="Jeremy Grossmann", author_email="package-maintainer@gns3.net", description="GNS3 server to asynchronously manage emulators", diff --git a/tox.ini b/tox.ini index b10796da..200e7ce4 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,6 @@ envlist = py33, py34 [testenv] -commands = py.test [] -s tests +commands = python setup.py test deps = -rdev-requirements.txt From e5642546f19e577fe0bfe0919280693ec334f359 Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Sat, 9 Aug 2014 12:26:24 +0100 Subject: [PATCH 10/10] Remove commented line, not needed anymore --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 7e437d4d..78bfa355 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,6 @@ class PyTest(TestCommand): def run_tests(self): #import here, cause outside the eggs aren't loaded import pytest - #errcode = tox.cmdline(self.test_args) errcode = pytest.main(self.test_args) sys.exit(errcode)