1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +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 self._connected = False
# Allow locking during ubridge operations # Allow locking during ubridge operations
self.ubridge_lock = asyncio.Lock() self.ubridge_lock = asyncio.Lock()
self._session = None
@asyncio.coroutine @asyncio.coroutine
def connector(self): def connector(self):
@ -107,17 +108,16 @@ class Docker(BaseManager):
data = json.dumps(data) data = json.dumps(data)
url = "http://docker/" + path url = "http://docker/" + path
try: try:
session = aiohttp.ClientSession() if self._session is None or self._session.closed is True:
response = yield from session.request( self._session = aiohttp.ClientSession(connector=(yield from self.connector()))
response = yield from self._session.request(
method, method,
url, url,
connector=(yield from self.connector()),
params=params, params=params,
data=data, data=data,
headers={"content-type": "application/json", }, headers={"content-type": "application/json", },
timeout=timeout timeout=timeout
) )
yield from session.close()
except (aiohttp.ClientResponseError, aiohttp.ClientOSError) as e: except (aiohttp.ClientResponseError, aiohttp.ClientOSError) as e:
raise DockerError("Docker has returned an error: {}".format(str(e))) raise DockerError("Docker has returned an error: {}".format(str(e)))
if response.status >= 300: if response.status >= 300:

View File

@ -28,8 +28,6 @@ from gns3server.compute.docker.docker_error import DockerError
def vm(): def vm():
vm = Docker() vm = Docker()
vm._connected = True vm._connected = True
vm._connector = MagicMock()
vm._connector.closed = False
return vm 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}))) data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
mock.assert_called_with('POST', mock.assert_called_with('POST',
'http://docker/test', 'http://docker/test',
connector=vm._connector,
data='{"a": true}', data='{"a": true}',
headers={'content-type': 'application/json'}, headers={'content-type': 'application/json'},
params={'b': 1}, 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}))) data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
mock.assert_called_with('POST', mock.assert_called_with('POST',
'http://docker/test', 'http://docker/test',
connector=vm._connector,
data='{"a": true}', data='{"a": true}',
headers={'content-type': 'application/json'}, headers={'content-type': 'application/json'},
params={'b': 1}, 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}))) data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
mock.assert_called_with('POST', mock.assert_called_with('POST',
'http://docker/test', 'http://docker/test',
connector=vm._connector,
data='{"a": true}', data='{"a": true}',
headers={'content-type': 'application/json'}, headers={'content-type': 'application/json'},
params={'b': 1}, params={'b': 1},