Skip to content

Commit

Permalink
Forbid controller and compute servers to be different versions.
Browse files Browse the repository at this point in the history
Report last compute server error to clients and display in the server summary.
  • Loading branch information
grossmj committed Aug 22, 2018
1 parent 59ce105 commit 089d25c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
36 changes: 29 additions & 7 deletions gns3server/controller/compute.py
Expand Up @@ -29,7 +29,7 @@
from ..utils.images import list_images
from ..utils.asyncio import locked_coroutine
from ..controller.controller_error import ControllerError
from ..version import __version__
from ..version import __version__, __version_info__


import logging
Expand Down Expand Up @@ -95,6 +95,7 @@ def __init__(self, compute_id, controller=None, protocol="http", host="localhost
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": []
Expand Down Expand Up @@ -301,7 +302,8 @@ def __json__(self, topology_dump=False):
"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
Expand Down Expand Up @@ -404,7 +406,7 @@ 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")
Expand All @@ -428,16 +430,36 @@ def connect(self):
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]:
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
Expand Down
2 changes: 2 additions & 0 deletions gns3server/controller/gns3vm/__init__.py
Expand Up @@ -336,6 +336,8 @@ def _check_network(self, compute):
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
def _suspend(self):
Expand Down
4 changes: 4 additions & 0 deletions gns3server/schemas/compute.py
Expand Up @@ -104,6 +104,10 @@
"maximum": 100,
"minimum": 0
},
"last_error": {
"description": "Last error on the compute",
"type": ["string", "null"]
},
"capabilities": CAPABILITIES_SCHEMA
},
"additionalProperties": False,
Expand Down
2 changes: 1 addition & 1 deletion gns3server/version.py
Expand Up @@ -23,7 +23,7 @@
# or negative for a release candidate or beta (after the base version
# number has been incremented)

__version__ = "2.1.10dev1"
__version__ = "2.1.10dev2"
__version_info__ = (2, 1, 10, 99)

# If it's a git checkout try to add the commit
Expand Down
1 change: 1 addition & 0 deletions tests/controller/test_compute.py
Expand Up @@ -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": []
Expand Down
1 change: 1 addition & 0 deletions tests/handlers/api/controller/test_compute.py
Expand Up @@ -131,6 +131,7 @@ def test_compute_list(http_controller, controller):
'name': 'My super server',
'cpu_usage_percent': None,
'memory_usage_percent': None,
'last_error': None,
'capabilities': {
'version': None,
'node_types': []
Expand Down

0 comments on commit 089d25c

Please sign in to comment.