diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 7ad192a8..8981fb48 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -61,7 +61,7 @@ class Controller: self._config_file = Config.instance().controller_config log.info("Load controller configuration file {}".format(self._config_file)) - async def start(self, computes): + async def start(self, computes=None): log.info("Controller is starting") self.load_base_files() @@ -108,11 +108,13 @@ class Controller: except ControllerError: log.fatal("Cannot access to the local server, make sure something else is not running on the TCP port {}".format(port)) sys.exit(1) - for c in computes: - try: - await self.add_compute(**c, connect=False) - except (ControllerError, KeyError): - pass # Skip not available servers at loading + + if computes: + for c in computes: + try: + await self.add_compute(**c, connect=False) + except (ControllerError, KeyError): + pass # Skip not available servers at loading try: await self.gns3vm.auto_start_vm() diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 337bd026..c88246f7 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -182,7 +182,17 @@ class Compute: @name.setter def name(self, name): - self._name = name + if name is not None: + self._name = name + else: + if self._user: + user = self._user + # Due to random user generated by 1.4 it's common to have a very long user + if len(user) > 14: + user = user[:11] + "..." + self._name = "{}://{}@{}:{}".format(self._protocol, user, self._host, self._port) + else: + self._name = "{}://{}:{}".format(self._protocol, self._host, self._port) @property def connected(self): diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index a7b69e35..9ced9c1c 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -34,7 +34,6 @@ def test_save(controller, controller_config_path): assert os.path.exists(controller_config_path) with open(controller_config_path) as f: data = json.load(f) - assert data["computes"] == [] assert data["version"] == __version__ assert data["iou_license"] == controller.iou_license assert data["gns3vm"] == controller.gns3vm.__json__() @@ -45,20 +44,10 @@ def test_load_controller_settings(controller, controller_config_path): controller.save() with open(controller_config_path) as f: data = json.load(f) - data["computes"] = [ - { - "host": "localhost", - "port": 8000, - "protocol": "http", - "user": "admin", - "password": "root", - "compute_id": "test1" - } - ] data["gns3vm"] = {"vmname": "Test VM"} with open(controller_config_path, "w+") as f: json.dump(data, f) - assert len(controller._load_controller_settings()) == 1 + controller._load_controller_settings() assert controller.gns3vm.settings["vmname"] == "Test VM" @@ -67,7 +56,6 @@ def test_load_controller_settings_with_no_computes_section(controller, controlle controller.save() with open(controller_config_path) as f: data = json.load(f) - del data['computes'] with open(controller_config_path, "w+") as f: json.dump(data, f) assert len(controller._load_controller_settings()) == 0 @@ -146,22 +134,6 @@ async def test_addDuplicateCompute(controller): await controller.add_compute(compute_id="test2", name="Test", connect=False) -@pytest.mark.asyncio -async def test_deleteCompute(controller, controller_config_path): - - c = await controller.add_compute(compute_id="test1", connect=False) - assert len(controller.computes) == 1 - controller._notification = MagicMock() - c._connected = True - await controller.delete_compute("test1") - assert len(controller.computes) == 0 - controller._notification.controller_emit.assert_called_with("compute.deleted", c.__json__()) - with open(controller_config_path) as f: - data = json.load(f) - assert len(data["computes"]) == 0 - assert c.connected is False - - @pytest.mark.asyncio async def test_deleteComputeProjectOpened(controller, controller_config_path): """ @@ -185,9 +157,6 @@ async def test_deleteComputeProjectOpened(controller, controller_config_path): await controller.delete_compute("test1") assert len(controller.computes) == 0 controller._notification.controller_emit.assert_called_with("compute.deleted", c.__json__()) - with open(controller_config_path) as f: - data = json.load(f) - assert len(data["computes"]) == 0 assert c.connected is False # Project 1 use this compute it should be close before deleting the compute @@ -195,26 +164,6 @@ async def test_deleteComputeProjectOpened(controller, controller_config_path): assert project2.status == "opened" -@pytest.mark.asyncio -async def test_addComputeConfigFile(controller, controller_config_path): - - await controller.add_compute(compute_id="test1", name="Test", connect=False) - 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', - 'user': None, - 'password': None - } - ] - - @pytest.mark.asyncio async def test_getCompute(controller):