From 3255be0ae23dc32ecb4cc67d86681816bd55bbe6 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 14 Jun 2016 10:16:33 +0200 Subject: [PATCH] Drop the commit system Ref https://github.com/GNS3/gns3-gui/issues/1243 --- gns3server/compute/base_manager.py | 12 +----- gns3server/compute/dynamips/__init__.py | 17 --------- gns3server/compute/project.py | 23 +----------- gns3server/controller/project.py | 5 --- .../handlers/api/compute/project_handler.py | 17 --------- .../api/controller/project_handler.py | 17 --------- tests/compute/test_project.py | 37 ------------------- tests/handlers/api/compute/test_project.py | 12 ------ tests/handlers/api/controller/test_project.py | 12 ------ 9 files changed, 2 insertions(+), 150 deletions(-) diff --git a/gns3server/compute/base_manager.py b/gns3server/compute/base_manager.py index ac1d6e92..d6a8c741 100644 --- a/gns3server/compute/base_manager.py +++ b/gns3server/compute/base_manager.py @@ -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 diff --git a/gns3server/compute/dynamips/__init__.py b/gns3server/compute/dynamips/__init__.py index 56676e5d..5ffc01c2 100644 --- a/gns3server/compute/dynamips/__init__.py +++ b/gns3server/compute/dynamips/__init__.py @@ -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): """ diff --git a/gns3server/compute/project.py b/gns3server/compute/project.py index 6483edfb..8c75ee5b 100644 --- a/gns3server/compute/project.py +++ b/gns3server/compute/project.py @@ -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): """ diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 725c94ab..d92d1522 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -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() diff --git a/gns3server/handlers/api/compute/project_handler.py b/gns3server/handlers/api/compute/project_handler.py index 35546110..29e3d527 100644 --- a/gns3server/handlers/api/compute/project_handler.py +++ b/gns3server/handlers/api/compute/project_handler.py @@ -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", diff --git a/gns3server/handlers/api/controller/project_handler.py b/gns3server/handlers/api/controller/project_handler.py index efe4f605..200722ad 100644 --- a/gns3server/handlers/api/controller/project_handler.py +++ b/gns3server/handlers/api/controller/project_handler.py @@ -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", diff --git a/tests/compute/test_project.py b/tests/compute/test_project.py index 82bd868f..32cb0064 100644 --- a/tests/compute/test_project.py +++ b/tests/compute/test_project.py @@ -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 diff --git a/tests/handlers/api/compute/test_project.py b/tests/handlers/api/compute/test_project.py index 6420bbcd..48deea76 100644 --- a/tests/handlers/api/compute/test_project.py +++ b/tests/handlers/api/compute/test_project.py @@ -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) diff --git a/tests/handlers/api/controller/test_project.py b/tests/handlers/api/controller/test_project.py index 6800abdf..5dc6156f 100644 --- a/tests/handlers/api/controller/test_project.py +++ b/tests/handlers/api/controller/test_project.py @@ -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