|
21 | 21 | import zipfile
|
22 | 22 |
|
23 | 23 | from tests.utils import asyncio_patch, AsyncioMagicMock
|
| 24 | +from unittest.mock import patch, MagicMock |
24 | 25 |
|
| 26 | +from gns3server.utils.asyncio import aiozipstream |
| 27 | +from gns3server.controller.project import Project |
| 28 | +from gns3server.controller.export_project import export_project |
25 | 29 | from gns3server.controller.import_project import import_project, _move_files_to_compute
|
26 | 30 | from gns3server.version import __version__
|
27 | 31 |
|
@@ -106,6 +110,54 @@ async def test_import_project_override(tmpdir, controller):
|
106 | 110 | assert project.name == "test"
|
107 | 111 |
|
108 | 112 |
|
| 113 | +async def write_file(path, z): |
| 114 | + |
| 115 | + with open(path, 'wb') as f: |
| 116 | + async for chunk in z: |
| 117 | + f.write(chunk) |
| 118 | + |
| 119 | + |
| 120 | +async def test_import_project_containing_symlink(tmpdir, controller): |
| 121 | + |
| 122 | + project = Project(controller=controller, name="test") |
| 123 | + project.dump = MagicMock() |
| 124 | + path = project.path |
| 125 | + |
| 126 | + project_id = str(uuid.uuid4()) |
| 127 | + topology = { |
| 128 | + "project_id": str(uuid.uuid4()), |
| 129 | + "name": "test", |
| 130 | + "auto_open": True, |
| 131 | + "auto_start": True, |
| 132 | + "topology": { |
| 133 | + }, |
| 134 | + "version": "2.0.0" |
| 135 | + } |
| 136 | + |
| 137 | + with open(os.path.join(path, "project.gns3"), 'w+') as f: |
| 138 | + json.dump(topology, f) |
| 139 | + |
| 140 | + os.makedirs(os.path.join(path, "vm1", "dynamips")) |
| 141 | + symlink_path = os.path.join(project.path, "vm1", "dynamips", "symlink") |
| 142 | + symlink_target = "/tmp/anywhere" |
| 143 | + os.symlink(symlink_target, symlink_path) |
| 144 | + |
| 145 | + zip_path = str(tmpdir / "project.zip") |
| 146 | + with aiozipstream.ZipFile() as z: |
| 147 | + with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir / "IOS"),): |
| 148 | + await export_project(z, project, str(tmpdir), include_images=False) |
| 149 | + await write_file(zip_path, z) |
| 150 | + |
| 151 | + with open(zip_path, "rb") as f: |
| 152 | + project = await import_project(controller, project_id, f) |
| 153 | + |
| 154 | + assert project.name == "test" |
| 155 | + assert project.id == project_id |
| 156 | + symlink_path = os.path.join(project.path, "vm1", "dynamips", "symlink") |
| 157 | + assert os.path.islink(symlink_path) |
| 158 | + assert os.readlink(symlink_path) == symlink_target |
| 159 | + |
| 160 | + |
109 | 161 | async def test_import_upgrade(tmpdir, controller):
|
110 | 162 | """
|
111 | 163 | Topology made for previous GNS3 version are upgraded during the process
|
|
0 commit comments