mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Drop the commit system
Ref https://github.com/GNS3/gns3-gui/issues/1243
This commit is contained in:
parent
52f852bc6d
commit
3255be0ae2
@ -288,16 +288,6 @@ class BaseManager:
|
||||
|
||||
pass
|
||||
|
||||
@asyncio.coroutine
|
||||
def project_committed(self, project):
|
||||
"""
|
||||
Called when a project is committed.
|
||||
|
||||
:param project: Project instance
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete_node(self, node_id):
|
||||
"""
|
||||
@ -309,7 +299,7 @@ class BaseManager:
|
||||
|
||||
node = yield from self.close_node(node_id)
|
||||
node.project.emit("node.deleted", node)
|
||||
node.project.mark_node_for_destruction(node)
|
||||
yield from node.project.remove_node(node)
|
||||
if node.id in self._nodes:
|
||||
del self._nodes[node.id]
|
||||
return node
|
||||
|
@ -239,23 +239,6 @@ class Dynamips(BaseManager):
|
||||
if device.project.id == project.id:
|
||||
yield from device.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower()))
|
||||
|
||||
@asyncio.coroutine
|
||||
def project_committed(self, project):
|
||||
"""
|
||||
Called when a project has been committed.
|
||||
|
||||
:param project: Project instance
|
||||
"""
|
||||
|
||||
# save the configs when the project is committed
|
||||
for node in self._nodes.copy().values():
|
||||
if node.project.id == project.id:
|
||||
try:
|
||||
yield from node.save_configs()
|
||||
except DynamipsError as e:
|
||||
log.warning(e)
|
||||
continue
|
||||
|
||||
@property
|
||||
def dynamips_path(self):
|
||||
"""
|
||||
|
@ -56,7 +56,6 @@ class Project:
|
||||
self._id = project_id
|
||||
|
||||
self._nodes = set()
|
||||
self._nodes_to_destroy = set()
|
||||
self._used_tcp_ports = set()
|
||||
self._used_udp_ports = set()
|
||||
|
||||
@ -231,14 +230,6 @@ class Project:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create the capture working directory: {}".format(e))
|
||||
return workdir
|
||||
|
||||
def mark_node_for_destruction(self, node):
|
||||
"""
|
||||
:param node: An instance of Node
|
||||
"""
|
||||
|
||||
self.remove_node(node)
|
||||
self._nodes_to_destroy.add(node)
|
||||
|
||||
def add_node(self, node):
|
||||
"""
|
||||
Adds a node to the project.
|
||||
@ -258,6 +249,7 @@ class Project:
|
||||
"""
|
||||
|
||||
if node in self._nodes:
|
||||
yield from node.delete()
|
||||
self._nodes.remove(node)
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -319,19 +311,6 @@ class Project:
|
||||
for port in self._used_udp_ports.copy():
|
||||
port_manager.release_udp_port(port, self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def commit(self):
|
||||
"""
|
||||
Writes project changes on disk
|
||||
"""
|
||||
|
||||
while self._nodes_to_destroy:
|
||||
node = self._nodes_to_destroy.pop()
|
||||
yield from node.delete()
|
||||
self.remove_node(node)
|
||||
for module in self.compute():
|
||||
yield from module.instance().project_committed(self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
"""
|
||||
|
@ -273,11 +273,6 @@ class Project:
|
||||
yield from compute.post("/projects/{}/close".format(self._id))
|
||||
self._allocated_node_names.clear()
|
||||
|
||||
@asyncio.coroutine
|
||||
def commit(self):
|
||||
for compute in self._project_created_on_compute:
|
||||
yield from compute.post("/projects/{}/commit".format(self._id))
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
yield from self.close()
|
||||
|
@ -121,23 +121,6 @@ class ProjectHandler:
|
||||
yield from module.instance().project_moved(project)
|
||||
response.json(project)
|
||||
|
||||
@Route.post(
|
||||
r"/projects/{project_id}/commit",
|
||||
description="Write changes on disk",
|
||||
parameters={
|
||||
"project_id": "Project UUID",
|
||||
},
|
||||
status_codes={
|
||||
204: "Changes have been written on disk",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
def commit(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
yield from project.commit()
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/projects/{project_id}/close",
|
||||
description="Close a project",
|
||||
|
@ -76,23 +76,6 @@ class ProjectHandler:
|
||||
project = controller.get_project(request.match_info["project_id"])
|
||||
response.json(project)
|
||||
|
||||
@Route.post(
|
||||
r"/projects/{project_id}/commit",
|
||||
description="Write changes on disk",
|
||||
parameters={
|
||||
"project_id": "Project UUID",
|
||||
},
|
||||
status_codes={
|
||||
204: "Changes have been written on disk",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
def commit(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
project = controller.get_project(request.match_info["project_id"])
|
||||
yield from project.commit()
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/projects/{project_id}/close",
|
||||
description="Close a project",
|
||||
|
@ -106,43 +106,6 @@ def test_node_working_directory(tmpdir, node):
|
||||
assert os.path.exists(p.node_working_directory(node))
|
||||
|
||||
|
||||
def test_mark_node_for_destruction(node):
|
||||
project = Project(project_id=str(uuid4()))
|
||||
project.add_node(node)
|
||||
project.mark_node_for_destruction(node)
|
||||
assert len(project._nodes_to_destroy) == 1
|
||||
assert len(project.nodes) == 0
|
||||
|
||||
|
||||
def test_commit(manager, loop):
|
||||
project = Project(project_id=str(uuid4()))
|
||||
node = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
project.add_node(node)
|
||||
directory = project.node_working_directory(node)
|
||||
project.mark_node_for_destruction(node)
|
||||
assert len(project._nodes_to_destroy) == 1
|
||||
assert os.path.exists(directory)
|
||||
loop.run_until_complete(asyncio.async(project.commit()))
|
||||
assert len(project._nodes_to_destroy) == 0
|
||||
assert os.path.exists(directory) is False
|
||||
assert len(project.nodes) == 0
|
||||
|
||||
|
||||
def test_commit_permission_issue(manager, loop):
|
||||
"""
|
||||
GNS3 will fix the permission and continue to delete
|
||||
"""
|
||||
project = Project(project_id=str(uuid4()))
|
||||
node = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
project.add_node(node)
|
||||
directory = project.node_working_directory(node)
|
||||
project.mark_node_for_destruction(node)
|
||||
assert len(project._nodes_to_destroy) == 1
|
||||
assert os.path.exists(directory)
|
||||
os.chmod(directory, 0)
|
||||
loop.run_until_complete(asyncio.async(project.commit()))
|
||||
|
||||
|
||||
def test_project_delete(loop):
|
||||
project = Project(project_id=str(uuid4()))
|
||||
directory = project.path
|
||||
|
@ -114,18 +114,6 @@ def test_update_path_project_non_local(http_compute, tmpdir):
|
||||
assert response.status == 403
|
||||
|
||||
|
||||
def test_commit_project(http_compute, project):
|
||||
with asyncio_patch("gns3server.compute.project.Project.commit", return_value=True) as mock:
|
||||
response = http_compute.post("/projects/{project_id}/commit".format(project_id=project.id), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
|
||||
def test_commit_project_invalid_uuid(http_compute):
|
||||
response = http_compute.post("/projects/{project_id}/commit".format(project_id=uuid.uuid4()))
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
def test_delete_project(http_compute, project):
|
||||
with asyncio_patch("gns3server.compute.project.Project.delete", return_value=True) as mock:
|
||||
response = http_compute.delete("/projects/{project_id}".format(project_id=project.id), example=True)
|
||||
|
@ -73,18 +73,6 @@ def test_list_projects(http_controller, tmpdir):
|
||||
assert projects[0]["name"] == "test"
|
||||
|
||||
|
||||
def test_commit_project(http_controller, project):
|
||||
with asyncio_patch("gns3server.controller.project.Project.commit", return_value=True) as mock:
|
||||
response = http_controller.post("/projects/{project_id}/commit".format(project_id=project.id), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
|
||||
def test_commit_project_invalid_uuid(http_controller):
|
||||
response = http_controller.post("/projects/{project_id}/commit".format(project_id=uuid.uuid4()))
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
def test_get_project(http_controller, project):
|
||||
response = http_controller.get("/projects/{project_id}".format(project_id=project.id), example=True)
|
||||
assert response.status == 200
|
||||
|
Loading…
Reference in New Issue
Block a user