From 78c301653fd5b6f370b112c86e7e5869a0ba46fa Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 10 Jan 2023 08:23:06 +0800 Subject: [PATCH 1/5] Convert README to Markdown --- MANIFEST.in | 2 +- README.md | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.rst | 241 ------------------------------------------------- setup.py | 2 +- 4 files changed, 258 insertions(+), 243 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/MANIFEST.in b/MANIFEST.in index 2b9ab0ff..6fa63e63 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include README.rst +include README.md include AUTHORS include LICENSE include MANIFEST.in diff --git a/README.md b/README.md new file mode 100644 index 00000000..087d346b --- /dev/null +++ b/README.md @@ -0,0 +1,256 @@ +GNS3-server +=========== + +[![image](https://github.com/GNS3/gns3-server/workflows/testing/badge.svg)](https://github.com/GNS3/gns3-server/actions?query=workflow%3Atesting) + +[![image](https://img.shields.io/pypi/v/gns3-server.svg)](https://pypi.python.org/pypi/gns3-server) + +[![image](https://snyk.io/test/github/GNS3/gns3-server/badge.svg)](https://snyk.io/test/github/GNS3/gns3-server) + +This is the GNS3 server repository. + +The GNS3 server manages emulators such as Dynamips, VirtualBox or +Qemu/KVM. Clients like the [GNS3 GUI](https://github.com/GNS3/gns3-gui/) +and the [GNS3 Web UI](https://github.com/GNS3/gns3-web-ui) control the +server using an HTTP REST API. + +Software dependencies +--------------------- + +In addition of Python dependencies listed in a section below, other +software may be required, recommended or optional. + +- [uBridge](https://github.com/GNS3/ubridge/) is required, it + interconnects the nodes. +- [Dynamips](https://github.com/GNS3/dynamips/) is required for + running IOS routers (using real IOS images) as well as the internal + switches and hubs. +- [VPCS](https://github.com/GNS3/vpcs/) is recommended, it is a + builtin node simulating a very simple computer to perform + connectitivy tests using ping, traceroute etc. +- Qemu is strongly recommended on Linux, as most node types are based + on Qemu, for example Cisco IOSv and Arista vEOS. +- libvirt is recommended (Linux only), as it\'s needed for the NAT + cloud. +- Docker is optional (Linux only), some nodes are based on Docker. +- mtools is recommended to support data transfer to/from QEMU VMs + using virtual disks. +- i386-libraries of libc and libcrypto are optional (Linux only), they + are only needed to run IOU based nodes. + +### Docker support + +Docker support needs the script program (bsdutils or +util-linux package), when running a docker VM and a static +busybox during installation (python3 setup.py install / pip3 install / +package creation). + +Branches +-------- + +### master + +master is the next stable release, you can test it in your day to day +activities. Bug fixes or small improvements pull requests go here. + +### 2.x (2.3 for example) + +Next major release + +*Never* use this branch for production. Pull requests for major new +features go here. + +Linux +----- + +GNS3 is perhaps packaged for your distribution: + +- Gentoo: +- Alpine: + +- NixOS: + + +Linux (Debian based) +-------------------- + +The following instructions have been tested with Ubuntu and Mint. You +must be connected to the Internet in order to install the dependencies. + +Dependencies: + +- Python 3.6, setuptools and the ones listed + [here](https://github.com/GNS3/gns3-server/blob/master/requirements.txt) + +The following commands will install some of these dependencies: + +``` {.bash} +sudo apt-get install python3-setuptools +``` + +Finally, these commands will install the server as well as the rest of +the dependencies: + +``` {.bash} +cd gns3-server-master +sudo python3 setup.py install +gns3server +``` + +To run tests use: + +``` {.bash} +py.test -v +``` + +### Docker container + +For development, you can run the GNS3 server in a container + +``` {.bash} +bash scripts/docker_dev_server.sh +``` + +### Run as daemon (Unix only) + +You will find init sample scripts for various systems inside the init +directory. + +Useful options: + +- `--daemon`: start process as a daemon +- `--log logfile`: store output in a logfile +- `--pid pidfile`: store the pid of the running process in a file and + prevent double execution + +All init scripts require the creation of a GNS3 user. You can change it +to another user. + +``` {.bash} +sudo adduser gns3 +``` + +upstart +------- + +For ubuntu < 15.04 + +You need to copy init/gns3.conf.upstart to /etc/init/gns3.conf + +``` {.bash} +sudo chown root /etc/init/gns3.conf +sudo service gns3 start +``` + +systemd +------- + +You need to copy init/gns3.service.systemd to +/lib/systemd/system/gns3.service + +``` {.bash} +sudo chown root /lib/systemd/system/gns3.service +sudo systemctl start gns3 +``` + +Windows +------- + +Please use our [all-in-one +installer](https://community.gns3.com/software/download) to install the +stable build. + +If you install via source you need to first install: + +- Python (3.3 or above) - +- Pywin32 - + +Then you can call + +``` {.bash} +python setup.py install +``` + +to install the remaining dependencies. + +To run the tests, you also need to call + +``` {.bash} +pip install pytest pytest-capturelog +``` + +before actually running the tests with + +``` {.bash} +python setup.py test +``` + +or with + +``` {.bash} +py.test -v +``` + +Mac OS X +-------- + +Please use our DMG package for a simple installation. + +If you want to test the current git version or contribute to the +project, you can follow these instructions with virtualenvwrapper: + and homebrew: +. + +``` {.bash} +brew install python3 +mkvirtualenv gns3-server --python=/usr/local/bin/python3.5 +python3 setup.py install +gns3server +``` + +SSL +--- + +If you want enable SSL support on GNS3 you can generate a self signed +certificate: + +``` {.bash} +bash gns3server/cert_utils/create_cert.sh +``` + +This command will put the files in \~/.config/GNS3/ssl + +After you can start the server in SSL mode with: + +``` {.bash} +python gns3server/main.py --certfile ~/.config/GNS3/ssl/server.cert --certkey ~/.config/GNS3/ssl/server.key --ssl +``` + +Or in your gns3\_server.conf by adding in the Server section: + +``` {.ini} +[Server] +certfile=/Users/noplay/.config/GNS3/ssl/server.cert +certkey=/Users/noplay/.config/GNS3/ssl/server.key +ssl=True +``` + +### Running tests + +Just run: + +``` {.bash} +py.test -vv +``` + +If you want test coverage: + +``` {.bash} +py.test --cov-report term-missing --cov=gns3server +``` + +Security issues +--------------- + +Please contact us using contact form available here: + diff --git a/README.rst b/README.rst deleted file mode 100644 index 11f2cab1..00000000 --- a/README.rst +++ /dev/null @@ -1,241 +0,0 @@ -GNS3-server -=========== - -.. image:: https://github.com/GNS3/gns3-server/workflows/testing/badge.svg - :target: https://github.com/GNS3/gns3-server/actions?query=workflow%3Atesting - -.. image:: https://img.shields.io/pypi/v/gns3-server.svg - :target: https://pypi.python.org/pypi/gns3-server - -.. image:: https://snyk.io/test/github/GNS3/gns3-server/badge.svg - :target: https://snyk.io/test/github/GNS3/gns3-server - -This is the GNS3 server repository. - -The GNS3 server manages emulators such as Dynamips, VirtualBox or Qemu/KVM. -Clients like the `GNS3 GUI `_ and the `GNS3 Web UI `_ control the server using a HTTP REST API. - -Software dependencies ---------------------- - -In addition of Python dependencies listed in a section below, other software may be required, recommended or optional. - -* `uBridge `_ is required, it interconnects the nodes. -* `Dynamips `_ is required for running IOS routers (using real IOS images) as well as the internal switches and hubs. -* `VPCS `_ is recommended, it is a builtin node simulating a very simple computer to perform connectitivy tests using ping, traceroute etc. -* Qemu is strongly recommended on Linux, as most node types are based on Qemu, for example Cisco IOSv and Arista vEOS. -* libvirt is recommended (Linux only), as it's needed for the NAT cloud. -* Docker is optional (Linux only), some nodes are based on Docker. -* mtools is recommended to support data transfer to/from QEMU VMs using virtual disks. -* i386-libraries of libc and libcrypto are optional (Linux only), they are only needed to run IOU based nodes. - -Docker support -************** - -Docker support needs the script program (`bsdutils` or `util-linux` package), when running a docker VM and a static busybox during installation (python3 setup.py install / pip3 install / package creation). - -Branches --------- - -master -****** -master is the next stable release, you can test it in your day to day activities. -Bug fixes or small improvements pull requests go here. - -2.x (2.3 for example) -********************* -Next major release - -*Never* use this branch for production. Pull requests for major new features go here. - -Linux ------ - -GNS3 is perhaps packaged for your distribution: - -* Gentoo: https://packages.gentoo.org/package/net-misc/gns3-server -* Alpine: https://pkgs.alpinelinux.org/package/v3.10/community/x86_64/gns3-server -* NixOS: https://search.nixos.org/packages?channel=21.11&from=0&size=50&sort=relevance&type=packages&query=gns3-server - - -Linux (Debian based) --------------------- - -The following instructions have been tested with Ubuntu and Mint. -You must be connected to the Internet in order to install the dependencies. - -Dependencies: - -- Python 3.6, setuptools and the ones listed `here `_ - -The following commands will install some of these dependencies: - -.. code:: bash - - sudo apt-get install python3-setuptools - -Finally these commands will install the server as well as the rest of the dependencies: - -.. code:: bash - - cd gns3-server-master - sudo python3 setup.py install - gns3server - -To run tests use: - -.. code:: bash - - py.test -v - - -Docker container -**************** - -For development you can run the GNS3 server in a container - -.. code:: bash - - bash scripts/docker_dev_server.sh - - -Run as daemon (Unix only) -************************** - -You will find init sample scripts for various systems -inside the init directory. - -Usefull options: - -* --daemon: start process as a daemon -* --log logfile: store output in a logfile -* --pid pidfile: store the pid of the running process in a file and prevent double execution - -All init scripts require the creation of a GNS3 user. You can change it to another user. - -.. code:: bash - - sudo adduser gns3 - -upstart -------- - -For ubuntu < 15.04 - -You need to copy init/gns3.conf.upstart to /etc/init/gns3.conf - -.. code:: bash - - sudo chown root /etc/init/gns3.conf - sudo service gns3 start - - -systemd -------- - -You need to copy init/gns3.service.systemd to /lib/systemd/system/gns3.service - -.. code:: bash - - sudo chown root /lib/systemd/system/gns3.service - sudo systemctl start gns3 - -Windows -------- - - -Please use our `all-in-one installer `_ to install the stable build. - -If you install via source you need to first install: - -- Python (3.3 or above) - https://www.python.org/downloads/windows/ -- Pywin32 - https://sourceforge.net/projects/pywin32/ - -Then you can call - -.. code:: bash - - python setup.py install - -to install the remaining dependencies. - -To run the tests, you also need to call - -.. code:: bash - - pip install pytest pytest-capturelog - -before actually running the tests with - -.. code:: bash - - python setup.py test - -or with - -.. code:: bash - - py.test -v - -Mac OS X --------- - -Please use our DMG package for a simple installation. - -If you want to test the current git version or contribute to the project, -you can follow these instructions with virtualenwrapper: http://virtualenvwrapper.readthedocs.org/ -and homebrew: http://brew.sh/. - -.. code:: bash - - brew install python3 - mkvirtualenv gns3-server --python=/usr/local/bin/python3.5 - python3 setup.py install - gns3server - -SSL ---- - -If you want enable SSL support on GNS3 you can generate a self signed certificate: - -.. code:: bash - - bash gns3server/cert_utils/create_cert.sh - -This command will put the files in ~/.config/GNS3/ssl - -After you can start the server in SSL mode with: - -.. code:: bash - - python gns3server/main.py --certfile ~/.config/GNS3/ssl/server.cert --certkey ~/.config/GNS3/ssl/server.key --ssl - - -Or in your gns3_server.conf by adding in the Server section: - -.. code:: ini - - [Server] - certfile=/Users/noplay/.config/GNS3/ssl/server.cert - certkey=/Users/noplay/.config/GNS3/ssl/server.key - ssl=True - -Running tests -************* - -Just run: - -.. code:: bash - - py.test -vv - -If you want test coverage: - -.. code:: bash - - py.test --cov-report term-missing --cov=gns3server - -Security issues ----------------- -Please contact us using contact form available here: -http://docs.gns3.com/1ON9JBXSeR7Nt2-Qum2o3ZX0GU86BZwlmNSUgvmqNWGY/index.html diff --git a/setup.py b/setup.py index 9b0a8655..9d112d58 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ setup( tests_require=["pytest", "pytest-capturelog", "pytest-aiohttp"], cmdclass={"test": PyTest}, description="GNS3 server", - long_description=open("README.rst", "r").read(), + long_description=open("README.md", "r").read(), install_requires=dependencies, entry_points={ "console_scripts": [ From e9c95ff299d569c9de1487d92b0e9f796dedcbee Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 10 Jan 2023 10:07:26 +0800 Subject: [PATCH 2/5] Fix tests --- tests/compute/qemu/test_qemu_manager.py | 5 ++++- tests/compute/qemu/test_qemu_vm.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/compute/qemu/test_qemu_manager.py b/tests/compute/qemu/test_qemu_manager.py index 66e7081e..e940a3ed 100644 --- a/tests/compute/qemu/test_qemu_manager.py +++ b/tests/compute/qemu/test_qemu_manager.py @@ -31,7 +31,10 @@ from unittest.mock import patch, MagicMock @pytest.fixture def fake_qemu_img_binary(tmpdir): - bin_path = str(tmpdir / "qemu-img") + if sys.platform.startswith("win"): + bin_path = str(tmpdir / "qemu-img.exe") + else: + bin_path = str(tmpdir / "qemu-img") with open(bin_path, "w+") as f: f.write("1") os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 634dcdea..31844ab1 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -45,7 +45,10 @@ async def manager(loop, port_manager): def fake_qemu_img_binary(monkeypatch, tmpdir): monkeypatch.setenv("PATH", str(tmpdir)) - bin_path = os.path.join(os.environ["PATH"], "qemu-img") + if sys.platform.startswith("win"): + bin_path = os.path.join(os.environ["PATH"], "qemu-img.exe") + else: + bin_path = os.path.join(os.environ["PATH"], "qemu-img") with open(bin_path, "w+") as f: f.write("1") os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) From eb3fc1bb3a950320d24306367c2ca508553667a1 Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 10 Jan 2023 11:09:27 +0800 Subject: [PATCH 3/5] Fix more tests --- tests/compute/qemu/test_qemu_manager.py | 2 +- tests/compute/qemu/test_qemu_vm.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/compute/qemu/test_qemu_manager.py b/tests/compute/qemu/test_qemu_manager.py index e940a3ed..7a14601f 100644 --- a/tests/compute/qemu/test_qemu_manager.py +++ b/tests/compute/qemu/test_qemu_manager.py @@ -32,7 +32,7 @@ from unittest.mock import patch, MagicMock def fake_qemu_img_binary(tmpdir): if sys.platform.startswith("win"): - bin_path = str(tmpdir / "qemu-img.exe") + bin_path = str(tmpdir / "qemu-img.EXE") else: bin_path = str(tmpdir / "qemu-img") with open(bin_path, "w+") as f: diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 31844ab1..55e9e954 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -46,7 +46,7 @@ def fake_qemu_img_binary(monkeypatch, tmpdir): monkeypatch.setenv("PATH", str(tmpdir)) if sys.platform.startswith("win"): - bin_path = os.path.join(os.environ["PATH"], "qemu-img.exe") + bin_path = os.path.join(os.environ["PATH"], "qemu-img.EXE") else: bin_path = os.path.join(os.environ["PATH"], "qemu-img") with open(bin_path, "w+") as f: @@ -60,7 +60,7 @@ def fake_qemu_binary(monkeypatch, tmpdir): monkeypatch.setenv("PATH", str(tmpdir)) if sys.platform.startswith("win"): - bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.exe") + bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.EXE") else: bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64") with open(bin_path, "w+") as f: From 997e0ad6ee821a1690bd445ef6068e9f775e4610 Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 10 Jan 2023 11:22:12 +0800 Subject: [PATCH 4/5] Fix more tests --- tests/compute/qemu/test_qemu_vm.py | 7 +++++-- tests/handlers/api/compute/test_nat.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 55e9e954..5465d720 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -60,7 +60,7 @@ def fake_qemu_binary(monkeypatch, tmpdir): monkeypatch.setenv("PATH", str(tmpdir)) if sys.platform.startswith("win"): - bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.EXE") + bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.exe") else: bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64") with open(bin_path, "w+") as f: @@ -859,7 +859,10 @@ def test_get_qemu_img(vm, tmpdir): open(str(tmpdir / "qemu-system-x86_64"), "w+").close() open(str(tmpdir / "qemu-img"), "w+").close() vm._qemu_path = str(tmpdir / "qemu-system-x86_64") - assert vm._get_qemu_img() == str(tmpdir / "qemu-img") + if sys.platform.startswith("win"): + assert vm._get_qemu_img() == str(tmpdir / "qemu-img.EXE") + else: + assert vm._get_qemu_img() == str(tmpdir / "qemu-img") # def test_get_qemu_img_not_exist(vm, tmpdir): diff --git a/tests/handlers/api/compute/test_nat.py b/tests/handlers/api/compute/test_nat.py index 425ed271..87bf4e75 100644 --- a/tests/handlers/api/compute/test_nat.py +++ b/tests/handlers/api/compute/test_nat.py @@ -74,9 +74,9 @@ async def test_nat_nio_update_udp(compute_api, vm): "rhost": "127.0.0.1" } - await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) + await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/1/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) params["filters"] = {} - response = await compute_api.put("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) + response = await compute_api.put("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/1/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) assert response.status == 201, response.body.decode() assert response.route == r"/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" From 5a3b502024b1f52a1464b3572d906610fe05f995 Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 10 Jan 2023 11:39:18 +0800 Subject: [PATCH 5/5] Fix NIO update UDP test --- tests/handlers/api/compute/test_nat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/handlers/api/compute/test_nat.py b/tests/handlers/api/compute/test_nat.py index 87bf4e75..6cfda85a 100644 --- a/tests/handlers/api/compute/test_nat.py +++ b/tests/handlers/api/compute/test_nat.py @@ -74,9 +74,11 @@ async def test_nat_nio_update_udp(compute_api, vm): "rhost": "127.0.0.1" } - await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/1/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) + with asyncio_patch("gns3server.compute.builtin.nodes.nat.Nat._start_ubridge"): + response = await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) + assert response.status == 201 params["filters"] = {} - response = await compute_api.put("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/1/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) + response = await compute_api.put("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), params) assert response.status == 201, response.body.decode() assert response.route == r"/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp"