1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Cleanup docker source code

This commit is contained in:
Julien Duponchelle 2017-03-20 20:03:51 +01:00
parent a571b1a2f8
commit 78c154e376
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 4 additions and 9 deletions

View File

@ -46,6 +46,7 @@ class Docker(BaseManager):
self._connected = False
# Allow locking during ubridge operations
self.ubridge_lock = asyncio.Lock()
self._session = None
@asyncio.coroutine
def connector(self):
@ -107,17 +108,16 @@ class Docker(BaseManager):
data = json.dumps(data)
url = "http://docker/" + path
try:
session = aiohttp.ClientSession()
response = yield from session.request(
if self._session is None or self._session.closed is True:
self._session = aiohttp.ClientSession(connector=(yield from self.connector()))
response = yield from self._session.request(
method,
url,
connector=(yield from self.connector()),
params=params,
data=data,
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:

View File

@ -28,8 +28,6 @@ from gns3server.compute.docker.docker_error import DockerError
def vm():
vm = Docker()
vm._connected = True
vm._connector = MagicMock()
vm._connector.closed = False
return vm
@ -48,7 +46,6 @@ def test_query_success(loop, vm):
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',
connector=vm._connector,
data='{"a": true}',
headers={'content-type': 'application/json'},
params={'b': 1},
@ -72,7 +69,6 @@ def test_query_error(loop, vm):
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',
connector=vm._connector,
data='{"a": true}',
headers={'content-type': 'application/json'},
params={'b': 1},
@ -94,7 +90,6 @@ def test_query_error_json(loop, vm):
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',
connector=vm._connector,
data='{"a": true}',
headers={'content-type': 'application/json'},
params={'b': 1},