diff --git a/gns3server/compute/docker/__init__.py b/gns3server/compute/docker/__init__.py index 5b41bd2c..048d5e47 100644 --- a/gns3server/compute/docker/__init__.py +++ b/gns3server/compute/docker/__init__.py @@ -107,7 +107,8 @@ class Docker(BaseManager): data = json.dumps(data) url = "http://docker/" + path try: - response = yield from aiohttp.request( + session = aiohttp.ClientSession() + response = yield from session.request( method, url, connector=(yield from self.connector()), @@ -116,6 +117,7 @@ class Docker(BaseManager): headers={"content-type": "application/json", }, timeout=timeout ) + yield from session.close() except (aiohttp.ClientResponseError, aiohttp.ClientOSError) as e: raise DockerError("Docker has returned an error: {}".format(str(e))) if response.status >= 300: diff --git a/tests/compute/docker/test_docker.py b/tests/compute/docker/test_docker.py index c71ef3fb..100c4fcc 100644 --- a/tests/compute/docker/test_docker.py +++ b/tests/compute/docker/test_docker.py @@ -44,7 +44,7 @@ def test_query_success(loop, vm): return b'{"c": false}' response.read.side_effect = read - with asyncio_patch("aiohttp.request", return_value=response) as mock: + with asyncio_patch("aiohttp.client.ClientSession.request", return_value=response) as mock: data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1}))) mock.assert_called_with('POST', 'http://docker/test', @@ -67,7 +67,7 @@ def test_query_error(loop, vm): return b"NOT FOUND" response.read.side_effect = read - with asyncio_patch("aiohttp.request", return_value=response) as mock: + with asyncio_patch("aiohttp.client.ClientSession.request", return_value=response) as mock: with pytest.raises(DockerError): data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1}))) mock.assert_called_with('POST', @@ -89,7 +89,7 @@ def test_query_error_json(loop, vm): return b'{"message": "Error"}' response.read.side_effect = read - with asyncio_patch("aiohttp.request", return_value=response) as mock: + with asyncio_patch("aiohttp.client.ClientSession.request", return_value=response) as mock: with pytest.raises(DockerError): data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1}))) mock.assert_called_with('POST',