aboutsummaryrefslogtreecommitdiffstats
path: root/community/gns3-server/aiohttp-support.patch
blob: 83bb6ee7337ab3097cd495b4bd04fda4fed0301c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From a7412d1c879920c3b2c2871763aafbe6836d1ed7 Mon Sep 17 00:00:00 2001
From: ziajka <dominik@gns3.net>
Date: Thu, 26 Oct 2017 16:29:01 +0200
Subject: [PATCH] aiohttp 2.3.1 dependency

---
 gns3server/controller/compute.py |  8 +++++++-
 gns3server/web/web_server.py     | 11 ++++++++---
 requirements.txt                 |  2 +-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py
index 05154fd3..8a3d35e8 100644
--- a/gns3server/controller/compute.py
+++ b/gns3server/controller/compute.py
@@ -506,10 +506,16 @@ def _run_http_query(self, method, path, data=None, timeout=20, raw=False):
                 else:
                     data = json.dumps(data).encode("utf-8")
         try:
+            log.debug("Attempting request to compute: {method} {url} {headers}".format(
+                method=method,
+                url=url,
+                headers=headers
+            ))
             response = yield from self._session().request(method, url, headers=headers, data=data, auth=self._auth, chunked=chunked, timeout=timeout)
         except asyncio.TimeoutError as e:
             raise ComputeError("Timeout error when connecting to {}".format(url))
-        except (aiohttp.ClientError, aiohttp.ServerDisconnectedError, ValueError, KeyError) as e:
+        except (aiohttp.ClientError, aiohttp.ServerDisconnectedError, ValueError, KeyError, socket.gaierror) as e:
+            #  aiohttp 2.3.1 raises socket.gaierror when cannot find host
             raise ComputeError(str(e))
         body = yield from response.read()
         if body and not raw:
diff --git a/gns3server/web/web_server.py b/gns3server/web/web_server.py
index 40179367..9ce9c2e0 100644
--- a/gns3server/web/web_server.py
+++ b/gns3server/web/web_server.py
@@ -43,8 +43,8 @@
 import logging
 log = logging.getLogger(__name__)
 
-if not aiohttp.__version__.startswith("2.2"):
-    raise RuntimeError("aiohttp 2.2 is required to run the GNS3 server")
+if not (aiohttp.__version__.startswith("2.2") or aiohttp.__version__.startswith("2.3")):
+    raise RuntimeError("aiohttp 2.2.x or 2.3.x is required to run the GNS3 server")
 
 
 class WebServer:
@@ -102,7 +102,12 @@ def shutdown_server(self):
         if self._app:
             yield from self._app.shutdown()
         if self._handler:
-            yield from self._handler.finish_connections(2)  # Parameter is timeout
+            try:
+                # aiohttp < 2.3
+                yield from self._handler.finish_connections(2)  # Parameter is timeout
+            except AttributeError:
+                # aiohttp >= 2.3
+                yield from self._handler.shutdown(2)  # Parameter is timeout
         if self._app:
             yield from self._app.cleanup()