mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
parent
134fed8fc5
commit
5289c714f4
@ -85,6 +85,8 @@ class Controller:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def stop(self):
|
def stop(self):
|
||||||
log.info("Stop controller")
|
log.info("Stop controller")
|
||||||
|
for project in self._projects.values():
|
||||||
|
yield from project.close()
|
||||||
for compute in self._computes.values():
|
for compute in self._computes.values():
|
||||||
yield from compute.close()
|
yield from compute.close()
|
||||||
if self.gns3vm.enable and self.gns3vm.auto_stop:
|
if self.gns3vm.enable and self.gns3vm.auto_stop:
|
||||||
@ -233,12 +235,6 @@ class Controller:
|
|||||||
self.save()
|
self.save()
|
||||||
self.notification.emit("compute.created", compute.__json__())
|
self.notification.emit("compute.created", compute.__json__())
|
||||||
|
|
||||||
#FIXME: temporary before the remote GNS3 VM support is back
|
|
||||||
if "vm" not in self._computes and not hasattr(sys, "_called_from_test"):
|
|
||||||
compute_vm = Compute(compute_id="vm", controller=self, name="GNS3 VM", **kwargs)
|
|
||||||
self._computes[compute_vm.id] = compute_vm
|
|
||||||
self.notification.emit("compute.created", compute_vm.__json__())
|
|
||||||
|
|
||||||
return compute
|
return compute
|
||||||
else:
|
else:
|
||||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||||
@ -247,10 +243,16 @@ class Controller:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def delete_compute(self, compute_id):
|
def delete_compute(self, compute_id):
|
||||||
"""
|
"""
|
||||||
Delete a compute node
|
Delete a compute node. Project using this compute will be close
|
||||||
|
|
||||||
:param compute_id: Compute server identifier
|
:param compute_id: Compute server identifier
|
||||||
"""
|
"""
|
||||||
compute = self.get_compute(compute_id)
|
compute = self.get_compute(compute_id)
|
||||||
|
|
||||||
|
for project in self._projects.values():
|
||||||
|
if compute in project.computes:
|
||||||
|
yield from project.close()
|
||||||
|
|
||||||
yield from compute.close()
|
yield from compute.close()
|
||||||
del self._computes[compute_id]
|
del self._computes[compute_id]
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -169,6 +169,37 @@ def test_deleteCompute(controller, controller_config_path, async_run):
|
|||||||
assert c.connected is False
|
assert c.connected is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_deleteComputeProjectOpened(controller, controller_config_path, async_run):
|
||||||
|
"""
|
||||||
|
When you delete a compute the project using it are close
|
||||||
|
"""
|
||||||
|
c = async_run(controller.add_compute(compute_id="test1"))
|
||||||
|
c.post = AsyncioMagicMock()
|
||||||
|
assert len(controller.computes) == 1
|
||||||
|
|
||||||
|
project1 = async_run(controller.add_project(name="Test1"))
|
||||||
|
async_run(project1.open())
|
||||||
|
# We simulate that the project use this compute
|
||||||
|
project1._project_created_on_compute.add(c)
|
||||||
|
|
||||||
|
project2 = async_run(controller.add_project(name="Test2"))
|
||||||
|
async_run(project2.open())
|
||||||
|
|
||||||
|
controller._notification = MagicMock()
|
||||||
|
c._connected = True
|
||||||
|
async_run(controller.delete_compute("test1"))
|
||||||
|
assert len(controller.computes) == 0
|
||||||
|
controller._notification.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
|
||||||
|
assert project1.status == "closed"
|
||||||
|
assert project2.status == "opened"
|
||||||
|
|
||||||
|
|
||||||
def test_addComputeConfigFile(controller, controller_config_path, async_run):
|
def test_addComputeConfigFile(controller, controller_config_path, async_run):
|
||||||
async_run(controller.add_compute(compute_id="test1", name="Test"))
|
async_run(controller.add_compute(compute_id="test1", name="Test"))
|
||||||
assert len(controller.computes) == 1
|
assert len(controller.computes) == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user