From 1b530bde3f42daf3ccd4d6f643dd97af84307d2a Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 8 Jun 2016 14:25:11 +0200 Subject: [PATCH] Fix Compute name is lost at save Fix #562 --- gns3server/controller/__init__.py | 1 + gns3server/controller/compute.py | 1 + tests/controller/test_compute.py | 2 ++ tests/controller/test_controller.py | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 6c12c31d..edf71f26 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -60,6 +60,7 @@ class Controller: Save the controller configuration on disk """ data = {"computes": [{"host": c.host, + "name": c.name, "port": c.port, "protocol": c.protocol, "user": c.user, diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index c63dbff6..8b8116ea 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -123,6 +123,7 @@ class Compute: self._session.close() self._connected = False self._controller.notification.emit("compute.updated", self.__json__()) + self._controller.save() @asyncio.coroutine def close(self): diff --git a/tests/controller/test_compute.py b/tests/controller/test_compute.py index 57095ef9..0107d26d 100644 --- a/tests/controller/test_compute.py +++ b/tests/controller/test_compute.py @@ -223,6 +223,7 @@ def test_close(compute, async_run): def test_update(compute, controller, async_run): compute._controller._notification = MagicMock() + compute._controller.save = MagicMock() compute.name = "Test" compute.host = "example.org" compute._connected = True @@ -231,6 +232,7 @@ def test_update(compute, controller, async_run): assert compute.host == "example.org" controller.notification.emit.assert_called_with("compute.updated", compute.__json__()) assert compute.connected is False + assert compute._controller.save.called def test_forward_get(compute, async_run): diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index 12ebc744..b775195e 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -102,13 +102,14 @@ def test_deleteCompute(controller, controller_config_path, async_run): def test_addComputeConfigFile(controller, controller_config_path, async_run): - async_run(controller.add_compute(compute_id="test1")) + async_run(controller.add_compute(compute_id="test1", name="Test")) assert len(controller.computes) == 1 with open(controller_config_path) as f: data = json.load(f) assert data["computes"] == [ { 'compute_id': 'test1', + 'name': 'Test', 'host': 'localhost', 'port': 3080, 'protocol': 'http',