mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Don't create directory structure during json dump. Fixes #2270
This commit is contained in:
parent
2a4ed9ba89
commit
3d85bba9d4
@ -233,6 +233,14 @@ class BaseNode:
|
||||
|
||||
return self._project.node_working_directory(self)
|
||||
|
||||
@property
|
||||
def working_path(self):
|
||||
"""
|
||||
Return the node working path. Doesn't create structure of directories when not present.
|
||||
"""
|
||||
|
||||
return self._project.node_working_path(self)
|
||||
|
||||
@property
|
||||
def temporary_directory(self):
|
||||
if self._temporary_directory is None:
|
||||
|
@ -86,7 +86,7 @@ class Cloud(BaseNode):
|
||||
"ports_mapping": self._ports_mapping,
|
||||
"interfaces": host_interfaces,
|
||||
"status": self.status,
|
||||
"node_directory": self.working_dir
|
||||
"node_directory": self.working_path
|
||||
}
|
||||
|
||||
@property
|
||||
|
@ -114,7 +114,7 @@ class DockerVM(BaseNode):
|
||||
"start_command": self.start_command,
|
||||
"status": self.status,
|
||||
"environment": self.environment,
|
||||
"node_directory": self.working_dir
|
||||
"node_directory": self.working_path
|
||||
}
|
||||
|
||||
def _get_free_display_port(self):
|
||||
|
@ -194,7 +194,7 @@ class IOUVM(BaseNode):
|
||||
|
||||
iou_vm_info = {"name": self.name,
|
||||
"node_id": self.id,
|
||||
"node_directory": self.working_dir,
|
||||
"node_directory": self.working_path,
|
||||
"console": self._console,
|
||||
"console_type": "telnet",
|
||||
"status": self.status,
|
||||
|
@ -207,7 +207,7 @@ class Project:
|
||||
:returns: Node working directory
|
||||
"""
|
||||
|
||||
workdir = os.path.join(self._path, "project-files", node.manager.module_name.lower(), node.id)
|
||||
workdir = self.node_working_path(node)
|
||||
if not self._deleted:
|
||||
try:
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
@ -215,6 +215,15 @@ class Project:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create the node working directory: {}".format(e))
|
||||
return workdir
|
||||
|
||||
def node_working_path(self, node):
|
||||
"""
|
||||
Returns a node working path for node. It doesn't create structure if not present on system.
|
||||
:param node: Node instance
|
||||
:return: Node working path
|
||||
"""
|
||||
return os.path.join(self._path, "project-files", node.manager.module_name.lower(), node.id)
|
||||
|
||||
|
||||
def tmp_working_directory(self):
|
||||
"""
|
||||
A temporary directory. Will be clean at project open and close
|
||||
|
@ -1626,7 +1626,7 @@ class QemuVM(BaseNode):
|
||||
answer = {
|
||||
"project_id": self.project.id,
|
||||
"node_id": self.id,
|
||||
"node_directory": self.working_dir
|
||||
"node_directory": self.working_path
|
||||
}
|
||||
# Qemu has a long list of options. The JSON schema is the single source of information
|
||||
for field in QEMU_OBJECT_SCHEMA["required"]:
|
||||
|
@ -89,7 +89,7 @@ class VirtualBoxVM(BaseNode):
|
||||
"use_any_adapter": self.use_any_adapter,
|
||||
"linked_clone": self.linked_clone}
|
||||
if self.linked_clone:
|
||||
json["node_directory"] = self.working_dir
|
||||
json["node_directory"] = self.working_path
|
||||
else:
|
||||
json["node_directory"] = None
|
||||
return json
|
||||
|
@ -86,7 +86,7 @@ class VMwareVM(BaseNode):
|
||||
"adapter_type": self.adapter_type,
|
||||
"use_any_adapter": self.use_any_adapter,
|
||||
"status": self.status,
|
||||
"node_directory": self.working_dir,
|
||||
"node_directory": self.working_path,
|
||||
"linked_clone": self.linked_clone}
|
||||
return json
|
||||
|
||||
|
@ -127,7 +127,7 @@ class VPCSVM(BaseNode):
|
||||
|
||||
return {"name": self.name,
|
||||
"node_id": self.id,
|
||||
"node_directory": self.working_dir,
|
||||
"node_directory": self.working_path,
|
||||
"status": self.status,
|
||||
"console": self._console,
|
||||
"console_type": "telnet",
|
||||
|
@ -106,6 +106,16 @@ def test_node_working_directory(tmpdir, node):
|
||||
assert os.path.exists(p.node_working_directory(node))
|
||||
|
||||
|
||||
def test_node_working_path(tmpdir, node):
|
||||
directory = Config.instance().get_section_config("Server").get("projects_path")
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
assert p.node_working_path(node) == os.path.join(directory, p.id, 'project-files', node.module_name, node.id)
|
||||
# after this execution directory structure should not be created
|
||||
assert not os.path.exists(p.node_working_path(node))
|
||||
|
||||
|
||||
def test_project_delete(loop):
|
||||
project = Project(project_id=str(uuid4()))
|
||||
directory = project.path
|
||||
|
Loading…
Reference in New Issue
Block a user