Compare commits

...
85 Commits
Author SHA1 Message Date
grossmj 878987a26e Release v2.1.18 2019-05-22 16:13:28 +07:00
grossmj c357d52ba4 Revert "Force aiohttp version to 2.3.10 and aiohttp-cors version to 0.5.3"
Ref https://github.com/GNS3/gns3-server/issues/1583
Ref https://github.com/GNS3/gns3-server/issues/1592

This reverts commit 351ed64de9.
2019-05-20 17:23:26 +07:00
grossmj 773bad811a Fix invalid reStructuredText for long description in setup.py 2019-05-17 16:14:19 +07:00
grossmj 6b54cc27da Release v2.1.17 2019-05-17 15:10:28 +07:00
grossmj 351ed64de9 Force aiohttp version to 2.3.10 and aiohttp-cors version to 0.5.3
This is to fix build issue for Ubuntu 19.04 package on Launchpad.
Ref #1583 https://github.com/GNS3/gns3-gui/issues/2774
2019-05-17 09:56:16 +07:00
grossmj f41158173b Development on 2.1.17dev1 2019-04-15 12:41:40 +07:00
grossmj cb5dc36987 Release v2.1.16 2019-04-15 12:00:18 +07:00
grossmj cc1980ac1c Fix broken embedded console for Ethernet switch. Fixes #1574 2019-04-11 17:57:47 +07:00
grossmj 8cd66cfc02 Remove old unused argument option. Fixes #1569 2019-04-09 19:26:07 +07:00
grossmj 645031ee15 Development on 2.1.16dev1 2019-03-21 13:56:11 +08:00
grossmj c70b344133 Release v2.1.15 2019-03-21 11:41:44 +08:00
grossmj e291ec1eb9 Fix IOU symlink issue on remote servers. 2019-03-18 18:11:16 +07:00
grossmj 8e8985c69f Fix vcpus configuration for GNS3 VM on VMware. Ref #2738. 2019-03-18 17:53:14 +07:00
grossmj 4eca82174d Development on 2.1.15dev1 2019-02-27 15:59:16 +07:00
grossmj 32f5dbb645 Release v2.1.14 2019-02-27 14:58:52 +07:00
grossmj 7aae682f0a Fix issue when setting cpuid.corespersocket for the GNS3 VM. Fixes https://github.com/GNS3/gns3-gui/issues/2723 2019-02-27 14:47:45 +07:00
grossmj 879e32eb9a Bump ACPI Shutdown Timeout to 120 seconds. Ref #1536 2019-02-26 23:19:33 +07:00
grossmj 01481cde1f Development on 2.1.14dev1 2019-02-26 18:10:23 +07:00
grossmj b5deb9d177 Release v2.1.13 2019-02-26 16:46:02 +07:00
Jeremy Grossmann e1aa13fa73 Force jsonschema dependency to 2.6.0
This is to fix this issue when starting the (frozen) application on Windows:

```
  File "C:\Python36-x64\lib\site-packages\jsonschema\validators.py", line 505, in <module>
  File "C:\Python36-x64\lib\site-packages\jsonschema\_utils.py", line 57, in load_schema
  File "C:\Python36-x64\lib\pkgutil.py", line 634, in get_data
OSError: [Errno 34] Result too large: 'jsonschema\\schemas\\draft6.json'
```
2019-02-26 15:28:11 +07:00
grossmj 62c51edbae Less aggressive connections to uBridge. Ref #1289 2019-02-22 16:05:31 +07:00
grossmj a13d063aa1 Fix topology images (Pictures) disappearing from projects. Fixes #1514. 2019-02-21 23:58:54 +07:00
grossmj 1ef1872f8e Reset MAC addresses when duplicating a project. Fixes #1522 2019-02-20 16:38:43 +07:00
grossmj 657698a961 Fix create a node from an appliance test. 2019-02-20 11:21:29 +07:00
grossmj 081ba31b50 Fix API call to create a node from an appliance doesn't return the new node data. Fixes #1527 2019-02-20 10:47:33 +07:00
grossmj aea4ae808f Detect invalid environment variable and send a warning when creating a Docker node. Ref #2683 2019-02-19 17:34:10 +07:00
grossmj ae3515434c Do not export/import symlinks for projects. Fixes #2699 2019-02-19 12:43:44 +07:00
grossmj 589c9754e8 Fix symlink not being created for duplicated IOU devices. Fixes https://github.com/GNS3/gns3-gui/issues/2699 2019-02-19 00:09:59 +08:00
grossmj 4ecd3b2015 Configure coresPerSocket value in VMX file for the GNS3 VM. Fixes https://github.com/GNS3/gns3-gui/issues/2688 2019-02-17 23:16:48 +08:00
grossmj 84ee3263ba Count logical CPUs to detect if the number of vCPUs is too high when configuring the GNS3 VM. Fixes #2688. 2019-02-17 23:07:33 +08:00
grossmj 174624121d Fix Qemu VM tests. Ref #1516 2019-02-17 19:53:46 +08:00
grossmj d9a9abf845 Add explicit error when trying to pull a Docker image from Docker Hub without Internet access. Fixes #1506. 2019-02-17 19:21:21 +08:00
grossmj 0b07299472 Fixes double display output in GRUB in QEMU v3.1. Fixes #1516. 2019-02-17 19:03:36 +08:00
grossmj 7fb192699b Development on 2.1.13dev1 2019-01-23 15:42:10 +08:00
grossmj bccdfc97d1 Release 2.1.12 2019-01-23 15:40:38 +08:00
Jeremy Grossmann 792c4310eb Merge pull request #1502 from GNS3/svg-symbols-fixes
Tune how to get the size of SVG images.
2019-01-22 00:41:26 +07:00
grossmj 3e21f96bf9 Fix indentation issue. Ref https://github.com/GNS3/gns3-gui/issues/2674
(cherry picked from commit c14d79a3d5)
2019-01-21 23:51:46 +07:00
grossmj 5f932fee9f Tune how to get the size of SVG images. Ref https://github.com/GNS3/gns3-gui/issues/2674.
* Default for missing height/width is "100%" as defined in the SVG specification
* Better error message, if viewBox attribute is missing
* Removal of "%" in percent more fault tolerant by using rstrip("%")

(cherry picked from commit e3757a8955)
2019-01-21 23:49:43 +07:00
grossmj ef38ccfefa Automatically create a symbolic link to the IOU image in the IOU working directory. Fixes #1484 2018-12-17 22:42:18 -06:00
grossmj 670b6d689a Merge remote-tracking branch 'origin/2.1' into 2.1 2018-12-14 19:53:51 -06:00
grossmj fc75a6b8d3 Fix link pause/filters only work for the first interface of Docker containers. Fixes #1482 2018-12-14 19:53:43 -06:00
Jeremy Grossmann 647ac87c89 Merge pull request #1476 from ddragic/x11vnc
Docker: fix x11vnc not starting
2018-11-29 07:03:58 +07:00
Dušan Dragić 817a053dfc docker_vm: fix x11vnc not starting 2018-11-29 00:37:20 +01:00
Jeremy Grossmann df4e4bec24 Merge pull request #1472 from GNS3/docker-console-resize
Telnet console resize support for Docker VM. Fixes #1471
2018-11-27 15:17:34 +07:00
grossmj 60ac6d2dfe Telnet console resize support for Docker VM. 2018-11-27 15:06:56 +07:00
grossmj c0a0a13bdd Avoid _fix_permissions() to be called twice when stopping Docker VM. Ref #1428 2018-11-26 15:53:24 +07:00
grossmj a3044ede77 Fix _fix_permissions() garbles permissions in Docker VM. Ref #1428 2018-11-25 17:11:42 +07:00
grossmj df3baffd9b Fix "None is not of type 'integer'" when opening project containing a Qemu VM. Fixes #2610. 2018-11-24 19:56:29 +07:00
grossmj e7b8309a80 Fix Docker VNC tests. Ref #1438 2018-11-11 23:25:23 +08:00
grossmj 029344da14 Only require Xtigervnc or Xvfb+x11vnc for Docker with vnc console. Ref #1438 2018-11-11 22:33:58 +08:00
grossmj d0bab9947e Support tigervnc in Docker VM. Ref #1438 2018-11-11 21:07:33 +08:00
grossmj e4a6db8ebc Fix some typos. 2018-10-04 15:22:42 +02:00
grossmj 181a31be32 Update minimum VIX version requirements for VMware. Ref #1415. 2018-10-02 11:22:32 +02:00
grossmj 8d368cd0f6 Development on 2.1.12dev1 2018-09-28 20:50:03 +02:00
grossmj 41d4ecc4b7 Release v2.1.11 2018-09-28 20:47:44 +02:00
grossmj 4d95e0b51f Catch some exceptions. 2018-09-28 15:04:38 +02:00
grossmj 4efdefaf5a Development on 2.1.11dev1 2018-09-15 11:23:18 +02:00
grossmj b6b345508b Release v2.1.10 2018-09-15 11:19:55 +02:00
grossmj 5d2e539193 Update appliances. 2018-09-14 22:18:13 +02:00
grossmj eb0e26b55f Include locale information and GNS3 VM version in crash reports. 2018-09-12 15:38:20 +02:00
grossmj 17d657c919 Fix small errors like unhandled exceptions etc. 2018-09-11 15:06:01 +02:00
grossmj 0aa9ab53d1 Import encodings.idna to avoid LookupError when standard library is in a zip file. 2018-09-07 09:34:17 +02:00
grossmj 4021a13651 Catch exceptions in various locations to fix small issues reported by Sentry. 2018-09-06 09:49:12 +02:00
grossmj 341e2e2e3a Check if serial pipe can be opened for VMware and VirtualBox VMs. 2018-09-06 07:02:32 +02:00
grossmj f8ecd61a98 Notify users if xvfb process or x11vnc process have crashed. Ref #1401. 2018-09-05 15:16:07 +08:00
grossmj c620d0be84 Improve the invalid port format detection. Fixes https://github.com/GNS3/gns3-gui/issues/2580 2018-09-05 13:35:42 +08:00
grossmj abfbadecd6 Update aiohttp verion requirement in order to support Python 3.7. Fixes https://github.com/GNS3/gns3-gui/issues/2566 2018-09-02 20:41:45 +07:00
grossmj 4a6202fa84 Update setup.py and fix minor issues. 2018-09-02 15:32:33 +07:00
grossmj f89d645b56 Update appliances. 2018-08-31 19:33:03 +07:00
grossmj b7dd8b5176 Catch asyncio.CancelledError when shutting down the server. 2018-08-28 17:10:24 +07:00
grossmj 00cf66fb0f Report GNS3 VM errors to the GUI server summary. Ref #1359. 2018-08-28 15:42:06 +07:00
grossmj 8d4e73d23c Replace vboxnet0 (if it does not exist) by the first available vboxnet interface on Windows. Fixes https://github.com/GNS3/gns3-vm/issues/102 2018-08-26 03:28:38 -07:00
grossmj 4e712280b3 Merge remote-tracking branch 'origin/2.1' into 2.1 2018-08-26 02:44:01 -07:00
grossmj 4d57a3befa Check if the VirtualBox host-only network exists when starting a GNS3 VM running on VirtualBox. Ref https://github.com/GNS3/gns3-vm/issues/102 2018-08-26 02:43:40 -07:00
grossmj 38b72079b2 Change file timestamps if necessary because ZIP does not support timestamps before 1980. Fixes #1360. 2018-08-25 18:10:40 +07:00
grossmj 814526ba26 Add missing coroutine decorator Ref https://github.com/GNS3/gns3-gui/issues/2566 2018-08-25 16:00:40 +07:00
grossmj f5dc635baa Fix test to support Python 3.7 Ref https://github.com/GNS3/gns3-gui/issues/2566 2018-08-25 15:50:08 +07:00
grossmj 902de3dd47 Refactor asyncio locking system for Python 3.7 support. Ref https://github.com/GNS3/gns3-gui/issues/2566 Ref https://github.com/GNS3/gns3-gui/issues/2568 2018-08-25 14:10:47 +07:00
grossmj ad9b6f42bf Test with Python 3.7 on Travis. 2018-08-24 18:59:10 +07:00
grossmj 3560cda06c Use asyncio.ensure_future() instead of asyncio.async() with conservative approach to support Python < 3.4.4. Fixes https://github.com/GNS3/gns3-gui/issues/2566 2018-08-24 18:57:18 +07:00
grossmj a3d1e865a8 Replace asyncio.async() by asyncio.ensure_future() in tests. Ref #2566. 2018-08-24 18:52:15 +07:00
grossmj 089d25c79d Forbid controller and compute servers to be different versions.
Report last compute server error to clients and display in the server summary.
2018-08-22 16:54:43 +07:00
grossmj 59ce105a50 Fix exception with short names for Dynamips interfaces. Fixes #1386. 2018-08-21 19:46:14 +07:00
grossmj aeb33024ca Add missing Qemu boot priority values. Fixes https://github.com/GNS3/gns3-server/issues/1385 2018-08-21 17:49:58 +07:00
ziajka c593785c6d Development on 2.1.10dev1 2018-08-13 13:50:43 +02:00
106 changed files with 1300 additions and 529 deletions

No files matched your search

+1
View File
@@ -30,3 +30,4 @@ env:
- PYTHON_VERSION=3.4
- PYTHON_VERSION=3.5
- PYTHON_VERSION=3.6
- PYTHON_VERSION=3.7
+78 -1
View File
@@ -1,5 +1,82 @@
# Change Log
## 2.1.18 22/05/2019
* Revert "Force aiohttp version to 2.3.10 and aiohttp-cors version to 0.5.3" Ref https://github.com/GNS3/gns3-server/issues/1583 Ref https://github.com/GNS3/gns3-server/issues/1592
* Fix invalid reStructuredText for long description in setup.py
## 2.1.17 17/05/2019
* Force aiohttp version to 2.3.10 and aiohttp-cors version to 0.5.3 This is to fix build issue for Ubuntu 19.04 package on Launchpad. Ref #1583 https://github.com/GNS3/gns3-gui/issues/2774
## 2.1.16 15/04/2019
* Fix broken embedded console for Ethernet switch. Fixes #1574
* Remove old unused argument option. Fixes #1569
## 2.1.15 21/03/2019
* Fix IOU symlink issue on remote servers.
* Fix vcpus configuration for GNS3 VM on VMware. Ref #2738.
## 2.1.14 27/02/2019
* Fix issue when setting cpuid.corespersocket for the GNS3 VM. Fixes https://github.com/GNS3/gns3-gui/issues/2723
* Bump ACPI Shutdown Timeout to 120 seconds. Ref #1536
## 2.1.13 26/02/2019
* Force jsonschema dependency to 2.6.0
* Less aggressive connections to uBridge. Ref #1289
* Fix topology images (Pictures) disappearing from projects. Fixes #1514.
* Reset MAC addresses when duplicating a project. Fixes #1522
* Fix API call to create a node from an appliance doesn't return the new node data. Fixes #1527
* Detect invalid environment variable and send a warning when creating a Docker node. Ref #2683
* Do not export/import symlinks for projects. Fixes #2699
* Fix symlink not being created for duplicated IOU devices. Fixes https://github.com/GNS3/gns3-gui/issues/2699
* Configure coresPerSocket value in VMX file for the GNS3 VM. Fixes https://github.com/GNS3/gns3-gui/issues/2688
* Count logical CPUs to detect if the number of vCPUs is too high when configuring the GNS3 VM. Fixes #2688.
* Add explicit error when trying to pull a Docker image from Docker Hub without Internet access. Fixes #1506.
* Fixes double display output in GRUB in QEMU v3.1. Fixes #1516.
## 2.1.12 23/01/2019
* Tune how to get the size of SVG images. Ref https://github.com/GNS3/gns3-gui/issues/2674.
* Automatically create a symbolic link to the IOU image in the IOU working directory. Fixes #1484
* Fix link pause/filters only work for the first interface of Docker containers. Fixes #1482
* Telnet console resize support for Docker VM.
* Fix _fix_permissions() garbles permissions in Docker VM. Ref #1428
* Fix "None is not of type 'integer'" when opening project containing a Qemu VM. Fixes #2610.
* Only require Xtigervnc or Xvfb+x11vnc for Docker with vnc console. Ref #1438
* Support tigervnc in Docker VM. Ref #1438
* Update minimum VIX version requirements for VMware. Ref #1415.
## 2.1.11 28/09/2018
* Catch some exceptions.
## 2.1.10 15/09/2018
* Include locale information and GNS3 VM version in crash reports.
* Fix small errors like unhandled exceptions etc.
* Import encodings.idna to avoid LookupError when standard library is in a zip file.
* Catch exceptions in various locations to fix small issues reported by Sentry.
* Check if serial pipe can be opened for VMware and VirtualBox VMs.
* Improve the invalid port format detection. Fixes https://github.com/GNS3/gns3-gui/issues/2580
* Update aiohttp verion requirement in order to support Python 3.7. Fixes https://github.com/GNS3/gns3-gui/issues/2566
* Update setup.py and fix minor issues.
* Catch asyncio.CancelledError when shutting down the server.
* Report GNS3 VM errors to the GUI server summary. Ref #1359.
* Replace vboxnet0 (if it does not exist) by the first available vboxnet interface on Windows. Fixes https://github.com/GNS3/gns3-vm/issues/102
* Check if the VirtualBox host-only network exists when starting a GNS3 VM running on VirtualBox. Ref https://github.com/GNS3/gns3-vm/issues/102
* Change file timestamps if necessary because ZIP does not support timestamps before 1980. Fixes #1360.
* Add missing coroutine decorator Ref https://github.com/GNS3/gns3-gui/issues/2566
* Refactor asyncio locking system for Python 3.7 support. Ref https://github.com/GNS3/gns3-gui/issues/2566 Ref https://github.com/GNS3/gns3-gui/issues/2568
* Use asyncio.ensure_future() instead of asyncio.async() with conservative approach to support Python < 3.4.4. Fixes https://github.com/GNS3/gns3-gui/issues/2566
* Forbid controller and compute servers to be different versions. Report last compute server error to clients and display in the server summary.
* Fix exception with short names for Dynamips interfaces. Fixes #1386.
* Add missing Qemu boot priority values. Fixes https://github.com/GNS3/gns3-server/issues/1385
## 2.1.9 13/08/2018
* Fix some more problems with interface short names. Fixes https://github.com/GNS3/gns3-gui/issues/2562
@@ -655,7 +732,7 @@
* Fix naming of IOU serial interfaces
* Improve timeout management
* When exporting debug information export GNS3 VM vmx content
* /debug for exporting debug informations
* /debug for exporting debug information
* Raise error if using a non linked clone VM twice
* Fix a possible deadlock at exit
* Fix import of some old dynamips topologies
+5 -4
View File
@@ -23,7 +23,7 @@ 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.1 for example)
********
*********************
Next major release
*Never* use this branch for production. Pull requests for major new features go here.
@@ -100,7 +100,7 @@ All the init script require the creation of a GNS3 user. You can change it to an
sudo adduser gns3
upstart
~~~~~~~
-------
For ubuntu < 15.04
@@ -113,7 +113,8 @@ You need to copy init/gns3.conf.upstart to /etc/init/gns3.conf
systemd
~~~~~~~~
-------
You need to copy init/gns3.service.systemd to /lib/systemd/system/gns3.service
.. code:: bash
@@ -219,5 +220,5 @@ If you want test coverage:
Security issues
----------------
Please contact us using contact informations available here:
Please contact us using contact form available here:
http://docs.gns3.com/1ON9JBXSeR7Nt2-Qum2o3ZX0GU86BZwlmNSUgvmqNWGY/index.html
+1 -1
View File
@@ -5,7 +5,7 @@
GET /v2/compute/debug
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Return debug informations about the compute
Return debug information about the compute
Response status codes
**********************
+19
View File
@@ -0,0 +1,19 @@
{
"name": "cEOS",
"category": "multilayer_switch",
"description": "Arista cEOS\u2122 introduces the containerized packaging of EOS software and its agents for deployment in cloud infrastructure with the same proven EOS software image that runs on all Arista products. These flexible deployment options empower cloud network operators that are customizing their operating environments to provide a uniform workflow for development, testing and deployment of differentiated services.",
"vendor_name": "Arista",
"vendor_url": "http://www.arista.com/",
"product_name": "cEOS",
"registry_version": 3,
"status": "experimental",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",
"usage": "Download:\nCreate a (free) Arista account and login.\nThen navigate to Support / Software Download and download the cEOS-lab image.\n\nInstallation:\nCopy the image to your GNS3VM (or other Linux) server, then run the following commands:\n\ndocker import cEOS-lab.tar.xz ceosimage:4.20.5F\necho \"rm /etc/systemd/system/getty.target.wants/getty@tty1.service\" | \\\ndocker run --name=ceos-container -e CEOS=1 -e container=docker -e EOS_PLATFORM=ceossim -e SKIP_ZEROTOUCH_BARRIER_IN_SYSDBINIT=1 -e ETBA=1 -e INTFTYPE=eth -i ceosimage:4.20.5F sh\ndocker commit --change='CMD [\"/sbin/init\"]' --change='VOLUME /mnt/flash' ceos-container ceosimage:GNS3\ndocker rm ceos-container\n\nUsage:\nThe login is admin, with no password by default",
"symbol": ":/symbols/multilayer_switch.svg",
"docker": {
"adapters": 8,
"image": "ceosimage:GNS3",
"console_type": "telnet"
}
}
+15
View File
@@ -19,6 +19,15 @@
"kvm": "allow"
},
"images": [
{
"filename": "BSDRP-1.90-full-amd64-serial.img",
"version": "1.90",
"md5sum": "78b7182bed93888d17d18a67d5fec3a7",
"filesize": 1000000000,
"download_url": "https://bsdrp.net/downloads",
"direct_download_url": "https://sourceforge.net/projects/bsdrp/files/BSD_Router_Project/1.90/amd64/BSDRP-1.90-full-amd64-serial.img.xz/download",
"compression": "xz"
},
{
"filename": "BSDRP-1.80-full-amd64-serial.img",
"version": "1.80",
@@ -39,6 +48,12 @@
}
],
"versions": [
{
"name": "1.90",
"images": {
"hda_disk_image": "BSDRP-1.90-full-amd64-serial.img"
}
},
{
"name": "1.80",
"images": {
+13
View File
@@ -25,6 +25,13 @@
"kvm": "require"
},
"images": [
{
"filename": "asav992.qcow2",
"version": "9.9.2",
"md5sum": "0cba453dbf70313d8d63a00700618f52",
"filesize": 204865536,
"download_url": "https://software.cisco.com/download/home/286119613/type/280775065/release/9.9.2"
},
{
"filename": "asav983.qcow2",
"version": "9.8.3",
@@ -104,6 +111,12 @@
}
],
"versions": [
{
"name": "9.9.2",
"images": {
"hda_disk_image": "asav992.qcow2"
}
},
{
"name": "9.8.3",
"images": {
+29 -4
View File
@@ -11,19 +11,32 @@
"status": "experimental",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",
"usage": "Default username/password: admin/admin, cisco/cisco and lab/lab. There is no default configuration present.",
"usage": "Default username/password: admin/admin, cisco/cisco and lab/lab. There is no default configuration present. Interfaces may take several minutes to be usable after appliance boot.",
"first_port_name": "MgmtEth0/0/CPU0/0",
"port_name_format": "GigabitEthernet0/0/0/{0}",
"qemu": {
"adapter_type": "e1000",
"adapters": 4,
"adapter_type": "virtio-net-pci",
"adapters": 7,
"ram": 16384,
"arch": "x86_64",
"console_type": "telnet",
"kvm": "require",
"options": "-smp 4"
"options": "-smp 4 -cpu host"
},
"images": [
{
"filename": "xrv9k-fullk9-x-6.4.2.qcow2",
"version": "6.4.2",
"md5sum": "6958763192c7bb59a1b8049d377de1b4",
"filesize": 1311703040,
"download_url": "https://software.cisco.com/download/home/286288939/type/280805694/release/6.4.2"
},
{ "filename": "xrv9k-fullk9-x-6.4.1.qcow2",
"version": "6.4.1",
"md5sum": "9c56b684e307706005a503e289cb9317",
"filesize": 1304887296,
"download_url": "https://software.cisco.com/download/home/286288939/type/280805694/release/6.4.1"
},
{
"filename": "xrv9k-fullk9-x-6.2.25.qcow2",
"version": "6.2.25",
@@ -47,6 +60,18 @@
}
],
"versions": [
{
"name": "6.4.2",
"images": {
"hda_disk_image": "xrv9k-fullk9-x-6.4.2.qcow2"
}
},
{
"name": "6.4.1",
"images": {
"hda_disk_image": "xrv9k-fullk9-x-6.4.1.qcow2"
}
},
{
"name": "6.2.25",
"images": {
+14
View File
@@ -25,6 +25,13 @@
"kvm": "require"
},
"images": [
{
"filename": "nxosv-final.9.2.1.qcow2",
"version": "9.2.1",
"md5sum": "1d7fa4654602d7ffbf62544edfe71986",
"filesize": 1330315264,
"download_url": "https://software.cisco.com/download/home/286312239/type/282088129/release/9.2%25281%2529"
},
{
"filename": "nxosv-final.7.0.3.I7.4.qcow2",
"version": "7.0.3.I7.4",
@@ -85,6 +92,13 @@
}
],
"versions": [
{
"name": "9.2.1",
"images": {
"bios_image": "OVMF-20160813.fd",
"hda_disk_image": "nxosv-final.9.2.1.qcow2"
}
},
{
"name": "7.0.3.I7.4",
"images": {
+14
View File
@@ -23,6 +23,14 @@
"kvm": "require"
},
"images": [
{
"filename": "cumulus-linux-3.6.2-vx-amd64.qcow2",
"version": "3.6.2",
"md5sum": "02b0621d68fb2e709b4bcc48748c7b6f",
"filesize": 1150746624,
"download_url": "https://cumulusnetworks.com/cumulus-vx/download/",
"direct_download_url": "https://s3.amazonaws.com/cumulusfiles/CumulusLinux-3.6.2/cumulus-linux-3.6.2-vx-amd64.qcow2"
},
{
"filename": "cumulus-linux-3.6.1-vx-amd64.qcow2",
"version": "3.6.1",
@@ -165,6 +173,12 @@
}
],
"versions": [
{
"name": "3.6.2",
"images": {
"hda_disk_image": "cumulus-linux-3.6.2-vx-amd64.qcow2"
}
},
{
"name": "3.6.1",
"images": {
+15
View File
@@ -26,6 +26,14 @@
"options": "-smp 2 -cpu core2duo"
},
"images": [
{
"filename": "exosvm-22.5.1.7.iso",
"version": "22.5.1.7",
"md5sum": "132ac87de368ab55d1f496f292338cd4",
"filesize": 51779584,
"download_url": "https://github.com/extremenetworks/Virtual_EXOS",
"direct_download_url": "https://github.com/extremenetworks/Virtual_EXOS/raw/master/vm-22.5.1.7.iso"
},
{
"filename": "exosvm-22.4.1.4.iso",
"version": "22.4.1.4",
@@ -100,6 +108,13 @@
}
],
"versions": [
{
"name": "22.5.1.7",
"images": {
"hda_disk_image": "empty8G.qcow2",
"cdrom_image": "exosvm-22.5.1.7.iso"
}
},
{
"name": "22.4.1.4",
"images": {
@@ -0,0 +1,64 @@
{
"name": "VOSS VM",
"category": "multilayer_switch",
"description": "The VOSS VM is a software emulation of a VSP8K switch.",
"vendor_name": "Extreme Networks",
"vendor_url": "http://www.extremenetworks.com",
"documentation_url": "http://www.extremenetworks.com/support/documentation",
"product_name": "VOSS_VM",
"registry_version": 3,
"status": "experimental",
"maintainer": "Extreme Networks",
"maintainer_email": "voss@extremenetworks.com",
"usage": "Boot up and login is rwa/rwa",
"symbol": "ethernet_switch.svg",
"first_port_name": "Mgmt",
"port_name_format": "1/{port1}",
"qemu":
{
"adapter_type": "e1000",
"adapters": 9,
"ram": 1024,
"hda_disk_interface": "ide",
"arch": "i386",
"console_type": "telnet",
"kvm": "allow",
"options": "-nographic"
},
"images":
[
{
"filename": "VOSSGNS3.7.1.0.0.qcow2",
"version": "voss_7.1.0.0",
"md5sum": "7bb2974efe1a1ab857debd9fa894dbe7",
"filesize": 193724416,
"direct_download_url": "https://stackingtool.extremenetworks.com/github/VOSSGNS3.7.1.0.0.qcow2"
},
{
"filename": "VOSSGNS3.7.0.0.0.img",
"version": "voss_7.0.0.0",
"md5sum": "65fe97461156aa88c836a90be1287649",
"filesize": 419430400,
"direct_download_url": "https://stackingtool.extremenetworks.com/github/VOSSGNS3.7.0.0.0.img"
}
],
"versions":
[
{
"name": "7.1.0.0",
"images":
{
"hda_disk_image": "VOSSGNS3.7.1.0.0.qcow2"
}
},
{
"name": "7.0.0.0",
"images": {
"hda_disk_image": "VOSSGNS3.7.0.0.0.img"
}
}
]
}
+14
View File
@@ -29,6 +29,13 @@
"options": "-smp 2 -cpu host"
},
"images": [
{
"filename": "BIG-IQ-5.4.0.2.24.7467.qcow2",
"version": "5.4.0.2",
"md5sum": "e3e6389438ba1e1676f507658f767e95",
"filesize": 3480748032,
"download_url": "https://downloads.f5.com/esd/serveDownload.jsp?path=/big-iq/big-iq_cm/5.4.0/english/virtual-edition_base-plus-hf2/&sw=BIG-IQ&pro=big-iq_CM&ver=5.4.0&container=Virtual-Edition_Base-Plus-HF2&file=BIG-IQ-5.4.0.2.24.7467.qcow2.zip"
},
{
"filename": "BIG-IQ-5.4.0.0.0.7437.qcow2",
"version": "5.4.0",
@@ -81,6 +88,13 @@
}
],
"versions": [
{
"name": "5.4.0.2",
"images": {
"hda_disk_image": "BIG-IQ-5.4.0.2.24.7467.qcow2",
"hdb_disk_image": "empty100G.qcow2"
}
},
{
"name": "5.4.0",
"images": {
+14 -1
View File
@@ -20,6 +20,14 @@
"kvm": "require"
},
"images": [
{
"filename": "kali-linux-2018.3-amd64.iso",
"version": "2018.3",
"md5sum": "6dc3e57177249f73492b9edb95d082d1",
"filesize": 3188391936,
"download_url": "https://www.kali.org/downloads/",
"direct_download_url": "http://cdimage.kali.org/kali-2018.3/kali-linux-2018.3-amd64.iso"
},
{
"filename": "kali-linux-2018.1-amd64.iso",
"version": "2018.1",
@@ -79,7 +87,12 @@
],
"versions": [
{
"name": "2018.8",
"name": "2018.3",
"images": {
"cdrom_image": "kali-linux-2018.3-amd64.iso"
}
}, {
"name": "2018.1",
"images": {
"cdrom_image": "kali-linux-2018.1-amd64.iso"
}
-1
View File
@@ -17,7 +17,6 @@
"ram": 2048,
"arch": "x86_64",
"console_type": "telnet",
"boot_priority": "dc",
"kvm": "allow",
"process_priority": "normal"
},
+43
View File
@@ -0,0 +1,43 @@
{
"name": "TacacsGUI",
"category": "guest",
"description": "TacacsGUI Free Access Control Server for Your Network Devices. GUI for powerful daemon. The project of Alexey Mochalin, based on tacacs daemon by Marc Huber",
"vendor_name": "TacacsGUI",
"vendor_url": "https://tacacsgui.com/",
"documentation_url": "https://tacacsgui.com/documentation/",
"product_name": "TacacsGUI",
"product_url": "https://drive.google.com/open?id=1U8tbj14NqEyCmarayhZm54qTyjgsJm4B",
"registry_version": 3,
"status": "stable",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",
"usage": "Credentials: SSH ---> username: root ---> password: 1234 MySQL DB: ---> username: root --> password: tacacs Web interface: ---> username: tacgui ---> password: abc123",
"port_name_format": "Port{port1}",
"qemu": {
"adapter_type": "e1000",
"adapters": 1,
"ram": 1024,
"hda_disk_interface": "ide",
"arch": "x86_64",
"console_type": "telnet",
"boot_priority": "c",
"kvm": "allow"
},
"images": [
{
"filename": "tac_plus.qcow2",
"version": "201710201114",
"md5sum": "6b5e66590051124dae586b8640b2eb11",
"filesize": 160301056,
"download_url": "https://drive.google.com/open?id=1U8tbj14NqEyCmarayhZm54qTyjgsJm4B"
}
],
"versions": [
{
"name": "201710201114",
"images": {
"hda_disk_image": "tac_plus.qcow2"
}
}
]
}
+3 -2
View File
@@ -30,6 +30,7 @@ log = logging.getLogger(__name__)
from uuid import UUID, uuid4
from gns3server.utils.interfaces import is_interface_up
from gns3server.utils.asyncio import asyncio_ensure_future
from ..config import Config
from ..utils.asyncio import wait_run_in_executor
from ..utils import force_unix_path
@@ -127,7 +128,7 @@ class BaseManager:
tasks = []
for node_id in self._nodes.keys():
tasks.append(asyncio.async(self.close_node(node_id)))
tasks.append(asyncio_ensure_future(self.close_node(node_id)))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -275,7 +276,7 @@ class BaseManager:
destination_dir = destination_node.working_dir
try:
shutil.rmtree(destination_dir)
shutil.copytree(source_node.working_dir, destination_dir)
shutil.copytree(source_node.working_dir, destination_dir, symlinks=True, ignore_dangling_symlinks=True)
except OSError as e:
raise aiohttp.web.HTTPConflict(text="Can't duplicate node data: {}".format(e))
+3 -2
View File
@@ -29,7 +29,7 @@ import re
from gns3server.utils.interfaces import interfaces
from ..compute.port_manager import PortManager
from ..utils.asyncio import wait_run_in_executor, locked_coroutine
from ..utils.asyncio import wait_run_in_executor, locking
from ..utils.asyncio.telnet_server import AsyncioTelnetServer
from ..ubridge.hypervisor import Hypervisor
from ..ubridge.ubridge_error import UbridgeError
@@ -516,7 +516,8 @@ class BaseNode:
except UbridgeError as e:
raise UbridgeError("Error while sending command '{}': {}: {}".format(command, e, self._ubridge_hypervisor.read_stdout()))
@locked_coroutine
@locking
@asyncio.coroutine
def _start_ubridge(self):
"""
Starts uBridge (handles connections to and from this node).
+1 -1
View File
@@ -163,7 +163,7 @@ class Cloud(BaseNode):
try:
output = yield from gns3server.utils.asyncio.subprocess_check_output("networksetup", "-listallhardwareports")
except (FileNotFoundError, subprocess.SubprocessError) as e:
except (OSError, subprocess.SubprocessError) as e:
log.warn("Could not execute networksetup: {}".format(e))
return False
+7 -3
View File
@@ -25,7 +25,7 @@ import asyncio
import logging
import aiohttp
from gns3server.utils import parse_version
from gns3server.utils.asyncio import locked_coroutine
from gns3server.utils.asyncio import locking
from gns3server.compute.base_manager import BaseManager
from gns3server.compute.docker.docker_vm import DockerVM
from gns3server.compute.docker.docker_error import DockerError, DockerHttp304Error, DockerHttp404Error
@@ -182,7 +182,8 @@ class Docker(BaseManager):
autoping=True)
return connection
@locked_coroutine
@locking
@asyncio.coroutine
def pull_image(self, image, progress_callback=None):
"""
Pull image from docker repository
@@ -199,7 +200,10 @@ class Docker(BaseManager):
if progress_callback:
progress_callback("Pulling '{}' from docker hub".format(image))
response = yield from self.http_query("POST", "images/create", params={"fromImage": image}, timeout=None)
try:
response = yield from self.http_query("POST", "images/create", params={"fromImage": image}, timeout=None)
except DockerError as e:
raise DockerError("Could not pull the '{}' image from Docker Hub, please check your Internet connection (original error: {})".format(image, e))
# The pull api will stream status via an HTTP JSON stream
content = ""
while True:
+122 -46
View File
@@ -24,11 +24,14 @@ import shutil
import psutil
import shlex
import aiohttp
import subprocess
import os
from gns3server.utils.asyncio.telnet_server import AsyncioTelnetServer
from gns3server.utils.asyncio.raw_command_server import AsyncioRawCommandServer
from gns3server.utils.asyncio import wait_for_file_creation
from gns3server.utils.asyncio import asyncio_ensure_future
from gns3server.utils.asyncio import monitor_process
from gns3server.utils.get_resource import get_resource
from gns3server.ubridge.ubridge_error import UbridgeError, UbridgeNamespaceError
@@ -80,12 +83,14 @@ class DockerVM(BaseNode):
self._ethernet_adapters = []
self._temporary_directory = None
self._telnet_servers = []
self._x11vnc_process = None
self._vnc_process = None
self._xvfb_process = None
self._console_resolution = console_resolution
self._console_http_path = console_http_path
self._console_http_port = console_http_port
self._console_websocket = None
self._extra_hosts = extra_hosts
self._permissions_fixed = False
self._volumes = []
# Keep a list of created bridge
@@ -226,11 +231,13 @@ class DockerVM(BaseNode):
binds = ["{}:/gns3:ro".format(ressources)]
# We mount our own etc/network
network_config = self._create_network_config()
try:
network_config = self._create_network_config()
except OSError as e:
raise DockerError("Could not create network config in the container: {}".format(e))
binds.append("{}:/gns3volumes/etc/network:rw".format(network_config))
self._volumes = ["/etc/network"]
volumes = image_infos.get("Config", {}).get("Volumes")
if volumes is None:
return binds
@@ -283,11 +290,12 @@ class DockerVM(BaseNode):
try:
image_infos = yield from self._get_image_information()
except DockerHttp404Error:
log.info("Image %s is missing pulling it from docker hub", self._image)
log.info("Image '{}' is missing, pulling it from Docker hub...".format(self._image))
yield from self.pull_image(self._image)
image_infos = yield from self._get_image_information()
if image_infos is None:
raise DockerError("Can't get image informations, please try again.")
if image_infos is None:
raise DockerError("Cannot get information for image '{}', please try again.".format(self._image))
params = {
"Hostname": self._name,
@@ -311,7 +319,10 @@ class DockerVM(BaseNode):
if params["Entrypoint"] is None:
params["Entrypoint"] = []
if self._start_command:
params["Cmd"] = shlex.split(self._start_command)
try:
params["Cmd"] = shlex.split(self._start_command)
except ValueError as e:
raise DockerError("Invalid start command '{}': {}".format(self._start_command, e))
if len(params["Cmd"]) == 0:
params["Cmd"] = image_infos.get("Config", {"Cmd": []})["Cmd"]
if params["Cmd"] is None:
@@ -336,6 +347,9 @@ class DockerVM(BaseNode):
if self._environment:
for e in self._environment.strip().split("\n"):
e = e.strip()
if e.split("=")[0] == "":
self.project.emit("log.warning", {"message": "{} has invalid environment variable: {}".format(self.name, e)})
continue
if not e.startswith("GNS3_"):
formatted = self._format_env(variables, e)
params["Env"].append(formatted)
@@ -353,8 +367,7 @@ class DockerVM(BaseNode):
result = yield from self.manager.query("POST", "containers/create", data=params)
self._cid = result['Id']
log.info("Docker container '{name}' [{id}] created".format(
name=self._name, id=self._id))
log.info("Docker container '{name}' [{id}] created".format(name=self._name, id=self._id))
return True
def _format_env(self, variables, env):
@@ -432,12 +445,14 @@ class DockerVM(BaseNode):
if self.console_type == "telnet":
yield from self._start_console()
elif self.console_type == "http" or self.console_type == "https":
yield from self._start_http()
if self.allocate_aux:
yield from self._start_aux()
self._permissions_fixed = False
self.status = "started"
log.info("Docker container '{name}' [{image}] started listen for {console_type} on {console}".format(name=self._name,
image=self._image,
@@ -447,22 +462,24 @@ class DockerVM(BaseNode):
@asyncio.coroutine
def _start_aux(self):
"""
Start an auxilary console
Start an auxiliary console
"""
# We can not use the API because docker doesn't expose a websocket api for exec
# https://github.com/GNS3/gns3-gui/issues/1039
process = yield from asyncio.subprocess.create_subprocess_exec(
"docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "while true; do TERM=vt100 /gns3/bin/busybox sh; done", "/dev/null",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)
try:
process = yield from asyncio.subprocess.create_subprocess_exec("docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "while true; do TERM=vt100 /gns3/bin/busybox sh; done", "/dev/null",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)
except OSError as e:
raise DockerError("Could not start auxiliary console process: {}".format(e))
server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=True, echo=True)
try:
self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.aux)))
except OSError as e:
raise DockerError("Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.aux, e))
log.debug("Docker container '%s' started listen for auxilary telnet on %d", self.name, self.aux)
log.debug("Docker container '%s' started listen for auxiliary telnet on %d", self.name, self.aux)
@asyncio.coroutine
def _fix_permissions(self):
@@ -472,6 +489,7 @@ class DockerVM(BaseNode):
"""
state = yield from self._get_container_state()
log.info("Docker container '{name}' fix ownership, state = {state}".format(name=self._name, state=state))
if state == "stopped" or state == "exited":
# We need to restart it to fix permissions
yield from self.manager.query("POST", "containers/{}/start".format(self._cid))
@@ -479,22 +497,27 @@ class DockerVM(BaseNode):
for volume in self._volumes:
log.debug("Docker container '{name}' [{image}] fix ownership on {path}".format(
name=self._name, image=self._image, path=volume))
process = yield from asyncio.subprocess.create_subprocess_exec(
"docker",
"exec",
self._cid,
"/gns3/bin/busybox",
"sh",
"-c",
"("
"/gns3/bin/busybox find \"{path}\" -depth -print0"
" | /gns3/bin/busybox xargs -0 /gns3/bin/busybox stat -c '%a:%u:%g:%n' > \"{path}/.gns3_perms\""
")"
" && /gns3/bin/busybox chmod -R u+rX \"{path}\""
" && /gns3/bin/busybox chown {uid}:{gid} -R \"{path}\""
.format(uid=os.getuid(), gid=os.getgid(), path=volume),
)
try:
process = yield from asyncio.subprocess.create_subprocess_exec(
"docker",
"exec",
self._cid,
"/gns3/bin/busybox",
"sh",
"-c",
"("
"/gns3/bin/busybox find \"{path}\" -depth -print0"
" | /gns3/bin/busybox xargs -0 /gns3/bin/busybox stat -c '%a:%u:%g:%n' > \"{path}/.gns3_perms\""
")"
" && /gns3/bin/busybox chmod -R u+rX \"{path}\""
" && /gns3/bin/busybox chown {uid}:{gid} -R \"{path}\""
.format(uid=os.getuid(), gid=os.getgid(), path=volume),
)
except OSError as e:
raise DockerError("Could not fix permissions for {}: {}".format(volume, e))
yield from process.wait()
self._permissions_fixed = True
@asyncio.coroutine
def _start_vnc(self):
@@ -503,14 +526,54 @@ class DockerVM(BaseNode):
"""
self._display = self._get_free_display_port()
if shutil.which("Xvfb") is None or shutil.which("x11vnc") is None:
raise DockerError("Please install Xvfb and x11vnc before using the VNC support")
self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb", "-nolisten", "tcp", ":{}".format(self._display), "-screen", "0", self._console_resolution + "x16")
# We pass a port for TCPV6 due to a crash in X11VNC if not here: https://github.com/GNS3/gns3-server/issues/569
self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-rfbportv6", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host)
if not (shutil.which("Xtigervnc") or shutil.which("Xvfb") and shutil.which("x11vnc")):
raise DockerError("Please install tigervnc-standalone-server (recommended) or Xvfb + x11vnc before using VNC support")
if shutil.which("Xtigervnc"):
with open(os.path.join(self.working_dir, "vnc.log"), "w") as fd:
self._vnc_process = yield from asyncio.create_subprocess_exec("Xtigervnc",
"-geometry", self._console_resolution,
"-depth", "16",
"-interface", self._manager.port_manager.console_host,
"-rfbport", str(self.console),
"-AlwaysShared",
"-SecurityTypes", "None",
":{}".format(self._display),
stdout=fd, stderr=subprocess.STDOUT)
else:
self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb",
"-nolisten",
"tcp", ":{}".format(self._display),
"-screen", "0",
self._console_resolution + "x16")
# We pass a port for TCPV6 due to a crash in X11VNC if not here: https://github.com/GNS3/gns3-server/issues/569
with open(os.path.join(self.working_dir, "vnc.log"), "w") as fd:
self._vnc_process = yield from asyncio.create_subprocess_exec("x11vnc",
"-forever",
"-nopw",
"-shared",
"-geometry", self._console_resolution,
"-display", "WAIT:{}".format(self._display),
"-rfbport", str(self.console),
"-rfbportv6", str(self.console),
"-noncache",
"-listen", self._manager.port_manager.console_host,
stdout=fd, stderr=subprocess.STDOUT)
x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
yield from wait_for_file_creation(x11_socket)
#monitor_process(self._vnc_process, self._vnc_callback)
def _vnc_callback(self, returncode):
"""
Called when the process has stopped.
:param returncode: Process returncode
"""
if returncode != 0:
self.project.emit("log.error", {"message": "The vnc process has stopped, return code: {}.".format(returncode)})
@asyncio.coroutine
def _start_http(self):
@@ -533,6 +596,19 @@ class DockerVM(BaseNode):
])
self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)))
@asyncio.coroutine
def _window_size_changed_callback(self, columns, rows):
"""
Called when the console window size has been changed.
(when naws is enabled in the Telnet server)
:param columns: number of columns
:param rows: number of rows
"""
# resize the container TTY.
yield from self._manager.query("POST", "containers/{}/resize?h={}&w={}".format(self._cid, rows, columns))
@asyncio.coroutine
def _start_console(self):
"""
@@ -555,8 +631,7 @@ class DockerVM(BaseNode):
output_stream = asyncio.StreamReader()
input_stream = InputStream()
telnet = AsyncioTelnetServer(reader=output_stream, writer=input_stream, echo=True)
telnet = AsyncioTelnetServer(reader=output_stream, writer=input_stream, echo=True, naws=True, window_size_changed_callback=self._window_size_changed_callback)
try:
self._telnet_servers.append((yield from asyncio.start_server(telnet.run, self._manager.port_manager.console_host, self.console)))
except OSError as e:
@@ -566,8 +641,7 @@ class DockerVM(BaseNode):
input_stream.ws = self._console_websocket
output_stream.feed_data(self.name.encode() + b" console is now available... Press RETURN to get started.\r\n")
asyncio.async(self._read_console_output(self._console_websocket, output_stream))
asyncio_ensure_future(self._read_console_output(self._console_websocket, output_stream))
@asyncio.coroutine
def _read_console_output(self, ws, out):
@@ -641,14 +715,15 @@ class DockerVM(BaseNode):
if state == "paused":
yield from self.unpause()
yield from self._fix_permissions()
if not self._permissions_fixed:
yield from self._fix_permissions()
state = yield from self._get_container_state()
if state != "stopped" or state != "exited":
# t=5 number of seconds to wait before killing the container
try:
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
log.info("Docker container '{name}' [{image}] stopped".format(
name=self._name, image=self._image))
log.info("Docker container '{name}' [{image}] stopped".format(name=self._name, image=self._image))
except DockerHttp304Error:
# Container is already stopped
pass
@@ -688,12 +763,13 @@ class DockerVM(BaseNode):
if state == "paused" or state == "running":
yield from self.stop()
if self.console_type == "vnc":
if self._x11vnc_process:
if self._vnc_process:
try:
self._x11vnc_process.terminate()
yield from self._x11vnc_process.wait()
self._vnc_process.terminate()
yield from self._vnc_process.wait()
except ProcessLookupError:
pass
if self._xvfb_process:
try:
self._xvfb_process.terminate()
yield from self._xvfb_process.wait()
+3 -2
View File
@@ -36,6 +36,7 @@ log = logging.getLogger(__name__)
from gns3server.utils.interfaces import interfaces, is_interface_up
from gns3server.utils.asyncio import wait_run_in_executor
from gns3server.utils import parse_version
from gns3server.utils.asyncio import asyncio_ensure_future
from uuid import uuid4
from ..base_manager import BaseManager
from ..port_manager import PortManager
@@ -172,7 +173,7 @@ class Dynamips(BaseManager):
tasks = []
for device in self._devices.values():
tasks.append(asyncio.async(device.hypervisor.stop()))
tasks.append(asyncio_ensure_future(device.hypervisor.stop()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -196,7 +197,7 @@ class Dynamips(BaseManager):
tasks = []
for device in self._devices.values():
if device.project.id == project.id:
tasks.append(asyncio.async(device.delete()))
tasks.append(asyncio_ensure_future(device.delete()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -87,6 +87,7 @@ class EthernetSwitch(Device):
self._mappings = {}
self._telnet_console = None
self._telnet_shell = None
self._telnet_server = None
self._console = self._manager.port_manager.get_free_tcp_port(self._project)
if ports is None:
# create 8 ports by default
@@ -217,8 +218,9 @@ class EthernetSwitch(Device):
Deletes this Ethernet switch.
"""
yield from self._telnet.close()
self._telnet_server.close()
if self._telnet_server:
self._telnet_server.close()
for nio in self._nios.values():
if nio:
yield from nio.close()
+2 -2
View File
@@ -40,7 +40,7 @@ from ..nios.nio_udp import NIOUDP
from gns3server.utils.file_watcher import FileWatcher
from gns3server.utils.asyncio import wait_run_in_executor, monitor_process
from gns3server.utils.asyncio import wait_run_in_executor, monitor_process, asyncio_ensure_future
from gns3server.utils.images import md5sum
@@ -196,7 +196,7 @@ class Router(BaseNode):
"""
Called when the NVRAM file has changed
"""
asyncio.async(self.save_configs())
asyncio_ensure_future(self.save_configs())
@property
def dynamips_id(self):
+23 -4
View File
@@ -43,7 +43,7 @@ from .utils.iou_export import nvram_export
from gns3server.ubridge.ubridge_error import UbridgeError
from gns3server.utils.file_watcher import FileWatcher
from gns3server.utils.asyncio.telnet_server import AsyncioTelnetServer
from gns3server.utils.asyncio import locked_coroutine
from gns3server.utils.asyncio import locking
import gns3server.utils.asyncio
import gns3server.utils.images
@@ -368,7 +368,7 @@ class IOUVM(BaseNode):
try:
output = yield from gns3server.utils.asyncio.subprocess_check_output("ldd", self._path)
except (FileNotFoundError, subprocess.SubprocessError) as e:
except (OSError, subprocess.SubprocessError) as e:
log.warn("Could not determine the shared library dependencies for {}: {}".format(self._path, e))
return
@@ -421,7 +421,7 @@ class IOUVM(BaseNode):
hostid = (yield from gns3server.utils.asyncio.subprocess_check_output("hostid")).strip()
except FileNotFoundError as e:
raise IOUError("Could not find hostid: {}".format(e))
except subprocess.SubprocessError as e:
except (OSError, subprocess.SubprocessError) as e:
raise IOUError("Could not execute hostid: {}".format(e))
try:
@@ -517,6 +517,17 @@ class IOUVM(BaseNode):
if "IOURC" not in os.environ:
env["IOURC"] = iourc_path
# create a symbolic link to the image to avoid IOU error "failed code signing checks"
# on newer images, see https://github.com/GNS3/gns3-server/issues/1484
try:
symlink = os.path.join(self.working_dir, os.path.basename(self.path))
if os.path.islink(symlink):
os.unlink(symlink)
os.symlink(self.path, symlink)
except OSError as e:
raise IOUError("Could not create symbolic link: {}".format(e))
command = yield from self._build_command()
try:
log.info("Starting IOU: {}".format(command))
@@ -550,7 +561,8 @@ class IOUVM(BaseNode):
# configure networking support
yield from self._networking()
@locked_coroutine
@locking
@asyncio.coroutine
def _networking(self):
"""
Configures the IOL bridge in uBridge.
@@ -650,6 +662,13 @@ class IOUVM(BaseNode):
pass
self._iou_process = None
try:
symlink = os.path.join(self.working_dir, os.path.basename(self.path))
if os.path.islink(symlink):
os.unlink(symlink)
except OSError as e:
log.warning("Could not delete symbolic link: {}".format(e))
self._started = False
self.save_configs()
+1 -1
View File
@@ -23,7 +23,7 @@ import logging
log = logging.getLogger(__name__)
# This ports are disallowed by Chrome and Firefox to avoid issues, we skip them as well
# These ports are disallowed by Chrome and Firefox to avoid issues, we skip them as well
BANNED_PORTS = set((1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 77, 79, 87, 95, 101, 102, 103,
104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 139, 143, 179, 389, 465, 512, 513, 514, 515, 526,
530, 531, 532, 540, 556, 563, 587, 601, 636, 993, 995, 2049, 3659, 4045, 6000, 6665, 6666, 6667,
+3 -3
View File
@@ -29,7 +29,7 @@ from uuid import UUID, uuid4
from .port_manager import PortManager
from .notification_manager import NotificationManager
from ..config import Config
from ..utils.asyncio import wait_run_in_executor
from ..utils.asyncio import wait_run_in_executor, asyncio_ensure_future
from ..utils.path import check_path_allowed, get_default_project_directory
import logging
@@ -346,7 +346,7 @@ class Project:
tasks = []
for node in self._nodes:
tasks.append(asyncio.async(node.manager.close_node(node.id)))
tasks.append(asyncio_ensure_future(node.manager.close_node(node.id)))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -415,7 +415,7 @@ class Project:
"""
files = []
for dirpath, dirnames, filenames in os.walk(self.path):
for dirpath, dirnames, filenames in os.walk(self.path, followlinks=False):
for filename in filenames:
if not filename.endswith(".ghost"):
path = os.path.relpath(dirpath, self.path)
+3 -3
View File
@@ -186,14 +186,14 @@ class Qemu(BaseManager):
return ""
else:
try:
output = yield from subprocess_check_output(qemu_path, "-version")
output = yield from subprocess_check_output(qemu_path, "-version", "-nographic")
match = re.search("version\s+([0-9a-z\-\.]+)", output)
if match:
version = match.group(1)
return version
else:
raise QemuError("Could not determine the Qemu version for {}".format(qemu_path))
except subprocess.SubprocessError as e:
except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Error while looking for the Qemu version: {}".format(e))
@staticmethod
@@ -213,7 +213,7 @@ class Qemu(BaseManager):
return version
else:
raise QemuError("Could not determine the Qemu-img version for {}".format(qemu_img_path))
except subprocess.SubprocessError as e:
except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Error while looking for the Qemu-img version: {}".format(e))
@staticmethod
+12 -10
View File
@@ -974,7 +974,7 @@ class QemuVM(BaseNode):
try:
if self.acpi_shutdown:
yield from self._control_vm("system_powerdown")
yield from gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=30)
yield from gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=120)
else:
self._process.terminate()
yield from gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=3)
@@ -1028,7 +1028,7 @@ class QemuVM(BaseNode):
if expect in line:
result = line.decode("utf-8").strip()
break
except EOFError as e:
except (ConnectionError, EOFError) as e:
log.warn("Could not read from QEMU monitor: {}".format(e))
writer.close()
return result
@@ -1601,18 +1601,19 @@ class QemuVM(BaseNode):
return network_options
def _graphic(self):
@asyncio.coroutine
def _disable_graphics(self):
"""
Adds the correct graphic options depending of the OS
Disable graphics depending of the QEMU version
"""
if sys.platform.startswith("win"):
if any(opt in self._options for opt in ["-display", "-nographic", "-curses", "-sdl" "-spice", "-vnc"]):
return []
if len(os.environ.get("DISPLAY", "")) > 0:
return []
if "-nographic" not in self._options:
version = yield from self.manager.get_qemu_version(self.qemu_path)
if version and parse_version(version) >= parse_version("3.0"):
return ["-display", "none"]
else:
return ["-nographic"]
return []
def _run_with_kvm(self, qemu_path, options):
"""
@@ -1678,7 +1679,8 @@ class QemuVM(BaseNode):
raise QemuError("Console type {} is unknown".format(self._console_type))
command.extend(self._monitor_options())
command.extend((yield from self._network_options()))
command.extend(self._graphic())
if self._console_type == "telnet":
command.extend((yield from self._disable_graphics()))
if additional_options:
try:
command.extend(shlex.split(additional_options))
+12 -3
View File
@@ -33,7 +33,7 @@ import xml.etree.ElementTree as ET
from gns3server.utils import parse_version
from gns3server.utils.asyncio.telnet_server import AsyncioTelnetServer
from gns3server.utils.asyncio.serial import asyncio_open_serial
from gns3server.utils.asyncio import locked_coroutine
from gns3server.utils.asyncio import locking
from gns3server.compute.virtualbox.virtualbox_error import VirtualBoxError
from gns3server.compute.nios.nio_udp import NIOUDP
from gns3server.compute.adapters.ethernet_adapter import EthernetAdapter
@@ -217,6 +217,8 @@ class VirtualBoxVM(BaseNode):
except ET.ParseError:
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file. "
"File {} is corrupted.".format(self._linked_vbox_file()))
except OSError as e:
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file '{}': {}".format(self._linked_vbox_file(), e))
machine = tree.getroot().find("{http://www.virtualbox.org/}Machine")
if machine is not None and machine.get("uuid") != "{" + self.id + "}":
@@ -245,6 +247,7 @@ class VirtualBoxVM(BaseNode):
return True
return False
@locking
@asyncio.coroutine
def start(self):
"""
@@ -296,7 +299,8 @@ class VirtualBoxVM(BaseNode):
if (yield from self.check_hw_virtualization()):
self._hw_virtualization = True
@locked_coroutine
@locking
@asyncio.coroutine
def stop(self):
"""
Stops this VirtualBox VM.
@@ -937,7 +941,12 @@ class VirtualBoxVM(BaseNode):
"""
Starts remote console support for this VM.
"""
self._remote_pipe = yield from asyncio_open_serial(self._get_pipe_name())
pipe_name = self._get_pipe_name()
try:
self._remote_pipe = yield from asyncio_open_serial(pipe_name)
except OSError as e:
raise VirtualBoxError("Could not open serial pipe '{}': {}".format(pipe_name, e))
server = AsyncioTelnetServer(reader=self._remote_pipe,
writer=self._remote_pipe,
binary=True,
+8 -1
View File
@@ -32,6 +32,7 @@ import shlex
from collections import OrderedDict
from gns3server.utils.interfaces import interfaces
from gns3server.utils.asyncio import subprocess_check_output
from gns3server.utils.asyncio import asyncio_ensure_future
from gns3server.utils import parse_version
log = logging.getLogger(__name__)
@@ -148,6 +149,7 @@ class VMware(BaseManager):
VIX 1.13 was the release for Player 6.
VIX 1.14 was the release for Player 7.
VIX 1.15 was the release for Workstation Player 12.
VIX 1.17 was the release for Workstation Player 14.
:param player_version: VMware Player major version.
"""
@@ -161,6 +163,8 @@ class VMware(BaseManager):
yield from self.check_vmrun_version(minimum_required_version="1.14.0")
elif player_version >= 12:
yield from self.check_vmrun_version(minimum_required_version="1.15.0")
elif player_version >= 14:
yield from self.check_vmrun_version(minimum_required_version="1.17.0")
self._host_type = "player"
@asyncio.coroutine
@@ -171,6 +175,7 @@ class VMware(BaseManager):
VIX 1.13 was the release for Workstation 10.
VIX 1.14 was the release for Workstation 11.
VIX 1.15 was the release for Workstation Pro 12.
VIX 1.17 was the release for Workstation Pro 14.
:param ws_version: VMware Workstation major version.
"""
@@ -184,6 +189,8 @@ class VMware(BaseManager):
yield from self.check_vmrun_version(minimum_required_version="1.14.0")
elif ws_version >= 12:
yield from self.check_vmrun_version(minimum_required_version="1.15.0")
elif ws_version >= 14:
yield from self.check_vmrun_version(minimum_required_version="1.17.0")
self._host_type = "ws"
@asyncio.coroutine
@@ -738,4 +745,4 @@ if __name__ == '__main__':
loop = asyncio.get_event_loop()
vmware = VMware.instance()
print("=> Check version")
loop.run_until_complete(asyncio.async(vmware.check_vmware_version()))
loop.run_until_complete(asyncio_ensure_future(vmware.check_vmware_version()))
+9 -3
View File
@@ -26,7 +26,7 @@ import tempfile
from gns3server.utils.asyncio.telnet_server import AsyncioTelnetServer
from gns3server.utils.asyncio.serial import asyncio_open_serial
from gns3server.utils.asyncio import locked_coroutine
from gns3server.utils.asyncio import locking
from collections import OrderedDict
from .vmware_error import VMwareError
from ..nios.nio_udp import NIOUDP
@@ -94,7 +94,8 @@ class VMwareVM(BaseNode):
return self._vmnets
@locked_coroutine
@locking
@asyncio.coroutine
def _control_vm(self, subcommand, *additional_args):
args = [self._vmx_path]
@@ -844,7 +845,12 @@ class VMwareVM(BaseNode):
"""
Starts remote console support for this VM.
"""
self._remote_pipe = yield from asyncio_open_serial(self._get_pipe_name())
pipe_name = self._get_pipe_name()
try:
self._remote_pipe = yield from asyncio_open_serial(self._get_pipe_name())
except OSError as e:
raise VMwareError("Could not open serial pipe '{}': {}".format(pipe_name, e))
server = AsyncioTelnetServer(reader=self._remote_pipe,
writer=self._remote_pipe,
binary=True,
+1 -1
View File
@@ -315,7 +315,7 @@ class VPCSVM(BaseNode):
if sys.platform.startswith("win32"):
try:
self._process.send_signal(signal.CTRL_BREAK_EVENT)
except OSError:
except (SystemError, OSError):
pass
else:
try:
+4 -6
View File
@@ -66,10 +66,8 @@ class Controller:
def load_appliances(self):
self._appliance_templates = {}
for directory, builtin in (
(get_resource('appliances'), True,), (self.appliances_path(), False,)
):
if os.path.isdir(directory):
for directory, builtin in ((get_resource('appliances'), True,), (self.appliances_path(), False,)):
if directory and os.path.isdir(directory):
for file in os.listdir(directory):
if not file.endswith('.gns3a') and not file.endswith('.gns3appliance'):
continue
@@ -200,7 +198,7 @@ class Controller:
for c in computes:
try:
yield from self.add_compute(**c)
except (aiohttp.web.HTTPConflict, KeyError):
except (aiohttp.web.HTTPError, KeyError):
pass # Skip not available servers at loading
yield from self.load_projects()
try:
@@ -509,7 +507,7 @@ class Controller:
return self._computes[compute_id]
except KeyError:
if compute_id == "vm":
raise aiohttp.web.HTTPNotFound(text="You try to use a node on the GNS3 VM server but the GNS3 VM is not configured")
raise aiohttp.web.HTTPNotFound(text="A node is set to use the GNS3 VM server but the GNS3 VM is not configured")
raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id))
def has_compute(self, compute_id):
+46 -11
View File
@@ -27,9 +27,9 @@ from operator import itemgetter
from ..utils import parse_version
from ..utils.images import list_images
from ..utils.asyncio import locked_coroutine
from ..utils.asyncio import locking, asyncio_ensure_future
from ..controller.controller_error import ControllerError
from ..version import __version__
from ..version import __version__, __version_info__
import logging
@@ -95,6 +95,7 @@ class Compute:
self._set_auth(user, password)
self._cpu_usage_percent = None
self._memory_usage_percent = None
self._last_error = None
self._capabilities = {
"version": None,
"node_types": []
@@ -137,6 +138,14 @@ class Compute:
self._password = None
self._auth = aiohttp.BasicAuth(self._user, "")
def set_last_error(self, msg):
"""
Set the last error message for this compute.
:param msg: message
"""
self._last_error = msg
@asyncio.coroutine
def interfaces(self):
"""
@@ -301,7 +310,8 @@ class Compute:
"connected": self._connected,
"cpu_usage_percent": self._cpu_usage_percent,
"memory_usage_percent": self._memory_usage_percent,
"capabilities": self._capabilities
"capabilities": self._capabilities,
"last_error": self._last_error
}
@asyncio.coroutine
@@ -398,13 +408,14 @@ class Compute:
except aiohttp.web.HTTPConflict:
pass
@locked_coroutine
@locking
@asyncio.coroutine
def connect(self):
"""
Check if remote server is accessible
"""
if not self._connected and not self._closed:
if not self._connected and not self._closed and self.host:
try:
log.info("Connecting to compute '{}'".format(self._id))
response = yield from self._run_http_query("GET", "/capabilities")
@@ -416,7 +427,7 @@ class Compute:
if self._connection_failure == 5:
log.warning("Cannot connect to compute '{}': {}".format(self._id, e))
yield from self._controller.close_compute_projects(self)
asyncio.get_event_loop().call_later(2, lambda: asyncio.async(self._try_reconnect()))
asyncio.get_event_loop().call_later(2, lambda: asyncio_ensure_future(self._try_reconnect()))
return
except aiohttp.web.HTTPNotFound:
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server or it's a 1.X server".format(self._id))
@@ -428,16 +439,40 @@ class Compute:
raise aiohttp.web.HTTPConflict(text="Invalid server url for server {}".format(self._id))
if "version" not in response.json:
msg = "The server {} is not a GNS3 server".format(self._id)
log.error(msg)
self._http_session.close()
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
raise aiohttp.web.HTTPConflict(text=msg)
self._capabilities = response.json
if parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
self._http_session.close()
raise aiohttp.web.HTTPConflict(text="The server {} versions are not compatible {} != {}".format(self._id, __version__, response.json["version"]))
if response.json["version"].split("-")[0] != __version__.split("-")[0]:
if self._name.startswith("GNS3 VM"):
msg = "GNS3 version {} is not the same as the GNS3 VM version {}. Please upgrade the GNS3 VM.".format(__version__,
response.json["version"])
else:
msg = "GNS3 controller version {} is not the same as compute server {} version {}".format(__version__,
self._name,
response.json["version"])
if __version_info__[3] == 0:
# Stable release
log.error(msg)
self._http_session.close()
self._last_error = msg
raise aiohttp.web.HTTPConflict(text=msg)
elif parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
# We don't allow different major version to interact even with dev build
log.error(msg)
self._http_session.close()
self._last_error = msg
raise aiohttp.web.HTTPConflict(text=msg)
else:
msg = "{}\nUsing different versions may result in unexpected problems. Please use at your own risk.".format(msg)
self._controller.notification.emit("log.warning", {"message": msg})
self._notifications = asyncio.gather(self._connect_notification())
self._connected = True
self._connection_failure = 0
self._last_error = None
self._controller.notification.emit("compute.updated", self.__json__())
@asyncio.coroutine
@@ -472,7 +507,7 @@ class Compute:
# Try to reconnect after 1 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
asyncio.get_event_loop().call_later(1, lambda: asyncio.async(self.connect()))
asyncio.get_event_loop().call_later(1, lambda: asyncio_ensure_future(self.connect()))
self._ws = None
self._cpu_usage_percent = None
self._memory_usage_percent = None
+1 -1
View File
@@ -55,7 +55,7 @@ class Drawing:
return self._id
@property
def ressource_filename(self):
def resource_filename(self):
"""
If the svg content has been dump to an external file return is name otherwise None
"""
+35 -4
View File
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import json
import asyncio
import aiohttp
@@ -23,13 +24,14 @@ import zipfile
import tempfile
import zipstream
from datetime import datetime
import logging
log = logging.getLogger(__name__)
@asyncio.coroutine
def export_project(project, temporary_dir, include_images=False, keep_compute_id=False, allow_all_nodes=False):
def export_project(project, temporary_dir, include_images=False, keep_compute_id=False, allow_all_nodes=False, reset_mac_addresses=False):
"""
Export a project to a zip file.
@@ -40,6 +42,7 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
:param include images: save OS images to the zip file
:param keep_compute_id: If false replace all compute id by local (standard behavior for .gns3project to make it portable)
:param allow_all_nodes: Allow all nodes type to be include in the zip even if not portable
:param reset_mac_addresses: Reset MAC addresses for every nodes.
:returns: ZipStream object
"""
@@ -59,10 +62,10 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
# First we process the .gns3 in order to be sure we don't have an error
for file in os.listdir(project._path):
if file.endswith(".gns3"):
yield from _patch_project_file(project, os.path.join(project._path, file), zstream, include_images, keep_compute_id, allow_all_nodes, temporary_dir)
yield from _patch_project_file(project, os.path.join(project._path, file), zstream, include_images, keep_compute_id, allow_all_nodes, temporary_dir, reset_mac_addresses)
# Export the local files
for root, dirs, files in os.walk(project._path, topdown=True):
for root, dirs, files in os.walk(project._path, topdown=True, followlinks=False):
files = [f for f in files if _is_exportable(os.path.join(root, f))]
for file in files:
path = os.path.join(root, file)
@@ -77,6 +80,7 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
# ignore the .gns3 file
if file.endswith(".gns3"):
continue
_patch_mtime(path)
zstream.write(path, os.path.relpath(path, project._path), compress_type=zipfile.ZIP_DEFLATED)
# Export files from remote computes
@@ -99,12 +103,30 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
f.write(data)
response.close()
f.close()
_patch_mtime(temp_path)
zstream.write(temp_path, arcname=compute_file["path"], compress_type=zipfile.ZIP_DEFLATED)
downloaded_files.add(compute_file['path'])
return zstream
def _patch_mtime(path):
"""
Patch the file mtime because ZIP does not support timestamps before 1980
:param path: file path
"""
if sys.platform.startswith("win"):
# only UNIX type platforms
return
st = os.stat(path)
file_date = datetime.fromtimestamp(st.st_mtime)
if file_date.year < 1980:
new_mtime = file_date.replace(year=1980).timestamp()
os.utime(path, (st.st_atime, new_mtime))
def _is_exportable(path):
"""
:returns: True if file should not be included in the final archive
@@ -114,6 +136,10 @@ def _is_exportable(path):
if path.endswith("snapshots"):
return False
# do not export symlinks
if os.path.islink(path):
return False
# do not export directories of snapshots
if "{sep}snapshots{sep}".format(sep=os.path.sep) in path:
return False
@@ -135,7 +161,7 @@ def _is_exportable(path):
@asyncio.coroutine
def _patch_project_file(project, path, zstream, include_images, keep_compute_id, allow_all_nodes, temporary_dir):
def _patch_project_file(project, path, zstream, include_images, keep_compute_id, allow_all_nodes, temporary_dir, reset_mac_addresses):
"""
Patch a project file (.gns3) to export a project.
The .gns3 file is renamed to project.gns3
@@ -168,6 +194,10 @@ def _patch_project_file(project, path, zstream, include_images, keep_compute_id,
if "properties" in node and node["node_type"] != "docker":
for prop, value in node["properties"].items():
# reset the MAC address
if reset_mac_addresses and prop in ("mac_addr", "mac_address"):
node["properties"][prop] = None
if node["node_type"] == "iou":
if not prop == "path":
continue
@@ -228,6 +258,7 @@ def _export_local_image(image, zstream):
if os.path.exists(path):
arcname = os.path.join("images", directory, os.path.basename(image))
_patch_mtime(path)
zstream.write(path, arcname)
return
+19 -11
View File
@@ -21,7 +21,7 @@ import asyncio
import aiohttp
import ipaddress
from ...utils.asyncio import locked_coroutine
from ...utils.asyncio import locking, asyncio_ensure_future
from .vmware_gns3_vm import VMwareGNS3VM
from .virtualbox_gns3_vm import VirtualBoxGNS3VM
from .remote_gns3_vm import RemoteGNS3VM
@@ -246,13 +246,15 @@ class GNS3VM:
except GNS3VMError as e:
# User will receive the error later when they will try to use the node
try:
yield from self._controller.add_compute(compute_id="vm",
name="GNS3 VM ({})".format(self.current_engine().vmname),
host=None,
force=True)
compute = yield from self._controller.add_compute(compute_id="vm",
name="GNS3 VM ({})".format(self.current_engine().vmname),
host=None,
force=True)
compute.set_last_error(str(e))
except aiohttp.web.HTTPConflict:
pass
log.error("Can't start the GNS3 VM: %s", str(e))
log.error("Cannot start the GNS3 VM: {}".format(e))
@asyncio.coroutine
def exit_vm(self):
@@ -265,7 +267,8 @@ class GNS3VM:
except GNS3VMError as e:
log.warn(str(e))
@locked_coroutine
@locking
@asyncio.coroutine
def start(self):
"""
Start the GNS3 VM
@@ -289,8 +292,9 @@ class GNS3VM:
yield from engine.start()
except Exception as e:
yield from self._controller.delete_compute("vm")
log.error("Can't start the GNS3 VM: {}".format(str(e)))
log.error("Cannot start the GNS3 VM: {}".format(str(e)))
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname))
compute.set_last_error(str(e))
raise e
yield from compute.connect() # we can connect now that the VM has started
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname),
@@ -302,7 +306,7 @@ class GNS3VM:
# check if the VM is in the same subnet as the local server, start 10 seconds later to give
# some time for the compute in the VM to be ready for requests
asyncio.get_event_loop().call_later(10, lambda: asyncio.async(self._check_network(compute)))
asyncio.get_event_loop().call_later(10, lambda: asyncio_ensure_future(self._check_network(compute)))
@asyncio.coroutine
def _check_network(self, compute):
@@ -336,8 +340,11 @@ class GNS3VM:
self._controller.notification.emit("log.warning", {"message": msg})
except ComputeError as e:
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e))
except aiohttp.web.HTTPConflict as e:
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e.text))
@locked_coroutine
@locking
@asyncio.coroutine
def _suspend(self):
"""
Suspend the GNS3 VM
@@ -349,7 +356,8 @@ class GNS3VM:
log.info("Suspend the GNS3 VM")
yield from engine.suspend()
@locked_coroutine
@locking
@asyncio.coroutine
def _stop(self):
"""
Stop the GNS3 VM
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import aiohttp
import logging
import asyncio
@@ -107,7 +108,6 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
Check if the DHCP server associated with a vboxnet is enabled.
:param vboxnet: vboxnet name
:returns: boolean
"""
@@ -125,6 +125,41 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
return True
return False
@asyncio.coroutine
def _check_vboxnet_exists(self, vboxnet):
"""
Check if the vboxnet interface exists
:param vboxnet: vboxnet name
:returns: boolean
"""
properties = yield from self._execute("list", ["hostonlyifs"])
for prop in properties.splitlines():
try:
name, value = prop.split(':', 1)
except ValueError:
continue
if name.strip() == "Name" and value.strip() == vboxnet:
return True
return False
@asyncio.coroutine
def _find_first_available_vboxnet(self):
"""
Find the first available vboxnet.
"""
properties = yield from self._execute("list", ["hostonlyifs"])
for prop in properties.splitlines():
try:
name, value = prop.split(':', 1)
except ValueError:
continue
if name.strip() == "Name":
return value.strip()
return None
@asyncio.coroutine
def _check_vbox_port_forwarding(self):
"""
@@ -158,18 +193,32 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
# get a NAT interface number
nat_interface_number = yield from self._look_for_interface("nat")
if nat_interface_number < 0:
raise GNS3VMError("The GNS3 VM: {} must have a NAT interface configured in order to start".format(self.vmname))
raise GNS3VMError('VM "{}" must have a NAT interface configured in order to start'.format(self.vmname))
hostonly_interface_number = yield from self._look_for_interface("hostonly")
if hostonly_interface_number < 0:
raise GNS3VMError("The GNS3 VM: {} must have a host only interface configured in order to start".format(self.vmname))
raise GNS3VMError('VM "{}" must have a host-only interface configured in order to start'.format(self.vmname))
vboxnet = yield from self._look_for_vboxnet(hostonly_interface_number)
if vboxnet is None:
raise GNS3VMError("VirtualBox host-only network could not be found for interface {} on GNS3 VM".format(hostonly_interface_number))
raise GNS3VMError('A VirtualBox host-only network could not be found on network adapter {} for "{}"'.format(hostonly_interface_number, self._vmname))
if not (yield from self._check_vboxnet_exists(vboxnet)):
if sys.platform.startswith("win") and vboxnet == "vboxnet0":
# The GNS3 VM is configured with vboxnet0 by default which is not available
# on Windows. Try to patch this with the first available vboxnet we find.
first_available_vboxnet = yield from self._find_first_available_vboxnet()
if first_available_vboxnet is None:
raise GNS3VMError('Please add a VirtualBox host-only network with DHCP enabled and attached it to network adapter {} for "{}"'.format(hostonly_interface_number, self._vmname))
yield from self.set_hostonly_network(hostonly_interface_number, first_available_vboxnet)
vboxnet = first_available_vboxnet
else:
raise GNS3VMError('VirtualBox host-only network "{}" does not exist, please make the sure the network adapter {} configuration is valid for "{}"'.format(vboxnet,
hostonly_interface_number,
self._vmname))
if not (yield from self._check_dhcp_server(vboxnet)):
raise GNS3VMError("DHCP must be enabled on VirtualBox host-only network: {} for GNS3 VM".format(vboxnet))
raise GNS3VMError('DHCP must be enabled on VirtualBox host-only network "{}"'.format(vboxnet))
vm_state = yield from self._get_state()
log.info('"{}" state is {}'.format(self._vmname, vm_state))
@@ -311,3 +360,17 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
yield from self._execute("modifyvm", [self._vmname, "--memory", str(ram)], timeout=3)
log.info("GNS3 VM RAM amount set to {}".format(ram))
@asyncio.coroutine
def set_hostonly_network(self, adapter_number, hostonly_network_name):
"""
Set a VirtualBox host-only network on a network adapter for the GNS3 VM.
:param adapter_number: network adapter number
:param hostonly_network_name: name of the VirtualBox host-only network
"""
yield from self._execute("modifyvm", [self._vmname, "--hostonlyadapter{}".format(adapter_number), hostonly_network_name], timeout=3)
log.info('VirtualBox host-only network "{}" set on network adapter {} for "{}"'.format(hostonly_network_name,
adapter_number,
self._vmname))
@@ -72,15 +72,19 @@ class VMwareGNS3VM(BaseGNS3VM):
if ram % 4 != 0:
raise GNS3VMError("Allocated memory {} for the GNS3 VM must be a multiple of 4".format(ram))
available_vcpus = psutil.cpu_count(logical=False)
available_vcpus = psutil.cpu_count(logical=True)
if vcpus > available_vcpus:
raise GNS3VMError("You have allocated too many vCPUs for the GNS3 VM! (max available is {} vCPUs)".format(available_vcpus))
try:
pairs = VMware.parse_vmware_file(self._vmx_path)
pairs["numvcpus"] = str(vcpus)
pairs["memsize"] = str(ram)
VMware.write_vmx_file(self._vmx_path, pairs)
if vcpus > 1:
pairs["numvcpus"] = str(vcpus)
cores_per_sockets = int(vcpus / psutil.cpu_count(logical=False))
if cores_per_sockets > 1:
pairs["cpuid.corespersocket"] = str(cores_per_sockets)
pairs["memsize"] = str(ram)
VMware.write_vmx_file(self._vmx_path, pairs)
log.info("GNS3 VM vCPU count set to {} and RAM amount set to {}".format(vcpus, ram))
except OSError as e:
raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
+6 -2
View File
@@ -184,9 +184,11 @@ def _move_files_to_compute(compute, project_id, directory, files_path):
location = os.path.join(directory, files_path)
if os.path.exists(location):
for (dirpath, dirnames, filenames) in os.walk(location):
for (dirpath, dirnames, filenames) in os.walk(location, followlinks=False):
for filename in filenames:
path = os.path.join(dirpath, filename)
if os.path.islink(path):
continue
dst = os.path.relpath(path, directory)
yield from _upload_file(compute, project_id, path, dst)
yield from wait_run_in_executor(shutil.rmtree, os.path.join(directory, files_path))
@@ -213,9 +215,11 @@ def _import_images(controller, path):
image_dir = controller.images_path()
root = os.path.join(path, "images")
for (dirpath, dirnames, filenames) in os.walk(root):
for (dirpath, dirnames, filenames) in os.walk(root, followlinks=False):
for filename in filenames:
path = os.path.join(dirpath, filename)
if os.path.islink(path):
continue
dst = os.path.join(image_dir, os.path.relpath(path, root))
os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.move(path, dst)
+3 -1
View File
@@ -22,6 +22,8 @@ import html
import asyncio
import aiohttp
from gns3server.utils.asyncio import asyncio_ensure_future
import logging
log = logging.getLogger(__name__)
@@ -296,7 +298,7 @@ class Link:
self._capturing = True
self._capture_file_name = capture_file_name
self._streaming_pcap = asyncio.async(self._start_streaming_pcap())
self._streaming_pcap = asyncio_ensure_future(self._start_streaming_pcap())
self._project.controller.notification.emit("link.updated", self.__json__())
@asyncio.coroutine
+5 -5
View File
@@ -91,12 +91,12 @@ class Node:
# Update node properties with additional elements
for prop in kwargs:
if prop not in ignore_properties:
if prop and prop not in ignore_properties:
if hasattr(self, prop):
try:
setattr(self, prop, kwargs[prop])
except AttributeError as e:
log.critical("Can't set attribute %s", prop)
log.critical("Cannot set attribute '%s'".format(prop))
raise e
else:
if prop not in self.CONTROLLER_ONLY_PROPERTIES and kwargs[prop] is not None and kwargs[prop] != "":
@@ -175,9 +175,9 @@ class Node:
if not os.path.isabs(path):
path = os.path.join(self.project.controller.configs_path(), path)
try:
with open(path) as f:
with open(path, encoding="utf-8") as f:
return f.read()
except (PermissionError, OSError):
except OSError:
return None
@property
@@ -254,7 +254,7 @@ class Node:
try:
self._width, self._height, filetype = self._project.controller.symbols.get_size(val)
except (ValueError, OSError) as e:
log.error("Could not write symbol: {}".format(e))
log.error("Could not set symbol: {}".format(e))
# If symbol is invalid we replace it by the default
self.symbol = ":/symbols/computer.svg"
if self._label is None:
+2 -6
View File
@@ -33,8 +33,8 @@ class ATMPort(SerialPort):
"""
return "ATM"
@property
def short_name_type(self):
@staticmethod
def short_name_type():
"""
Returns the short name type for this port.
@@ -42,10 +42,6 @@ class ATMPort(SerialPort):
"""
return "a"
@property
def short_name(self):
return "{}".format(self._port_number)
@property
def data_link_types(self):
"""
+2 -2
View File
@@ -39,8 +39,8 @@ class EthernetPort(Port):
return "Ethernet"
@property
def short_name_type(self):
@staticmethod
def short_name_type():
"""
Returns the short name type for this port.
@@ -34,8 +34,8 @@ class FastEthernetPort(Port):
return "FastEthernet"
@property
def short_name_type(self):
@staticmethod
def short_name_type():
"""
Returns the short name type for this port.
@@ -34,10 +34,6 @@ class FrameRelayPort(SerialPort):
return "FrameRelay"
@property
def short_name(self):
return "{}".format(self._port_number)
@property
def data_link_types(self):
"""
@@ -34,8 +34,8 @@ class GigabitEthernetPort(Port):
return "GigabitEthernet"
@property
def short_name_type(self):
@staticmethod
def short_name_type():
"""
Returns the short name type for this port.
+2 -2
View File
@@ -67,9 +67,9 @@ class Port:
if self._short_name:
return self._short_name
elif '/' in self._name:
return self._name.replace(self.long_name_type(), self.short_name_type)
return self._name.replace(self.long_name_type(), self.short_name_type())
elif self._name.startswith("{}{}".format(self.long_name_type(), self._interface_number)):
return self.short_name_type + "{}".format(self._interface_number)
return self.short_name_type() + "{}".format(self._interface_number)
return self._name
@short_name.setter
+3 -3
View File
@@ -72,7 +72,7 @@ class StandardPortFactory:
segment_number,
adapter=adapter_number,
**cls._generate_replacement(interface_number, segment_number))
except (ValueError, KeyError) as e:
except (IndexError, ValueError, KeyError) as e:
raise aiohttp.web.HTTPConflict(text="Invalid port name format {}: {}".format(port_name_format, str(e)))
port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet")
interface_number += 1
@@ -191,7 +191,7 @@ class DynamipsPortFactory:
for port_number in range(0, cls.ADAPTER_MATRIX[properties[name]]["nb_ports"]):
name = "{}{}/{}".format(port_class.long_name_type(), adapter_number, port_number)
port = port_class(name, adapter_number, adapter_number, port_number)
port.short_name = "{}{}/{}".format(port.short_name_type, adapter_number, port_number)
port.short_name = "{}{}/{}".format(port_class.short_name_type(), adapter_number, port_number)
ports.append(port)
adapter_number += 1
elif name.startswith("wic") and properties[name]:
@@ -200,7 +200,7 @@ class DynamipsPortFactory:
for port_number in range(0, cls.WIC_MATRIX[properties[name]]["nb_ports"]):
name = "{}{}/{}".format(port_class.long_name_type(), 0, display_wic_port_number)
port = port_class(name, 0, 0, wic_port_number)
port.short_name = "{}{}/{}".format(port.short_name_type, 0, display_wic_port_number)
port.short_name = "{}{}/{}".format(port_class.short_name_type(), 0, display_wic_port_number)
ports.append(port)
display_wic_port_number += 1
wic_port_number += 1
+2 -2
View File
@@ -33,8 +33,8 @@ class POSPort(SerialPort):
"""
return "POS"
@property
def short_name_type(self):
@staticmethod
def short_name_type():
"""
Returns the short name type for this port.
+2 -2
View File
@@ -34,8 +34,8 @@ class SerialPort(Port):
return "Serial"
@property
def short_name_type(self):
@staticmethod
def short_name_type():
"""
Returns the short name type for this port.
+24 -19
View File
@@ -36,8 +36,9 @@ from .udp_link import UDPLink
from ..config import Config
from ..utils.path import check_path_allowed, get_default_project_directory
from ..utils.asyncio.pool import Pool
from ..utils.asyncio import locked_coroutine
from ..utils.asyncio import locking
from ..utils.asyncio import wait_run_in_executor
from ..utils.asyncio import asyncio_ensure_future
from .export_project import export_project
from .import_project import import_project
@@ -145,7 +146,6 @@ class Project:
}
)
def reset(self):
"""
Called when open/close a project. Cleanup internal stuff
@@ -524,7 +524,8 @@ class Project:
self.dump()
return node
@locked_coroutine
@locking
@asyncio.coroutine
def __delete_node_links(self, node):
"""
Delete all link connected to this node.
@@ -702,24 +703,26 @@ class Project:
# We don't care if a compute is down at this step
except (ComputeError, aiohttp.web.HTTPError, aiohttp.ClientResponseError, TimeoutError):
pass
self._cleanPictures()
self._clean_pictures()
self._status = "closed"
if not ignore_notification:
self.controller.notification.emit("project.closed", self.__json__())
def _cleanPictures(self):
def _clean_pictures(self):
"""
Delete unused images
Delete unused pictures.
"""
# Project have been deleted
if not os.path.exists(self.path):
# Project have been deleted or is loading or is not opened
if not os.path.exists(self.path) or self._loading or self._status != "opened":
return
try:
pictures = set(os.listdir(self.pictures_directory))
for drawing in self._drawings.values():
try:
pictures.remove(drawing.ressource_filename)
resource_filename = drawing.resource_filename
if resource_filename:
pictures.remove(resource_filename)
except KeyError:
pass
@@ -731,11 +734,12 @@ class Project:
except KeyError:
pass
for pict in pictures:
os.remove(os.path.join(self.pictures_directory, pict))
for pic_filename in pictures:
path = os.path.join(self.pictures_directory, pic_filename)
log.info("Deleting unused picture '{}'".format(path))
os.remove(path)
except OSError as e:
log.warning(str(e))
log.warning("Could not delete unused pictures: {}".format(e))
@asyncio.coroutine
def delete(self):
@@ -782,7 +786,8 @@ class Project:
def _topology_file(self):
return os.path.join(self.path, self._filename)
@locked_coroutine
@locking
@asyncio.coroutine
def open(self):
"""
Load topology elements
@@ -840,7 +845,7 @@ class Project:
link = yield from self.add_link(link_id=link_data["link_id"])
if "filters" in link_data:
yield from link.update_filters(link_data["filters"])
for node_link in link_data["nodes"]:
for node_link in link_data.get("nodes", []):
node = self.get_node(node_link["node_id"])
port = node.get_port(node_link["adapter_number"], node_link["port_number"])
if port is None:
@@ -868,7 +873,7 @@ class Project:
try:
if os.path.exists(path + ".backup"):
shutil.copy(path + ".backup", path)
except (PermissionError, OSError):
except OSError:
pass
self._status = "closed"
self._loading = False
@@ -887,7 +892,7 @@ class Project:
# Start all in the background without waiting for completion
# we ignore errors because we want to let the user open
# their project and fix it
asyncio.async(self.start_all())
asyncio_ensure_future(self.start_all())
@asyncio.coroutine
def wait_loaded(self):
@@ -926,13 +931,13 @@ class Project:
self.dump()
try:
with tempfile.TemporaryDirectory() as tmpdir:
zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True)
zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True, reset_mac_addresses=True)
project_path = os.path.join(tmpdir, "project.gns3p")
yield from wait_run_in_executor(self._create_duplicate_project_file, project_path, zipstream)
with open(project_path, "rb") as f:
project = yield from import_project(self._controller, str(uuid.uuid4()), f, location=location, name=name, keep_compute_id=True)
except (ValueError, OSError, UnicodeEncodeError) as e:
raise aiohttp.web.HTTPConflict(text="Can not duplicate project: {}".format(str(e)))
raise aiohttp.web.HTTPConflict(text="Cannot duplicate project: {}".format(str(e)))
if previous_status == "closed":
yield from self.close()
+1 -1
View File
@@ -101,7 +101,7 @@ class Snapshot:
with tempfile.TemporaryDirectory() as tmpdir:
zipstream = yield from export_project(self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True)
yield from wait_run_in_executor(self._create_snapshot_file, zipstream)
except OSError as e:
except (ValueError, OSError, RuntimeError) as e:
raise aiohttp.web.HTTPConflict(text="Could not create snapshot file '{}': {}".format(self.path, e))
@asyncio.coroutine
+14 -5
View File
@@ -22,6 +22,9 @@ from ..utils.get_resource import get_resource
from ..utils.picture import get_size
from ..config import Config
import logging
log = logging.getLogger(__name__)
class Symbols:
"""
@@ -72,19 +75,25 @@ class Symbols:
def symbols_path(self):
directory = os.path.expanduser(Config.instance().get_section_config("Server").get("symbols_path", "~/GNS3/symbols"))
if directory:
os.makedirs(directory, exist_ok=True)
try:
os.makedirs(directory, exist_ok=True)
except OSError as e:
log.error("Could not create symbol directory '{}': {}".format(directory, e))
return None
return directory
def get_path(self, symbol_id):
try:
return self._symbols_path[symbol_id]
# Symbol not found refresh cache
# Symbol not found, let's refresh the cache
except KeyError:
self.list()
try:
self.list()
return self._symbols_path[symbol_id]
except KeyError:
return self._symbols_path[":/symbols/computer.svg"]
except (OSError, KeyError):
log.warning("Could not retrieve symbol '{}'".format(symbol_id))
symbols_path = self._symbols_path
return symbols_path[":/symbols/computer.svg"]
def get_size(self, symbol_id):
try:
+4 -4
View File
@@ -409,7 +409,7 @@ def _convert_1_3_later(topo, topo_path):
symbol = old_node.get("symbol", ":/symbols/computer.svg")
old_node["ports"] = _create_cloud(node, old_node, symbol)
else:
raise NotImplementedError("Conversion of {} is not supported".format(old_node["type"]))
raise aiohttp.web.HTTPConflict(text="Conversion of {} is not supported".format(old_node["type"]))
for prop in old_node.get("properties", {}):
if prop not in ["console", "name", "console_type", "console_host", "use_ubridge"]:
@@ -608,13 +608,13 @@ def _create_cloud(node, old_node, icon):
elif old_port["name"].startswith("nio_nat"):
continue
else:
raise NotImplementedError("The conversion of cloud with {} is not supported".format(old_port["name"]))
raise aiohttp.web.HTTPConflict(text="The conversion of cloud with {} is not supported".format(old_port["name"]))
if port_type == "udp":
try:
_, lport, rhost, rport = old_port["name"].split(":")
except ValueError:
raise NotImplementedError("UDP tunnel using IPV6 is not supported in cloud")
raise aiohttp.web.HTTPConflict(text="UDP tunnel using IPV6 is not supported in cloud")
port = {
"name": "UDP tunnel {}".format(len(ports) + 1),
"port_number": len(ports) + 1,
@@ -645,7 +645,7 @@ def _convert_snapshots(topo_dir):
old_snapshots_dir = os.path.join(topo_dir, "project-files", "snapshots")
if os.path.exists(old_snapshots_dir):
new_snapshots_dir = os.path.join(topo_dir, "snapshots")
os.makedirs(new_snapshots_dir)
os.makedirs(new_snapshots_dir, exist_ok=True)
for snapshot in os.listdir(old_snapshots_dir):
snapshot_dir = os.path.join(old_snapshots_dir, snapshot)
+26 -4
View File
@@ -20,7 +20,7 @@ import sys
import struct
import aiohttp
import platform
import locale
try:
import raven
@@ -57,7 +57,7 @@ class CrashReport:
Report crash to a third party service
"""
DSN = "sync+https://56af21e241ed4c1894ebe17bf06b1cd1:6075f91067954267b51e90b9638a6fad@sentry.io/38482"
DSN = "https://2b1412df322748bc8b36639671f1a40e:25804fdd614d498aa429c689f540779e@sentry.io/38482"
if hasattr(sys, "frozen"):
cacert = get_resource("cacert.pem")
if cacert is not None and os.path.isfile(cacert):
@@ -92,7 +92,8 @@ class CrashReport:
"url": request.path,
"data": request.json,
})
self._client.tags_context({
context = {
"os:name": platform.system(),
"os:release": platform.release(),
"os:win_32": " ".join(platform.win32_ver()),
@@ -105,7 +106,28 @@ class CrashReport:
"python:bit": struct.calcsize("P") * 8,
"python:encoding": sys.getdefaultencoding(),
"python:frozen": "{}".format(hasattr(sys, "frozen"))
})
}
if sys.platform.startswith("linux") and not hasattr(sys, "frozen"):
# add locale information
try:
language, encoding = locale.getlocale()
context["locale:language"] = language
context["locale:encoding"] = encoding
except ValueError:
pass
# add GNS3 VM version if it exists
home = os.path.expanduser("~")
gns3vm_version = os.path.join(home, ".config", "GNS3", "gns3vm_version")
if os.path.isfile(gns3vm_version):
try:
with open(gns3vm_version) as fd:
context["gns3vm:version"] = fd.readline().strip()
except OSError:
pass
self._client.tags_context(context)
try:
report = self._client.captureException()
except Exception as e:
@@ -263,10 +263,11 @@ class DockerHandler:
docker_manager = Docker.instance()
container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
nio = container.ethernet_adapters[int(request.match_info["adapter_number"])].get_nio(0)
adapter_number = int(request.match_info["adapter_number"])
nio = container.ethernet_adapters[adapter_number].get_nio(0)
if "filters" in request.json and nio:
nio.filters = request.json["filters"]
yield from container.adapter_update_nio_binding(int(request.match_info["port_number"]), nio)
yield from container.adapter_update_nio_binding(adapter_number, nio)
response.set_status(201)
response.json(request.json)
@@ -301,12 +301,9 @@ class IOUHandler:
nio = vm.adapters[adapter_number].get_nio(port_number)
if "filters" in request.json and nio:
nio.filters = request.json["filters"]
yield from vm.adapter_update_nio_binding(
adapter_number,
port_number,
nio)
yield from vm.adapter_update_nio_binding(adapter_number, port_number, nio)
response.set_status(201)
response.json(nio)
response.json(request.json)
@Route.delete(
r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
@@ -20,6 +20,7 @@ import aiohttp
from aiohttp.web import WebSocketResponse
from gns3server.web.route import Route
from gns3server.compute.notification_manager import NotificationManager
from gns3server.utils.asyncio import asyncio_ensure_future
@asyncio.coroutine
@@ -43,7 +44,7 @@ class NotificationHandler:
ws = WebSocketResponse()
yield from ws.prepare(request)
asyncio.async(process_websocket(ws))
asyncio_ensure_future(process_websocket(ws))
with notifications.queue() as queue:
while True:
@@ -42,9 +42,9 @@ class ServerHandler:
@Route.get(
r"/debug",
description="Return debug informations about the compute",
description="Return debug information about the compute",
status_codes={
201: "Writed"
201: "Written"
})
def debug(request, response):
response.content_type = "text/plain"
@@ -279,12 +279,13 @@ class VMwareHandler:
vmware_manager = VMware.instance()
vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
nio = vm.ethernet_adapters[int(request.match_info["adapter_number"])]
adapter_number = int(request.match_info["adapter_number"])
nio = vm.ethernet_adapters[adapter_number]
if "filters" in request.json and nio:
nio.filters = request.json["filters"]
yield from vm.adapter_update_nio_binding(int(request.match_info["adapter_number"]), nio)
response.set_status(201)
response.json(request.json)
yield from vm.adapter_update_nio_binding(adapter_number, nio)
response.set_status(201)
response.json(request.json)
@Route.delete(
r"/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
@@ -67,8 +67,9 @@ class ApplianceHandler:
controller = Controller.instance()
project = controller.get_project(request.match_info["project_id"])
yield from project.add_node_from_appliance(request.match_info["appliance_id"],
x=request.json["x"],
y=request.json["y"],
compute_id=request.json.get("compute_id"))
node = yield from project.add_node_from_appliance(request.match_info["appliance_id"],
x=request.json["x"],
y=request.json["y"],
compute_id=request.json.get("compute_id"))
response.set_status(201)
response.json(node)
@@ -59,7 +59,7 @@ class ComputeHandler:
@Route.put(
r"/computes/{compute_id}",
description="Get a compute server information",
description="Update a compute server",
status_codes={
200: "Compute server updated",
400: "Invalid request",
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import aiohttp
import asyncio
import tempfile
@@ -25,6 +26,7 @@ from gns3server.controller import Controller
from gns3server.controller.import_project import import_project
from gns3server.controller.export_project import export_project
from gns3server.config import Config
from gns3server.utils.asyncio import asyncio_ensure_future
from gns3server.schemas.project import (
@@ -246,7 +248,7 @@ class ProjectHandler:
ws = aiohttp.web.WebSocketResponse()
yield from ws.prepare(request)
asyncio.async(process_websocket(ws))
asyncio_ensure_future(process_websocket(ws))
with controller.notification.queue(project) as queue:
while True:
@@ -285,9 +287,9 @@ class ProjectHandler:
try:
with tempfile.TemporaryDirectory() as tmp_dir:
datas = yield from export_project(
project, tmp_dir,
include_images=bool(int(request.query.get("include_images", "0"))))
stream = yield from export_project(project,
tmp_dir,
include_images=bool(int(request.query.get("include_images", "0"))))
# We need to do that now because export could failed and raise an HTTP error
# that why response start need to be the later possible
response.content_type = 'application/gns3project'
@@ -295,15 +297,15 @@ class ProjectHandler:
response.enable_chunked_encoding()
yield from response.prepare(request)
for data in datas:
for data in stream:
response.write(data)
yield from response.drain()
yield from response.write_eof()
# Will be raise if you have no space left or permission issue on your temporary directory
# RuntimeError: something was wrong during the zip process
except (OSError, RuntimeError) as e:
raise aiohttp.web.HTTPNotFound(text="Can't export project: {}".format(str(e)))
except (ValueError, OSError, RuntimeError) as e:
raise aiohttp.web.HTTPNotFound(text="Cannot export project: {}".format(str(e)))
@Route.post(
r"/projects/{project_id}/import",
@@ -332,14 +334,25 @@ class ProjectHandler:
# We write the content to a temporary location and after we extract it all.
# It could be more optimal to stream this but it is not implemented in Python.
# Spooled means the file is temporary kept in memory until max_size is reached
# Cannot use tempfile.SpooledTemporaryFile(max_size=10000) in Python 3.7 due
# to a bug https://bugs.python.org/issue26175
try:
with tempfile.SpooledTemporaryFile(max_size=10000) as temp:
while True:
chunk = yield from request.content.read(1024)
if not chunk:
break
temp.write(chunk)
project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name)
if sys.version_info >= (3, 7) and sys.version_info < (3, 8):
with tempfile.TemporaryFile() as temp:
while True:
chunk = yield from request.content.read(1024)
if not chunk:
break
temp.write(chunk)
project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name)
else:
with tempfile.SpooledTemporaryFile(max_size=10000) as temp:
while True:
chunk = yield from request.content.read(1024)
if not chunk:
break
temp.write(chunk)
project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name)
except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not import the project: {}".format(e))
@@ -20,6 +20,7 @@ from gns3server.config import Config
from gns3server.controller import Controller
from gns3server.schemas.version import VERSION_SCHEMA
from gns3server.version import __version__
from gns3server.utils.asyncio import asyncio_ensure_future
from aiohttp.web import HTTPConflict, HTTPForbidden
@@ -57,7 +58,7 @@ class ServerHandler:
tasks = []
for project in projects:
tasks.append(asyncio.async(project.close()))
tasks.append(asyncio_ensure_future(project.close()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -71,7 +72,10 @@ class ServerHandler:
# then shutdown the server itself
from gns3server.web.web_server import WebServer
server = WebServer.instance()
asyncio.async(server.shutdown_server())
try:
asyncio_ensure_future(server.shutdown_server())
except asyncio.CancelledError:
pass
response.set_status(201)
@Route.get(
@@ -135,7 +139,7 @@ class ServerHandler:
r"/debug",
description="Dump debug information to disk (debug directory in config directory). Work only for local server",
status_codes={
201: "Writed"
201: "Written"
})
def debug(request, response):
@@ -152,7 +156,7 @@ class ServerHandler:
f.write(ServerHandler._getDebugData())
except Exception as e:
# If something is wrong we log the info to the log and we hope the log will be include correctly to the debug export
log.error("Could not export debug informations {}".format(e), exc_info=1)
log.error("Could not export debug information {}".format(e), exc_info=1)
try:
if Controller.instance().gns3vm.engine == "vmware":
@@ -52,21 +52,22 @@ class SymbolHandler:
controller = Controller.instance()
try:
yield from response.file(controller.symbols.get_path(request.match_info["symbol_id"]))
except (KeyError, FileNotFoundError, PermissionError):
except (KeyError, OSError) as e:
log.warning("Could not get symbol file: {}".format(e))
response.set_status(404)
@Route.post(
r"/symbols/{symbol_id:.+}/raw",
description="Write the symbol file",
status_codes={
200: "Symbol returned"
200: "Symbol written"
},
raw=True)
def upload(request, response):
controller = Controller.instance()
path = os.path.join(controller.symbols.symbols_path(), os.path.basename(request.match_info["symbol_id"]))
try:
with open(path, 'wb') as f:
with open(path, "wb") as f:
while True:
try:
chunk = yield from request.content.read(1024)
@@ -75,8 +76,9 @@ class SymbolHandler:
if not chunk:
break
f.write(chunk)
except OSError as e:
except (UnicodeEncodeError, OSError) as e:
raise aiohttp.web.HTTPConflict(text="Could not write symbol file '{}': {}".format(path, e))
# Reset the symbol list
controller.symbols.list()
response.set_status(204)
-1
View File
@@ -91,7 +91,6 @@ def parse_arguments(argv):
parser.add_argument("--host", help="run on the given host/IP address")
parser.add_argument("--port", help="run on the given port", type=int)
parser.add_argument("--ssl", action="store_true", help="run in SSL mode")
parser.add_argument("--no-ubridge", action="store_false", help="do not use ubridge to handle node connections")
parser.add_argument("--config", help="Configuration file")
parser.add_argument("--certfile", help="SSL cert file")
parser.add_argument("--certkey", help="SSL key file")
+4
View File
@@ -104,6 +104,10 @@ COMPUTE_OBJECT_SCHEMA = {
"maximum": 100,
"minimum": 0
},
"last_error": {
"description": "Last error on the compute",
"type": ["string", "null"]
},
"capabilities": CAPABILITIES_SCHEMA
},
"additionalProperties": False,
+3 -3
View File
@@ -137,7 +137,7 @@ VM_CREATE_SCHEMA = {
},
"mac_addr": {
"description": "Base MAC address",
"type": "string",
"type": ["null", "string"],
"minLength": 1,
"pattern": "^([0-9a-fA-F]{4}\\.){2}[0-9a-fA-F]{4}$"
},
@@ -355,7 +355,7 @@ VM_UPDATE_SCHEMA = {
},
"mac_addr": {
"description": "Base MAC address",
"type": "string",
"type": ["null", "string"],
"minLength": 1,
"pattern": "^([0-9a-fA-F]{4}\\.){2}[0-9a-fA-F]{4}$"
},
@@ -595,7 +595,7 @@ VM_OBJECT_SCHEMA = {
},
"mac_addr": {
"description": "Base MAC address",
"type": "string",
"type": ["null", "string"]
#"minLength": 1,
#"pattern": "^([0-9a-fA-F]{4}\\.){2}[0-9a-fA-F]{4}$"
},
+4 -4
View File
@@ -131,7 +131,7 @@ QEMU_CREATE_SCHEMA = {
},
"boot_priority": {
"description": "QEMU boot priority",
"enum": ["c", "d", "n", "cn", "cd"]
"enum": ["c", "d", "n", "cn", "cd", "dn", "dc", "nc", "nd"]
},
"ram": {
"description": "Amount of RAM in MB",
@@ -316,7 +316,7 @@ QEMU_UPDATE_SCHEMA = {
},
"boot_priority": {
"description": "QEMU boot priority",
"enum": ["c", "d", "n", "cn", "cd"]
"enum": ["c", "d", "n", "cn", "cd", "dn", "dc", "nc", "nd"]
},
"ram": {
"description": "Amount of RAM in MB",
@@ -500,7 +500,7 @@ QEMU_OBJECT_SCHEMA = {
},
"boot_priority": {
"description": "QEMU boot priority",
"enum": ["c", "d", "n", "cn", "cd"]
"enum": ["c", "d", "n", "cn", "cd", "dn", "dc", "nc", "nd"]
},
"node_directory": {
"description": "Path to the VM working directory",
@@ -537,7 +537,7 @@ QEMU_OBJECT_SCHEMA = {
"description": "Console TCP port",
"minimum": 1,
"maximum": 65535,
"type": "integer"
"type": ["integer", "null"]
},
"console_type": {
"description": "Console type",
+1 -1
View File
@@ -178,7 +178,7 @@ class Hypervisor(UBridgeHypervisor):
env=env)
log.info("ubridge started PID={}".format(self._process.pid))
except (OSError, PermissionError, subprocess.SubprocessError) as e:
except (OSError, subprocess.SubprocessError) as e:
ubridge_stdout = self.read_stdout()
log.error("Could not start ubridge: {}\n{}".format(e, ubridge_stdout))
raise UbridgeError("Could not start ubridge: {}\n{}".format(e, ubridge_stdout))
+6 -4
View File
@@ -20,7 +20,7 @@ import time
import logging
import asyncio
from ..utils.asyncio import locked_coroutine
from ..utils.asyncio import locking
from .ubridge_error import UbridgeError
log = logging.getLogger(__name__)
@@ -69,7 +69,7 @@ class UBridgeHypervisor:
connection_success = False
last_exception = None
while time.time() - begin < timeout:
yield from asyncio.sleep(0.01)
yield from asyncio.sleep(0.1)
try:
self._reader, self._writer = yield from asyncio.open_connection(host, self._port)
except OSError as e:
@@ -84,6 +84,7 @@ class UBridgeHypervisor:
log.info("Connected to uBridge hypervisor after {:.4f} seconds".format(time.time() - begin))
try:
yield from asyncio.sleep(0.1)
version = yield from self.send("hypervisor version")
self._version = version[0].split("-", 1)[0]
except IndexError:
@@ -176,7 +177,8 @@ class UBridgeHypervisor:
self._host = host
@locked_coroutine
@locking
@asyncio.coroutine
def send(self, command):
"""
Sends commands to this hypervisor.
@@ -236,7 +238,7 @@ class UBridgeHypervisor:
.format(host=self._host, port=self._port, command=command, run=self.is_running()))
else:
retries += 1
yield from asyncio.sleep(0.1)
yield from asyncio.sleep(0.5)
continue
retries = 0
buf += chunk.decode("utf-8")
+27 -18
View File
@@ -108,7 +108,7 @@ def _check_process(process, termination_callback):
def monitor_process(process, termination_callback):
"""Call termination_callback when a process dies"""
asyncio.async(_check_process(process, termination_callback))
asyncio_ensure_future(_check_process(process, termination_callback))
@asyncio.coroutine
@@ -138,23 +138,32 @@ def wait_for_named_pipe_creation(pipe_path, timeout=60):
return
raise asyncio.TimeoutError()
#FIXME: Use the following wrapper when we drop Python 3.4 and use the async def syntax
# def locking(f):
#
# @wraps(f)
# async def wrapper(oself, *args, **kwargs):
# lock_name = "__" + f.__name__ + "_lock"
# if not hasattr(oself, lock_name):
# setattr(oself, lock_name, asyncio.Lock())
# async with getattr(oself, lock_name):
# return await f(oself, *args, **kwargs)
# return wrapper
def locked_coroutine(f):
"""
Method decorator that replace asyncio.coroutine that warranty
that this specific method of this class instance will not we
executed twice at the same time
"""
@asyncio.coroutine
def new_function(*args, **kwargs):
def locking(f):
# In the instance of the class we will store
# a lock has an attribute.
lock_var_name = "__" + f.__name__ + "_lock"
if not hasattr(args[0], lock_var_name):
setattr(args[0], lock_var_name, asyncio.Lock())
@functools.wraps(f)
def wrapper(oself, *args, **kwargs):
lock_name = "__" + f.__name__ + "_lock"
if not hasattr(oself, lock_name):
setattr(oself, lock_name, asyncio.Lock())
with (yield from getattr(oself, lock_name)):
return (yield from f(oself, *args, **kwargs))
return wrapper
with (yield from getattr(args[0], lock_var_name)):
return (yield from f(*args, **kwargs))
return new_function
#FIXME: conservative approach to supported versions, please remove it when we drop the support to Python < 3.4.4
try:
from asyncio import ensure_future
asyncio_ensure_future = asyncio.ensure_future
except ImportError:
asyncio_ensure_future = getattr(asyncio, 'async')
+7 -4
View File
@@ -198,8 +198,8 @@ class UnstoppableEventLoop(EventLoop):
class ShellConnection(TelnetConnection):
def __init__(self, reader, writer, shell, loop):
super(ShellConnection, self).__init__(reader, writer)
def __init__(self, reader, writer, shell, window_size_changed_callback, loop):
super(ShellConnection, self).__init__(reader, writer, window_size_changed_callback)
self._shell = shell
self._loop = loop
self._cli = None
@@ -239,9 +239,12 @@ class ShellConnection(TelnetConnection):
def disconnected(self):
pass
@asyncio.coroutine
def window_size_changed(self, columns, rows):
self._size = Size(rows=rows, columns=columns)
self._cb.terminal_size_changed()
if self._window_size_changed_callback:
yield from self._window_size_changed_callback(columns, rows)
@asyncio.coroutine
def feed(self, data):
@@ -291,8 +294,8 @@ def create_telnet_shell(shell, loop=None):
if loop is None:
loop = asyncio.get_event_loop()
def factory(reader, writer):
return ShellConnection(reader, writer, shell, loop)
def factory(reader, writer, window_size_changed_callback):
return ShellConnection(reader, writer, shell, window_size_changed_callback, loop)
return AsyncioTelnetServer(binary=True, echo=True, naws=True, connection_factory=factory)
@@ -20,6 +20,8 @@ import copy
import asyncio
import asyncio.subprocess
from gns3server.utils.asyncio import asyncio_ensure_future
import logging
log = logging.getLogger(__name__)
@@ -69,8 +71,8 @@ class AsyncioRawCommandServer:
else:
replaces.append((replace[0], replace[1], ))
network_read = asyncio.async(network_reader.read(READ_SIZE))
reader_read = asyncio.async(process_reader.read(READ_SIZE))
network_read = asyncio_ensure_future(network_reader.read(READ_SIZE))
reader_read = asyncio_ensure_future(process_reader.read(READ_SIZE))
timeout = 30
while True:
@@ -89,7 +91,7 @@ class AsyncioRawCommandServer:
if network_reader.at_eof():
raise ConnectionResetError()
network_read = asyncio.async(network_reader.read(READ_SIZE))
network_read = asyncio_ensure_future(network_reader.read(READ_SIZE))
process_writer.write(data)
yield from process_writer.drain()
@@ -97,7 +99,7 @@ class AsyncioRawCommandServer:
if process_reader.at_eof():
raise ConnectionResetError()
reader_read = asyncio.async(process_reader.read(READ_SIZE))
reader_read = asyncio_ensure_future(process_reader.read(READ_SIZE))
for replace in replaces:
data = data.replace(replace[0], replace[1])
+32 -22
View File
@@ -15,11 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
import asyncio
import asyncio.subprocess
import struct
from gns3server.utils.asyncio import asyncio_ensure_future
import logging
log = logging.getLogger(__name__)
@@ -60,10 +62,11 @@ READ_SIZE = 1024
class TelnetConnection(object):
"""Default implementation of telnet connection which may but may not be used."""
def __init__(self, reader, writer):
def __init__(self, reader, writer, window_size_changed_callback=None):
self.is_closing = False
self._reader = reader
self._writer = writer
self._window_size_changed_callback = window_size_changed_callback
@property
def reader(self):
@@ -83,10 +86,13 @@ class TelnetConnection(object):
"""Method called when client is disconnecting"""
pass
@asyncio.coroutine
def window_size_changed(self, columns, rows):
"""Method called when window size changed, only can occur when
`naws` flag is enable in server configuration."""
pass
if self._window_size_changed_callback:
yield from self._window_size_changed_callback(columns, rows)
@asyncio.coroutine
def feed(self, data):
@@ -114,7 +120,7 @@ class TelnetConnection(object):
class AsyncioTelnetServer:
MAX_NEGOTIATION_READ = 10
def __init__(self, reader=None, writer=None, binary=True, echo=False, naws=False, connection_factory=None):
def __init__(self, reader=None, writer=None, binary=True, echo=False, naws=False, window_size_changed_callback=None, connection_factory=None):
"""
Initializes telnet server
:param naws when True make a window size negotiation
@@ -129,6 +135,7 @@ class AsyncioTelnetServer:
self._lock = asyncio.Lock()
self._reader_process = None
self._current_read = None
self._window_size_changed_callback = window_size_changed_callback
self._binary = binary
# If echo is true when the client send data
@@ -137,8 +144,8 @@ class AsyncioTelnetServer:
self._echo = echo
self._naws = naws
def default_connection_factory(reader, writer):
return TelnetConnection(reader, writer)
def default_connection_factory(reader, writer, window_size_changed_callback):
return TelnetConnection(reader, writer, window_size_changed_callback)
if connection_factory is None:
connection_factory = default_connection_factory
@@ -188,18 +195,16 @@ class AsyncioTelnetServer:
@asyncio.coroutine
def run(self, network_reader, network_writer):
# Keep track of connected clients
connection = self._connection_factory(network_reader, network_writer)
connection = self._connection_factory(network_reader, network_writer, self._window_size_changed_callback)
self._connections[network_writer] = connection
try:
yield from self._write_intro(network_writer, echo=self._echo, binary=self._binary, naws=self._naws)
yield from connection.connected()
yield from self._process(network_reader, network_writer, connection)
except ConnectionResetError:
except ConnectionError:
with (yield from self._lock):
network_writer.close()
if self._reader_process == network_reader:
self._reader_process = None
# Cancel current read from this reader
@@ -212,9 +217,12 @@ class AsyncioTelnetServer:
@asyncio.coroutine
def close(self):
for writer, connection in self._connections.items():
writer.write_eof()
yield from writer.drain()
try:
writer.write_eof()
yield from writer.drain()
except (AttributeError, ConnectionError):
continue
@asyncio.coroutine
def client_connected_hook(self):
pass
@@ -229,13 +237,13 @@ class AsyncioTelnetServer:
self._reader_process = network_reader
if self._reader:
if self._reader_process == network_reader:
self._current_read = asyncio.async(self._reader.read(READ_SIZE))
self._current_read = asyncio_ensure_future(self._reader.read(READ_SIZE))
return self._current_read
return None
@asyncio.coroutine
def _process(self, network_reader, network_writer, connection):
network_read = asyncio.async(network_reader.read(READ_SIZE))
network_read = asyncio_ensure_future(network_reader.read(READ_SIZE))
reader_read = yield from self._get_reader(network_reader)
while True:
@@ -261,7 +269,7 @@ class AsyncioTelnetServer:
if network_reader.at_eof():
raise ConnectionResetError()
network_read = asyncio.async(network_reader.read(READ_SIZE))
network_read = asyncio_ensure_future(network_reader.read(READ_SIZE))
if IAC in data:
data = yield from self._IAC_parser(data, network_reader, network_writer, connection)
@@ -304,6 +312,7 @@ class AsyncioTelnetServer:
cmd.append(buffer[location])
return op
@asyncio.coroutine
def _negotiate(self, data, connection):
""" Performs negotiation commands"""
@@ -311,12 +320,13 @@ class AsyncioTelnetServer:
if command == NAWS:
if len(payload) == 4:
columns, rows = struct.unpack(str('!HH'), bytes(payload))
connection.window_size_changed(columns, rows)
yield from connection.window_size_changed(columns, rows)
else:
log.warning('Wrong number of NAWS bytes')
else:
log.debug("Not supported negotiation sequence, received {} bytes", len(data))
@asyncio.coroutine
def _IAC_parser(self, buf, network_reader, network_writer, connection):
"""
Processes and removes any Telnet commands from the buffer.
@@ -369,7 +379,7 @@ class AsyncioTelnetServer:
break
# SE command is followed by IAC, remove the last two operations from stack
self._negotiate(negotiation[0:-2], connection)
yield from self._negotiate(negotiation[0:-2], connection)
# This must be a 3-byte TELNET command
else:
@@ -418,10 +428,10 @@ if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
loop = asyncio.get_event_loop()
process = loop.run_until_complete(asyncio.async(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)))
process = loop.run_until_complete(asyncio_ensure_future(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)))
server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=False, echo=False)
coro = asyncio.start_server(server.run, '127.0.0.1', 4444, loop=loop)
+21 -8
View File
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
import io
import struct
from xml.etree.ElementTree import ElementTree, ParseError
@@ -103,13 +104,21 @@ def get_size(data, default_width=0, default_height=0):
root = tree.getroot()
try:
width_attr = root.attrib.get("width", "0")
height_attr = root.attrib.get("height", "0")
width_attr = root.attrib.get("width", "100%")
height_attr = root.attrib.get("height", "100%")
if width_attr.endswith("%") or height_attr.endswith("%"):
# check to viewBox attribute if width or height value is a percentage
_, _, width_attr, height_attr = root.attrib.get("viewBox").split()
viewbox = root.attrib.get("viewBox")
if not viewbox:
raise ValueError("Invalid SVG file: missing viewBox attribute")
_, _, viewbox_width, viewbox_height = re.split(r'[\s,]+', viewbox)
if width_attr.endswith("%"):
width = _svg_convert_size(viewbox_width, width_attr)
else:
width = _svg_convert_size(width_attr)
if height_attr.endswith("%"):
height = _svg_convert_size(viewbox_height, height_attr)
else:
height = _svg_convert_size(height_attr)
except (AttributeError, IndexError) as e:
raise ValueError("Invalid SVG file: {}".format(e))
@@ -117,11 +126,12 @@ def get_size(data, default_width=0, default_height=0):
return width, height, filetype
def _svg_convert_size(size):
def _svg_convert_size(size, percent=None):
"""
Convert svg size to the px version
:param size: String with the size
:param percent: String with the percentage, None = 100%
"""
# https://www.w3.org/TR/SVG/coords.html#Units
@@ -133,8 +143,11 @@ def _svg_convert_size(size):
"in": 90,
"px": 1
}
if len(size) > 3:
factor = 1.0
if len(size) >= 3:
if size[-2:] in conversion_table:
return round(float(size[:-2]) * conversion_table[size[-2:]])
return round(float(size))
factor = conversion_table[size[-2:]]
size = size[:-2]
if percent:
factor *= float(percent.rstrip("%")) / 100.0
return round(float(size) * factor)
+10 -2
View File
@@ -43,8 +43,16 @@ class PingStats:
cur_time > cls._last_measurement + 1.9:
cls._last_measurement = cur_time
# Non blocking call to get cpu usage. First call will return 0
cls._last_cpu_percent = psutil.cpu_percent(interval=None)
cls._last_mem_percent = psutil.virtual_memory().percent
try:
cls._last_cpu_percent = psutil.cpu_percent(interval=None)
cls._last_mem_percent = psutil.virtual_memory().percent
except RuntimeError:
# ignore the following error:
# RuntimeError: host_statistics(HOST_CPU_LOAD_INFO) syscall failed: (ipc/send) invalid reply port
pass
except PermissionError:
# [Errno 13] Permission denied: '/proc/stat'
pass
stats["cpu_usage_percent"] = cls._last_cpu_percent
stats["memory_usage_percent"] = cls._last_mem_percent
return stats
+2 -2
View File
@@ -23,8 +23,8 @@
# or negative for a release candidate or beta (after the base version
# number has been incremented)
__version__ = "2.1.9"
__version_info__ = (2, 1, 9, 0)
__version__ = "2.1.18"
__version_info__ = (2, 1, 18, 0)
# If it's a git checkout try to add the commit
if "dev" in __version__:
+5
View File
@@ -225,6 +225,11 @@ class Route(object):
response = Response(request=request, route=route)
response.set_status(408)
response.json({"message": "Client error", "status": 408})
except MemoryError:
log.error("Memory error detected, server has run out of memory!", exc_info=1)
response = Response(request=request, route=route)
response.set_status(500)
response.json({"message": "Memory error", "status": 500})
except Exception as e:
log.error("Uncaught exception detected: {type}".format(type=type(e)), exc_info=1)
response = Response(request=request, route=route)
+15 -4
View File
@@ -29,12 +29,17 @@ import functools
import time
import atexit
# Import encoding now, to avoid implicit import later.
# Implicit import within threads may cause LookupError when standard library is in a ZIP
import encodings.idna
from .route import Route
from ..config import Config
from ..compute import MODULES
from ..compute.port_manager import PortManager
from ..compute.qemu import Qemu
from ..controller import Controller
from ..utils.asyncio import asyncio_ensure_future
# do not delete this import
import gns3server.handlers
@@ -136,7 +141,10 @@ class WebServer:
def signal_handler(signame, *args):
log.warning("Server has got signal {}, exiting...".format(signame))
asyncio.async(self.shutdown_server())
try:
asyncio_ensure_future(self.shutdown_server())
except asyncio.CancelledError:
pass
signals = ["SIGTERM", "SIGINT"]
if sys.platform.startswith("win"):
@@ -203,7 +211,7 @@ class WebServer:
# Because with a large image collection
# without md5sum already computed we start the
# computing with server start
asyncio.async(Qemu.instance().list_images())
asyncio_ensure_future(Qemu.instance().list_images())
def run(self):
"""
@@ -283,7 +291,7 @@ class WebServer:
self._exit_handling()
if server_config.getboolean("shell"):
asyncio.async(self.start_shell())
asyncio_ensure_future(self.start_shell())
try:
self._loop.run_forever()
@@ -294,4 +302,7 @@ class WebServer:
log.warning("TypeError exception in the loop {}".format(e))
finally:
if self._loop.is_running():
self._loop.run_until_complete(self.shutdown_server())
try:
self._loop.run_until_complete(self.shutdown_server())
except asyncio.CancelledError:
pass
+3 -3
View File
@@ -1,5 +1,5 @@
jsonschema>=2.4.0
aiohttp>=2.2.0,<2.4.0 # pyup: ignore
jsonschema==2.6.0
aiohttp>=2.3.3,<2.4.0 # pyup: ignore
aiohttp-cors>=0.5.3,<0.6.0 # pyup: ignore
yarl>=0.11
Jinja2>=2.7.3
@@ -8,4 +8,4 @@ psutil>=3.0.0
zipstream>=1.1.4
typing>=3.5.3.0 # Otherwise yarl fails with python 3.4
prompt-toolkit==1.0.15
async-timeout<3.0.0 # pyup: ignore; 3.0 drops support for python 3.4
async-timeout<3.0.0 # pyup: ignore; 3.0 drops support for python 3.4
+6 -2
View File
@@ -62,17 +62,21 @@ setup(
zip_safe=False,
platforms="any",
classifiers=[
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Information Technology",
"Topic :: System :: Networking",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
],
)
+8 -8
View File
@@ -45,7 +45,7 @@ def test_query_success(loop, vm):
response.read.side_effect = read
vm._session.request = AsyncioMagicMock(return_value=response)
data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
data = loop.run_until_complete(asyncio.ensure_future(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
vm._session.request.assert_called_with('POST',
'http://docker/v1.25/test',
data='{"a": true}',
@@ -68,7 +68,7 @@ def test_query_error(loop, vm):
response.read.side_effect = read
vm._session.request = AsyncioMagicMock(return_value=response)
with pytest.raises(DockerError):
data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
data = loop.run_until_complete(asyncio.ensure_future(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
vm._session.request.assert_called_with('POST',
'http://docker/v1.25/test',
data='{"a": true}',
@@ -89,7 +89,7 @@ def test_query_error_json(loop, vm):
response.read.side_effect = read
vm._session.request = AsyncioMagicMock(return_value=response)
with pytest.raises(DockerError):
data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
data = loop.run_until_complete(asyncio.ensure_future(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
vm._session.request.assert_called_with('POST',
'http://docker/v1.25/test',
data='{"a": true}',
@@ -126,7 +126,7 @@ def test_list_images(loop):
]
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
images = loop.run_until_complete(asyncio.async(Docker.instance().list_images()))
images = loop.run_until_complete(asyncio.ensure_future(Docker.instance().list_images()))
mock.assert_called_with("GET", "images/json", params={"all": 0})
assert len(images) == 5
assert {"image": "ubuntu:12.04"} in images
@@ -160,7 +160,7 @@ def test_pull_image(loop):
with asyncio_patch("gns3server.compute.docker.Docker.query", side_effect=DockerHttp404Error("404")):
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
images = loop.run_until_complete(asyncio.async(Docker.instance().pull_image("ubuntu")))
images = loop.run_until_complete(asyncio.ensure_future(Docker.instance().pull_image("ubuntu")))
mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}, timeout=None)
@@ -174,7 +174,7 @@ def test_docker_check_connection_docker_minimum_version(vm, loop):
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
vm._connected = False
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm._check_connection()))
loop.run_until_complete(asyncio.ensure_future(vm._check_connection()))
def test_docker_check_connection_docker_preferred_version_against_newer(vm, loop):
@@ -185,7 +185,7 @@ def test_docker_check_connection_docker_preferred_version_against_newer(vm, loop
with patch("gns3server.compute.docker.Docker.connector"), \
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
vm._connected = False
loop.run_until_complete(asyncio.async(vm._check_connection()))
loop.run_until_complete(asyncio.ensure_future(vm._check_connection()))
assert vm._api_version == DOCKER_PREFERRED_API_VERSION
@@ -197,5 +197,5 @@ def test_docker_check_connection_docker_preferred_version_against_older(vm, loop
with patch("gns3server.compute.docker.Docker.connector"), \
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
vm._connected = False
loop.run_until_complete(asyncio.async(vm._check_connection()))
loop.run_until_complete(asyncio.ensure_future(vm._check_connection()))
assert vm._api_version == DOCKER_MINIMUM_API_VERSION
+60 -61
View File
@@ -87,7 +87,7 @@ def test_create(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
mock.assert_called_with("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@@ -126,7 +126,7 @@ def test_create_with_tag(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:16.04")
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
mock.assert_called_with("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@@ -168,7 +168,7 @@ def test_create_vnc(loop, project, manager):
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc", console=5900)
vm._start_vnc = MagicMock()
vm._display = 42
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
mock.assert_called_with("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@@ -214,7 +214,7 @@ def test_create_with_extra_hosts(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", extra_hosts=extra_hosts)
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
called_kwargs = mock.call_args[1]
assert "GNS3_EXTRA_HOSTS=199.199.199.1\ttest\n199.199.199.1\ttest2" in called_kwargs["data"]["Env"]
assert vm._extra_hosts == extra_hosts
@@ -232,7 +232,7 @@ def test_create_with_extra_hosts_wrong_format(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", extra_hosts=extra_hosts)
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
def test_create_with_empty_extra_hosts(loop, project, manager):
@@ -246,7 +246,7 @@ def test_create_with_empty_extra_hosts(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", extra_hosts=extra_hosts)
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
called_kwargs = mock.call_args[1]
assert len([ e for e in called_kwargs["data"]["Env"] if "GNS3_EXTRA_HOSTS" in e]) == 0
@@ -266,7 +266,7 @@ def test_create_with_project_variables(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
called_kwargs = mock.call_args[1]
assert "VAR1=" in called_kwargs["data"]["Env"]
assert "VAR2=VAL1" in called_kwargs["data"]["Env"]
@@ -284,7 +284,7 @@ def test_create_start_cmd(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
vm._start_command = "/bin/ls"
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
mock.assert_called_with("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@@ -328,7 +328,7 @@ def test_create_environment(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2"
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
assert mock.call_args[1]['data']['Env'] == [
"container=docker",
"GNS3_MAX_ETHERNET=eth0",
@@ -352,7 +352,7 @@ def test_create_environment_with_last_new_line_character(loop, project, manager)
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2\n"
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
assert mock.call_args[1]['data']['Env'] == [
"container=docker",
"GNS3_MAX_ETHERNET=eth0",
@@ -385,7 +385,7 @@ def test_create_image_not_available(loop, project, manager):
vm._get_image_information.side_effect = information
with asyncio_patch("gns3server.compute.docker.DockerVM.pull_image", return_value=True) as mock_pull:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
mock.assert_called_with("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@@ -431,17 +431,17 @@ def test_get_container_state(loop, vm):
}
}
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "running"
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "running"
response["State"]["Running"] = False
response["State"]["Paused"] = True
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "paused"
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "paused"
response["State"]["Running"] = False
response["State"]["Paused"] = False
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "exited"
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "exited"
def test_is_running(loop, vm):
@@ -452,17 +452,17 @@ def test_is_running(loop, vm):
}
}
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.async(vm.is_running())) is False
assert loop.run_until_complete(asyncio.ensure_future(vm.is_running())) is False
response["State"]["Running"] = True
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.async(vm.is_running())) is True
assert loop.run_until_complete(asyncio.ensure_future(vm.is_running())) is True
def test_pause(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
loop.run_until_complete(asyncio.async(vm.pause()))
loop.run_until_complete(asyncio.ensure_future(vm.pause()))
mock.assert_called_with("POST", "containers/e90e34656842/pause")
assert vm.status == "suspended"
@@ -471,7 +471,7 @@ def test_pause(loop, vm):
def test_unpause(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
loop.run_until_complete(asyncio.async(vm.unpause()))
loop.run_until_complete(asyncio.ensure_future(vm.unpause()))
mock.assert_called_with("POST", "containers/e90e34656842/unpause")
@@ -491,10 +491,10 @@ def test_start(loop, vm, manager, free_console_port):
vm._start_console = AsyncioMagicMock()
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
vm._add_ubridge_connection.assert_called_once_with(nio, 0)
@@ -510,7 +510,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
vm.adapters = 1
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
@@ -520,7 +520,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_log", return_value='Hello not available') as mock_log:
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
mock_query.assert_any_call("POST", "containers/e90e34656842/start")
mock_add_ubridge_connection.assert_called_once_with(nio, 0)
@@ -542,7 +542,7 @@ def test_start_without_nio(loop, vm, manager, free_console_port):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
with asyncio_patch("gns3server.compute.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection:
with asyncio_patch("gns3server.compute.docker.DockerVM._start_console") as mock_start_console:
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
assert mock_add_ubridge_connection.called
@@ -555,7 +555,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock:
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert mock.called
assert vm.status == "started"
@@ -563,7 +563,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
def test_restart(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
loop.run_until_complete(asyncio.async(vm.restart()))
loop.run_until_complete(asyncio.ensure_future(vm.restart()))
mock.assert_called_with("POST", "containers/e90e34656842/restart")
@@ -576,7 +576,7 @@ def test_stop(loop, vm):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.stop()))
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
assert mock.stop.called
assert vm._ubridge_hypervisor is None
@@ -588,7 +588,7 @@ def test_stop_paused_container(loop, vm):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause") as mock_unpause:
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.stop()))
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
assert mock_unpause.called
@@ -606,7 +606,7 @@ def test_update(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update()))
loop.run_until_complete(asyncio.ensure_future(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={
@@ -656,7 +656,7 @@ def test_update_vnc(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update()))
loop.run_until_complete(asyncio.ensure_future(vm.update()))
assert vm.console == original_console
assert vm.aux == original_aux
@@ -675,7 +675,7 @@ def test_update_running(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update()))
loop.run_until_complete(asyncio.ensure_future(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={
@@ -713,7 +713,7 @@ def test_delete(loop, vm):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.delete()))
loop.run_until_complete(asyncio.ensure_future(vm.delete()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
@@ -723,11 +723,11 @@ def test_close(loop, vm, port_manager):
"rport": 4343,
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.close()))
loop.run_until_complete(asyncio.ensure_future(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True
@@ -742,7 +742,7 @@ def test_close_vnc(loop, vm, port_manager):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.close()))
loop.run_until_complete(asyncio.ensure_future(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True
@@ -756,7 +756,7 @@ def test_get_namespace(loop, vm):
}
}
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
assert loop.run_until_complete(asyncio.async(vm._get_namespace())) == 42
assert loop.run_until_complete(asyncio.ensure_future(vm._get_namespace())) == 42
mock_query.assert_called_with("GET", "containers/e90e34656842/json")
@@ -771,7 +771,7 @@ def test_add_ubridge_connection(loop, vm):
vm._ubridge_hypervisor = MagicMock()
vm._namespace = 42
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0)))
calls = [
call.send('bridge create bridge0'),
@@ -792,7 +792,7 @@ def test_add_ubridge_connection_none_nio(loop, vm):
vm._ubridge_hypervisor = MagicMock()
vm._namespace = 42
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0)))
calls = [
call.send('bridge create bridge0'),
@@ -813,7 +813,7 @@ def test_add_ubridge_connection_invalid_adapter_number(loop, vm):
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 12)))
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 12)))
def test_add_ubridge_connection_no_free_interface(loop, vm):
@@ -829,7 +829,7 @@ def test_add_ubridge_connection_no_free_interface(loop, vm):
interfaces = ["tap-gns3-e{}".format(index) for index in range(4096)]
with patch("psutil.net_if_addrs", return_value=interfaces):
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0)))
def test_adapter_add_nio_binding(vm, loop):
@@ -838,7 +838,7 @@ def test_adapter_add_nio_binding(vm, loop):
"rport": 4343,
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
assert vm._ethernet_adapters[0].get_nio(0) == nio
@@ -853,9 +853,9 @@ def test_adapter_udpate_nio_binding(vm, loop):
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.async(vm.adapter_update_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_update_nio_binding(0, nio)))
assert vm._ubridge_apply_filters.called
@@ -867,9 +867,9 @@ def test_adapter_udpate_nio_binding_bridge_not_started(vm, loop):
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.async(vm.adapter_update_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_update_nio_binding(0, nio)))
assert vm._ubridge_apply_filters.called is False
@@ -880,7 +880,7 @@ def test_adapter_add_nio_binding_invalid_adapter(vm, loop):
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(12, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(12, nio)))
def test_adapter_remove_nio_binding(vm, loop):
@@ -892,10 +892,10 @@ def test_adapter_remove_nio_binding(vm, loop):
"rport": 4343,
"rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio)
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
with asyncio_patch("gns3server.compute.docker.DockerVM._ubridge_send") as delete_ubridge_mock:
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(0)))
assert vm._ethernet_adapters[0].get_nio(0) is None
delete_ubridge_mock.assert_any_call('bridge stop bridge0')
delete_ubridge_mock.assert_any_call('bridge remove_nio_udp bridge0 4242 127.0.0.1 4343')
@@ -903,15 +903,15 @@ def test_adapter_remove_nio_binding(vm, loop):
def test_adapter_remove_nio_binding_invalid_adapter(vm, loop):
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(12)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(12)))
def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap")
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.async(vm.start_capture(0, output_file)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, output_file)))
assert vm._ethernet_adapters[0].get_nio(0).capturing
@@ -919,10 +919,10 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap")
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(vm.start_capture(0, output_file))
assert vm._ethernet_adapters[0].get_nio(0).capturing
loop.run_until_complete(asyncio.async(vm.stop_capture(0)))
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0)))
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
@@ -935,7 +935,7 @@ def test_get_log(loop, vm):
mock_query.read = read
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
images = loop.run_until_complete(asyncio.async(vm._get_log()))
images = loop.run_until_complete(asyncio.ensure_future(vm._get_log()))
mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={})
@@ -944,7 +944,7 @@ def test_get_image_informations(project, manager, loop):
}
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
loop.run_until_complete(asyncio.async(vm._get_image_information()))
loop.run_until_complete(asyncio.ensure_future(vm._get_image_information()))
mock.assert_called_with("GET", "images/ubuntu:latest/json")
@@ -971,25 +971,24 @@ def test_mount_binds(vm, tmpdir):
def test_start_vnc(vm, loop):
vm.console_resolution = "1280x1024"
with patch("shutil.which", return_value="/bin/x"):
with patch("shutil.which", return_value="/bin/Xtigervnc"):
with asyncio_patch("gns3server.compute.docker.docker_vm.wait_for_file_creation") as mock_wait:
with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec:
loop.run_until_complete(asyncio.async(vm._start_vnc()))
loop.run_until_complete(asyncio.ensure_future(vm._start_vnc()))
assert vm._display is not None
mock_exec.assert_any_call("Xvfb", "-nolisten", "tcp", ":{}".format(vm._display), "-screen", "0", "1280x1024x16")
mock_exec.assert_any_call("x11vnc", "-forever", "-nopw", "-shared", "-geometry", "1280x1024", "-display", "WAIT:{}".format(vm._display), "-rfbport", str(vm.console), "-rfbportv6", str(vm.console), "-noncache", "-listen", "127.0.0.1")
assert mock_exec.call_args[0] == ("Xtigervnc", "-geometry", vm.console_resolution, "-depth", "16", "-interface", "127.0.0.1", "-rfbport", str(vm.console), "-AlwaysShared", "-SecurityTypes", "None", ":{}".format(vm._display))
mock_wait.assert_called_with("/tmp/.X11-unix/X{}".format(vm._display))
def test_start_vnc_xvfb_missing(vm, loop):
with pytest.raises(DockerError):
loop.run_until_complete(asyncio.async(vm._start_vnc()))
loop.run_until_complete(asyncio.ensure_future(vm._start_vnc()))
def test_start_aux(vm, loop):
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
loop.run_until_complete(asyncio.async(vm._start_aux()))
loop.run_until_complete(asyncio.ensure_future(vm._start_aux()))
mock_exec.assert_called_with('docker', 'exec', '-i', 'e90e34656842', '/gns3/bin/busybox', 'script', '-qfc', 'while true; do TERM=vt100 /gns3/bin/busybox sh; done', '/dev/null', stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
@@ -1051,5 +1050,5 @@ def test_read_console_output_with_binary_mode(vm, loop):
output_stream = MagicMock()
with asyncio_patch('gns3server.compute.docker.docker_vm.DockerVM.stop'):
loop.run_until_complete(asyncio.async(vm._read_console_output(input_stream, output_stream)))
loop.run_until_complete(asyncio.ensure_future(vm._read_console_output(input_stream, output_stream)))
output_stream.feed_data.assert_called_once_with(b"test")
@@ -70,6 +70,6 @@ def test_router_invalid_dynamips_path(project, manager, loop):
with pytest.raises(DynamipsError):
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
loop.run_until_complete(asyncio.async(router.create()))
loop.run_until_complete(asyncio.ensure_future(router.create()))
assert router.name == "test"
assert router.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
+23 -23
View File
@@ -101,7 +101,7 @@ def test_start(loop, vm):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as mock_exec:
mock_process.returncode = None
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
@@ -129,7 +129,7 @@ def test_start_with_iourc(loop, vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file}):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as exec_mock:
mock_process.returncode = None
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.is_running()
arsgs, kwargs = exec_mock.call_args
assert kwargs["env"]["IOURC"] == fake_file
@@ -167,10 +167,10 @@ def test_stop(loop, vm):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
process.returncode = None
assert vm.is_running()
loop.run_until_complete(asyncio.async(vm.stop()))
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
assert vm.is_running() is False
process.terminate.assert_called_with()
@@ -192,9 +192,9 @@ def test_reload(loop, vm, fake_iou_bin):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.is_running()
loop.run_until_complete(asyncio.async(vm.reload()))
loop.run_until_complete(asyncio.ensure_future(vm.reload()))
assert vm.is_running() is True
process.terminate.assert_called_with()
@@ -204,7 +204,7 @@ def test_close(vm, port_manager, loop):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
vm.start()
port = vm.console
loop.run_until_complete(asyncio.async(vm.close()))
loop.run_until_complete(asyncio.ensure_future(vm.close()))
# Raise an exception if the port is not free
port_manager.reserve_tcp_port(port, vm.project)
assert vm.is_running() is False
@@ -249,7 +249,7 @@ def test_create_netmap_config(vm):
def test_build_command(vm, loop):
assert loop.run_until_complete(asyncio.async(vm._build_command())) == [vm.path, str(vm.application_id)]
assert loop.run_until_complete(asyncio.ensure_future(vm._build_command())) == [vm.path, str(vm.application_id)]
def test_get_startup_config(vm):
@@ -311,11 +311,11 @@ def test_library_check(loop, vm):
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="") as mock:
loop.run_until_complete(asyncio.async(vm._library_check()))
loop.run_until_complete(asyncio.ensure_future(vm._library_check()))
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="libssl => not found") as mock:
with pytest.raises(IOUError):
loop.run_until_complete(asyncio.async(vm._library_check()))
loop.run_until_complete(asyncio.ensure_future(vm._library_check()))
def test_enable_l1_keepalives(loop, vm):
@@ -323,14 +323,14 @@ def test_enable_l1_keepalives(loop, vm):
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-l Enable Layer 1 keepalive messages\n-u <n> UDP port base for distributed networks\n") as mock:
command = ["test"]
loop.run_until_complete(asyncio.async(vm._enable_l1_keepalives(command)))
loop.run_until_complete(asyncio.ensure_future(vm._enable_l1_keepalives(command)))
assert command == ["test", "-l"]
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-u <n> UDP port base for distributed networks\n") as mock:
command = ["test"]
with pytest.raises(IOUError):
loop.run_until_complete(asyncio.async(vm._enable_l1_keepalives(command)))
loop.run_until_complete(asyncio.ensure_future(vm._enable_l1_keepalives(command)))
assert command == ["test"]
@@ -338,8 +338,8 @@ def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap")
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, 0, nio)))
loop.run_until_complete(asyncio.async(vm.start_capture(0, 0, output_file)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, 0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, 0, output_file)))
assert vm._adapters[0].get_nio(0).capturing
@@ -347,10 +347,10 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap")
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, 0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, 0, nio)))
loop.run_until_complete(vm.start_capture(0, 0, output_file))
assert vm._adapters[0].get_nio(0).capturing
loop.run_until_complete(asyncio.async(vm.stop_capture(0, 0)))
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0, 0)))
assert vm._adapters[0].get_nio(0).capturing is False
@@ -363,42 +363,42 @@ def test_invalid_iou_file(loop, vm, iourc_file):
hostname = socket.gethostname()
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
# Missing ;
with pytest.raises(IOUError):
with open(iourc_file, "w+") as f:
f.write("[license]\n{} = aaaaaaaaaaaaaaaa".format(hostname))
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
# Key too short
with pytest.raises(IOUError):
with open(iourc_file, "w+") as f:
f.write("[license]\n{} = aaaaaaaaaaaaaa;".format(hostname))
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
# Invalid hostname
with pytest.raises(IOUError):
with open(iourc_file, "w+") as f:
f.write("[license]\nbla = aaaaaaaaaaaaaa;")
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
# Missing licence section
with pytest.raises(IOUError):
with open(iourc_file, "w+") as f:
f.write("[licensetest]\n{} = aaaaaaaaaaaaaaaa;")
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
# Broken config file
with pytest.raises(IOUError):
with open(iourc_file, "w+") as f:
f.write("[")
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
# Missing file
with pytest.raises(IOUError):
os.remove(iourc_file)
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
def test_iourc_content(vm):
+1 -1
View File
@@ -69,5 +69,5 @@ def test_rebase(tmpdir, loop):
qcow2 = Qcow2(str(tmpdir / "linked.qcow2"))
assert qcow2.version == 3
assert qcow2.backing_file == "empty8G.qcow2"
loop.run_until_complete(asyncio.async(qcow2.rebase(qemu_img(), str(tmpdir / "empty16G.qcow2"))))
loop.run_until_complete(asyncio.ensure_future(qcow2.rebase(qemu_img(), str(tmpdir / "empty16G.qcow2"))))
assert qcow2.backing_file == str(tmpdir / "empty16G.qcow2")
+11 -11
View File
@@ -41,7 +41,7 @@ def fake_qemu_img_binary(tmpdir):
def test_get_qemu_version(loop):
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
version = loop.run_until_complete(asyncio.async(Qemu.get_qemu_version("/tmp/qemu-test")))
version = loop.run_until_complete(asyncio.ensure_future(Qemu.get_qemu_version("/tmp/qemu-test")))
if sys.platform.startswith("win"):
assert version == ""
else:
@@ -64,7 +64,7 @@ def test_binary_list(loop):
else:
version = "2.2.0"
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list()))
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.binary_list()))
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} in qemus
@@ -72,14 +72,14 @@ def test_binary_list(loop):
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86_64-spice"), "version": version} not in qemus
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list(["x86"])))
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.binary_list(["x86"])))
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} not in qemus
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list(["x86", "x42"])))
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.binary_list(["x86", "x42"])))
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
@@ -98,7 +98,7 @@ def test_img_binary_list(loop):
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
qemus = loop.run_until_complete(asyncio.async(Qemu.img_binary_list()))
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.img_binary_list()))
version = "2.2.0"
@@ -125,7 +125,7 @@ def test_create_image_abs_path(loop, tmpdir, fake_qemu_img_binary):
"size": 100
}
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, str(tmpdir / "hda.qcow2"), options)))
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(fake_qemu_img_binary, str(tmpdir / "hda.qcow2"), options)))
args, kwargs = process.call_args
assert args == (
fake_qemu_img_binary,
@@ -152,7 +152,7 @@ def test_create_image_relative_path(loop, tmpdir, fake_qemu_img_binary):
}
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
args, kwargs = process.call_args
assert args == (
fake_qemu_img_binary,
@@ -174,7 +174,7 @@ def test_create_image_exist(loop, tmpdir, fake_qemu_img_binary):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
with pytest.raises(QemuError):
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
assert not process.called
@@ -193,7 +193,7 @@ def test_create_image_with_not_supported_characters_by_filesystem(loop, tmpdir,
patch("os.makedirs"):
with pytest.raises(QemuError):
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(
fake_qemu_img_binary, "hda.qcow2", options)))
assert not process.called
@@ -201,12 +201,12 @@ def test_create_image_with_not_supported_characters_by_filesystem(loop, tmpdir,
def test_get_kvm_archs_kvm_ok(loop):
with patch("os.path.exists", return_value=True):
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
archs = loop.run_until_complete(asyncio.ensure_future(Qemu.get_kvm_archs()))
if platform.machine() == 'x86_64':
assert archs == ['x86_64', 'i386']
else:
assert archs == [platform.machine()]
with patch("os.path.exists", return_value=False):
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
archs = loop.run_until_complete(asyncio.ensure_future(Qemu.get_kvm_archs()))
assert archs == []
+91 -39
View File
@@ -116,9 +116,10 @@ def test_is_running(vm, running_subprocess_mock):
def test_start(loop, vm, running_subprocess_mock):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock) as mock:
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.is_running()
assert vm.command_line == ' '.join(mock.call_args[0])
@@ -130,14 +131,15 @@ def test_stop(loop, vm, running_subprocess_mock):
future = asyncio.Future()
future.set_result(True)
process.wait.return_value = future
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.adapter_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.is_running()
loop.run_until_complete(asyncio.async(vm.stop()))
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
assert vm.is_running() is False
process.terminate.assert_called_with()
@@ -150,9 +152,9 @@ def test_termination_callback(vm, async_run):
async_run(vm._termination_callback(0))
assert vm.status == "stopped"
async_run(queue.get(0)) #  Ping
async_run(queue.get(1)) #  Ping
(action, event, kwargs) = async_run(queue.get(0))
(action, event, kwargs) = async_run(queue.get(1))
assert action == "node.updated"
assert event == vm
@@ -170,7 +172,7 @@ def test_termination_callback_error(vm, tmpdir, async_run):
async_run(vm._termination_callback(1))
assert vm.status == "stopped"
async_run(queue.get(0)) # Ping
async_run(queue.get(1)) # Ping
(action, event, kwargs) = queue.get_nowait()
assert action == "node.updated"
@@ -184,7 +186,7 @@ def test_termination_callback_error(vm, tmpdir, async_run):
def test_reload(loop, vm):
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as mock:
loop.run_until_complete(asyncio.async(vm.reload()))
loop.run_until_complete(asyncio.ensure_future(vm.reload()))
assert mock.called_with("system_reset")
@@ -193,33 +195,34 @@ def test_suspend(loop, vm):
control_vm_result = MagicMock()
control_vm_result.match.group.decode.return_value = "running"
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock:
loop.run_until_complete(asyncio.async(vm.suspend()))
loop.run_until_complete(asyncio.ensure_future(vm.suspend()))
assert mock.called_with("system_reset")
def test_add_nio_binding_udp(vm, loop):
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
assert nio.lport == 4242
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
assert nio.lport == 4242
def test_port_remove_nio_binding(vm, loop):
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(0)))
assert vm._ethernet_adapters[0].ports[0] is None
def test_close(vm, port_manager, loop):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
console_port = vm.console
loop.run_until_complete(asyncio.async(vm.close()))
loop.run_until_complete(asyncio.ensure_future(vm.close()))
# Raise an exception if the port is not free
port_manager.reserve_tcp_port(console_port, vm.project)
@@ -328,7 +331,7 @@ def test_disk_options(vm, tmpdir, loop, fake_qemu_img_binary):
open(vm._hda_disk_image, "w+").close()
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
options = loop.run_until_complete(asyncio.async(vm._disk_options()))
options = loop.run_until_complete(asyncio.ensure_future(vm._disk_options()))
assert process.called
args, kwargs = process.call_args
assert args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hda_disk_image), "-f", "qcow2", os.path.join(vm.working_dir, "hda_disk.qcow2"))
@@ -338,20 +341,22 @@ def test_disk_options(vm, tmpdir, loop, fake_qemu_img_binary):
def test_cdrom_option(vm, tmpdir, loop, fake_qemu_img_binary):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
vm._cdrom_image = str(tmpdir / "test.iso")
open(vm._cdrom_image, "w+").close()
options = loop.run_until_complete(asyncio.async(vm._build_command()))
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert ' '.join(['-cdrom', str(tmpdir / "test.iso")]) in ' '.join(options)
def test_bios_option(vm, tmpdir, loop, fake_qemu_img_binary):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
vm._bios_image = str(tmpdir / "test.img")
open(vm._bios_image, "w+").close()
options = loop.run_until_complete(asyncio.async(vm._build_command()))
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert ' '.join(['-bios', str(tmpdir / "test.img")]) in ' '.join(options)
@@ -359,14 +364,14 @@ def test_bios_option(vm, tmpdir, loop, fake_qemu_img_binary):
def test_vnc_option(vm, tmpdir, loop, fake_qemu_img_binary):
vm._console_type = 'vnc'
vm._console = 5905
options = loop.run_until_complete(asyncio.async(vm._build_command()))
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert '-vnc 127.0.0.1:5' in ' '.join(options)
def test_spice_option(vm, tmpdir, loop, fake_qemu_img_binary):
vm._console_type = 'spice'
vm._console = 5905
options = loop.run_until_complete(asyncio.async(vm._build_command()))
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert '-spice addr=127.0.0.1,port=5905,disable-ticketing' in ' '.join(options)
assert '-vga qxl' in ' '.join(options)
@@ -383,7 +388,7 @@ def test_disk_options_multiple_disk(vm, tmpdir, loop, fake_qemu_img_binary):
open(vm._hdd_disk_image, "w+").close()
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
options = loop.run_until_complete(asyncio.async(vm._disk_options()))
options = loop.run_until_complete(asyncio.ensure_future(vm._disk_options()))
assert options == [
'-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk',
@@ -400,7 +405,7 @@ def test_set_process_priority(vm, loop, fake_qemu_img_binary):
vm._process = MagicMock()
vm._process.pid = 42
vm._process_priority = "low"
loop.run_until_complete(asyncio.async(vm._set_process_priority()))
loop.run_until_complete(asyncio.ensure_future(vm._set_process_priority()))
assert process.called
args, kwargs = process.call_args
assert args == ("renice", "-n", "5", "-p", "42")
@@ -412,7 +417,7 @@ def test_set_process_priority_normal(vm, loop, fake_qemu_img_binary):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
vm._process = MagicMock()
vm._process.pid = 42
loop.run_until_complete(asyncio.async(vm._set_process_priority()))
loop.run_until_complete(asyncio.ensure_future(vm._set_process_priority()))
assert not process.called
@@ -429,7 +434,7 @@ def test_control_vm(vm, loop):
reader = MagicMock()
writer = MagicMock()
with asyncio_patch("asyncio.open_connection", return_value=(reader, writer)) as open_connect:
res = loop.run_until_complete(asyncio.async(vm._control_vm("test")))
res = loop.run_until_complete(asyncio.ensure_future(vm._control_vm("test")))
assert writer.write.called_with("test")
assert res is None
@@ -446,7 +451,7 @@ def test_control_vm_expect_text(vm, loop, running_subprocess_mock):
reader.readline.return_value = future
vm._monitor = 4242
res = loop.run_until_complete(asyncio.async(vm._control_vm("test", [b"epic"])))
res = loop.run_until_complete(asyncio.ensure_future(vm._control_vm("test", [b"epic"])))
assert writer.write.called_with("test")
assert res == "epic product"
@@ -454,9 +459,10 @@ def test_control_vm_expect_text(vm, loop, running_subprocess_mock):
def test_build_command(vm, loop, fake_qemu_binary, port_manager):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio = vm._local_udp_tunnels[0][0]
assert cmd == [
fake_qemu_binary,
@@ -477,7 +483,9 @@ def test_build_command(vm, loop, fake_qemu_binary, port_manager):
"-device",
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
"-netdev",
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport),
"-display",
"none"
]
@@ -486,10 +494,11 @@ def test_build_command_manual_uuid(vm, loop, fake_qemu_binary, port_manager):
If user has set a uuid we keep it
"""
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
vm.options = "-uuid e1c307a4-896f-11e6-81a5-3c07547807cc"
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert "e1c307a4-896f-11e6-81a5-3c07547807cc" in cmd
assert vm.id not in cmd
@@ -502,7 +511,7 @@ def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_mana
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.3.2")
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio = vm._local_udp_tunnels[0][0]
assert cmd == [
fake_qemu_binary,
@@ -524,7 +533,8 @@ def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_mana
"-device",
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
"-netdev",
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport),
"-nographic"
]
@@ -536,7 +546,7 @@ def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.4.2")
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio = vm._local_udp_tunnels[0][0]
assert cmd == [
fake_qemu_binary,
@@ -560,25 +570,65 @@ def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_
"-device",
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
"-netdev",
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport),
"-nographic"
]
def test_build_command_kvm_3_1(linux_platform, vm, loop, fake_qemu_binary, port_manager):
"""
Qemu 2.4 introduce an issue with KVM
"""
vm._run_with_kvm = MagicMock(return_value=True)
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio = vm._local_udp_tunnels[0][0]
assert cmd == [
fake_qemu_binary,
"-name",
"test",
"-m",
"256M",
"-smp",
"cpus=1",
"-enable-kvm",
"-machine",
"smm=off",
"-boot",
"order=c",
"-uuid",
vm.id,
"-serial",
"telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
"-net",
"none",
"-device",
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
"-netdev",
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport),
"-display",
"none"
]
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_build_command_without_display(vm, loop, fake_qemu_binary):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.5.0")
os.environ["DISPLAY"] = ""
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert "-nographic" in cmd
def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager):
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.5.0")
os.environ["DISPLAY"] = "0:0"
vm.adapters = 2
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio1 = vm._local_udp_tunnels[0][0]
nio2 = vm._local_udp_tunnels[1][0]
assert cmd == [
@@ -604,7 +654,8 @@ def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager):
"-device",
"e1000,mac={},netdev=gns3-1".format(int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)),
"-netdev",
"socket,id=gns3-1,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio2.rport, nio2.lport)
"socket,id=gns3-1,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio2.rport, nio2.lport),
"-nographic"
]
@@ -613,13 +664,14 @@ def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port
Should support multiple base vmac address
"""
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.5.0")
vm.adapters = 2
vm.mac_address = "00:00:ab:0e:0f:09"
mac_0 = vm._mac_address
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
assert mac_0[:8] == "00:00:ab"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert "e1000,mac={},netdev=gns3-0".format(mac_0) in cmd
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
@@ -628,7 +680,7 @@ def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
assert mac_0[:8] == "00:42:ab"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
assert "e1000,mac={},netdev=gns3-0".format(mac_0) in cmd
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
@@ -648,7 +700,7 @@ def test_build_command_large_number_of_adapters(vm, loop, fake_qemu_binary, port
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
assert mac_0[:8] == "00:00:ab"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
# Count if we have 100 e1000 adapters in the command
assert len([l for l in cmd if "e1000" in l ]) == 100
@@ -672,10 +724,10 @@ def test_build_command_large_number_of_adapters(vm, loop, fake_qemu_binary, port
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.0.0")
with pytest.raises(QemuError):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
vm.adapters = 5
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
# Windows accept this kind of mistake
@@ -685,7 +737,7 @@ def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
vm.options = "'test"
with pytest.raises(QemuError):
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
def test_hda_disk_image(vm, images_dir):
+2 -2
View File
@@ -83,7 +83,7 @@ def test_close(node, loop, port_manager):
node.aux = aux
port = node.console
assert loop.run_until_complete(asyncio.async(node.close()))
assert loop.run_until_complete(asyncio.ensure_future(node.close()))
# Raise an exception if the port is not free
port_manager.reserve_tcp_port(port, node.project)
# Raise an exception if the port is not free
@@ -92,7 +92,7 @@ def test_close(node, loop, port_manager):
assert node.aux is None
# Called twice closed should return False
assert loop.run_until_complete(asyncio.async(node.close())) is False
assert loop.run_until_complete(asyncio.ensure_future(node.close())) is False
def test_aux(project, manager, port_manager):
+6 -6
View File
@@ -43,7 +43,7 @@ def manager(port_manager):
@pytest.fixture(scope="function")
def node(project, manager, loop):
node = manager.create_node("test", project.id, "00010203-0405-0607-0809-0a0b0c0d0e0f")
return loop.run_until_complete(asyncio.async(node))
return loop.run_until_complete(asyncio.ensure_future(node))
def test_affect_uuid():
@@ -140,7 +140,7 @@ def test_project_delete(loop):
project = Project(project_id=str(uuid4()))
directory = project.path
assert os.path.exists(directory)
loop.run_until_complete(asyncio.async(project.delete()))
loop.run_until_complete(asyncio.ensure_future(project.delete()))
assert os.path.exists(directory) is False
@@ -150,7 +150,7 @@ def test_project_delete_permission_issue(loop):
assert os.path.exists(directory)
os.chmod(directory, 0)
with pytest.raises(aiohttp.web.HTTPInternalServerError):
loop.run_until_complete(asyncio.async(project.delete()))
loop.run_until_complete(asyncio.ensure_future(project.delete()))
os.chmod(directory, 700)
@@ -164,7 +164,7 @@ def test_project_add_node(manager):
def test_project_close(loop, node, project):
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.close") as mock:
loop.run_until_complete(asyncio.async(project.close()))
loop.run_until_complete(asyncio.ensure_future(project.close()))
assert mock.called
assert node.id not in node.manager._nodes
@@ -181,7 +181,7 @@ def test_list_files(tmpdir, loop):
with open(os.path.join(path, "test.txt"), "w+") as f:
f.write("test2")
files = loop.run_until_complete(asyncio.async(project.list_files()))
files = loop.run_until_complete(asyncio.ensure_future(project.list_files()))
assert files == [
{
@@ -210,5 +210,5 @@ def test_emit(async_run):
def test_update_project(loop):
variables = [{"name": "TEST", "value": "VAL"}]
project = Project(project_id=str(uuid.uuid4()))
loop.run_until_complete(asyncio.async(project.update(variables=variables)))
loop.run_until_complete(asyncio.ensure_future(project.update(variables=variables)))
assert project.variables == variables
+9 -9
View File
@@ -56,7 +56,7 @@ def test_vm_invalid_traceng_path(vm, manager, loop):
with pytest.raises(TraceNGError):
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.name == "test"
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
@@ -66,13 +66,13 @@ def test_start(loop, vm, async_run):
process.returncode = None
with NotificationManager.instance().queue() as queue:
async_run(queue.get(0)) # Ping
async_run(queue.get(1)) # Ping
vm.ip_address = "192.168.1.1"
with patch("sys.platform", return_value="win"):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
loop.run_until_complete(asyncio.async(vm.start("192.168.1.2")))
loop.run_until_complete(asyncio.ensure_future(vm.start("192.168.1.2")))
assert mock_exec.call_args[0] == (vm._traceng_path(),
'-u',
'-c',
@@ -88,7 +88,7 @@ def test_start(loop, vm, async_run):
'192.168.1.2')
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
(action, event, kwargs) = async_run(queue.get(0))
(action, event, kwargs) = async_run(queue.get(1))
assert action == "node.updated"
assert event == vm
@@ -115,15 +115,15 @@ def test_stop(loop, vm, async_run):
assert vm.is_running()
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.stop()))
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
assert vm.is_running() is False
process.terminate.assert_called_with()
async_run(queue.get(0)) #  Ping
async_run(queue.get(0)) #  Started
async_run(queue.get(1)) #  Ping
async_run(queue.get(1)) #  Started
(action, event, kwargs) = async_run(queue.get(0))
(action, event, kwargs) = async_run(queue.get(1))
assert action == "node.updated"
assert event == vm
@@ -175,5 +175,5 @@ def test_close(vm, port_manager, loop):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
vm.start()
loop.run_until_complete(asyncio.async(vm.close()))
loop.run_until_complete(asyncio.ensure_future(vm.close()))
assert vm.is_running() is False
@@ -92,7 +92,7 @@ def test_list_vms(manager, loop):
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute") as mock:
mock.side_effect = execute_mock
vms = loop.run_until_complete(asyncio.async(manager.list_vms()))
vms = loop.run_until_complete(asyncio.ensure_future(manager.list_vms()))
assert vms == [
{"vmname": "Windows 8.1", "ram": 512},
{"vmname": "Linux Microcore 4.7.1", "ram": 256}
@@ -75,20 +75,20 @@ def test_rename_vmname(project, manager, async_run):
def test_vm_valid_virtualbox_api_version(loop, project, manager):
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]):
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
def test_vm_invalid_virtualbox_api_version(loop, project, manager):
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]):
with pytest.raises(VirtualBoxError):
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
loop.run_until_complete(asyncio.async(vm.create()))
loop.run_until_complete(asyncio.ensure_future(vm.create()))
def test_vm_adapter_add_nio_binding_adapter_not_exist(loop, vm, manager, free_console_port):
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
with pytest.raises(VirtualBoxError):
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(15, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(15, nio)))
def test_json(vm, tmpdir, project):
+4 -4
View File
@@ -56,8 +56,8 @@ def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap")
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
vm.adapters = 1
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.async(vm.start_capture(0, output_file)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, output_file)))
assert vm._ethernet_adapters[0].get_nio(0).capturing
@@ -66,8 +66,8 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap")
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
vm.adapters = 1
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(vm.start_capture(0, output_file))
assert vm._ethernet_adapters[0].get_nio(0).capturing
loop.run_until_complete(asyncio.async(vm.stop_capture(0)))
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0)))
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
+12 -12
View File
@@ -56,13 +56,13 @@ def test_vm(project, manager):
def test_vm_check_vpcs_version(loop, vm, manager):
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"):
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
assert vm._vpcs_version == parse_version("0.9")
def test_vm_check_vpcs_version_0_6_1(loop, vm, manager):
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"):
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
assert vm._vpcs_version == parse_version("0.6.1")
@@ -71,7 +71,7 @@ def test_vm_invalid_vpcs_version(loop, manager, vm):
with pytest.raises(VPCSError):
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
assert vm.name == "test"
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
@@ -81,7 +81,7 @@ def test_vm_invalid_vpcs_path(vm, manager, loop):
with pytest.raises(VPCSError):
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert vm.name == "test"
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
@@ -91,12 +91,12 @@ def test_start(loop, vm, async_run):
process.returncode = None
with NotificationManager.instance().queue() as queue:
async_run(queue.get(0)) # Ping
async_run(queue.get(1)) # Ping
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
loop.run_until_complete(asyncio.async(vm.start()))
loop.run_until_complete(asyncio.ensure_future(vm.start()))
assert mock_exec.call_args[0] == (vm._vpcs_path(),
'-p',
str(vm._internal_console_port),
@@ -113,7 +113,7 @@ def test_start(loop, vm, async_run):
'127.0.0.1')
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
(action, event, kwargs) = async_run(queue.get(0))
(action, event, kwargs) = async_run(queue.get(1))
assert action == "node.updated"
assert event == vm
@@ -169,7 +169,7 @@ def test_stop(loop, vm, async_run):
assert vm.is_running()
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.stop()))
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
assert vm.is_running() is False
if sys.platform.startswith("win"):
@@ -177,10 +177,10 @@ def test_stop(loop, vm, async_run):
else:
process.terminate.assert_called_with()
async_run(queue.get(0)) #  Ping
async_run(queue.get(0)) #  Started
async_run(queue.get(1)) #  Ping
async_run(queue.get(1)) #  Started
(action, event, kwargs) = async_run(queue.get(0))
(action, event, kwargs) = async_run(queue.get(1))
assert action == "node.updated"
assert event == vm
@@ -300,5 +300,5 @@ def test_close(vm, port_manager, loop):
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
vm.start()
loop.run_until_complete(asyncio.async(vm.close()))
loop.run_until_complete(asyncio.ensure_future(vm.close()))
assert vm.is_running() is False
+2 -2
View File
@@ -104,7 +104,7 @@ def http_server(request, loop, port_manager, monkeypatch, controller):
monkeypatch.setattr('gns3server.compute.virtualbox.virtualbox_vm.VirtualBoxVM.close', lambda self: True)
loop.run_until_complete(instance.unload())
srv.close()
srv.wait_closed()
loop.run_until_complete(srv.wait_closed())
@pytest.fixture
@@ -314,7 +314,7 @@ def async_run(loop):
"""
Shortcut for running in asyncio loop
"""
return lambda x: loop.run_until_complete(asyncio.async(x))
return lambda x: loop.run_until_complete(asyncio.ensure_future(x))
@pytest.yield_fixture
+1
View File
@@ -277,6 +277,7 @@ def test_json(compute):
"cpu_usage_percent": None,
"memory_usage_percent": None,
"connected": True,
"last_error": None,
"capabilities": {
"version": None,
"node_types": []
Loaded 100 of 106 files, more files were not shown because too many files have changed in this diff. Show more