mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 16:54:51 +02:00
Filter snapshots directory during the snapshot, Fixes: #1297
This commit is contained in:
parent
835bc24b44
commit
09c7d73ee9
@ -29,7 +29,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def export_project(project, temporary_dir, include_images=False, keep_compute_id=False, allow_all_nodes=False):
|
||||
def export_project(project, temporary_dir, include_images=False, keep_compute_id=False,
|
||||
allow_all_nodes=False, ignore_prefixes=None):
|
||||
"""
|
||||
Export the project as zip. It's a ZipStream object.
|
||||
The file will be read chunk by chunk when you iterate on
|
||||
@ -111,6 +112,10 @@ def _filter_files(path):
|
||||
if path.endswith("snapshots"):
|
||||
return True
|
||||
|
||||
# filter directory of snapshots
|
||||
if "{sep}snapshots{sep}".format(sep=os.path.sep) in path:
|
||||
return True
|
||||
|
||||
try:
|
||||
i = s.index("project-files")
|
||||
if s[i + 1] in ("tmp", "captures", "snapshots"):
|
||||
|
@ -22,6 +22,7 @@ import pytest
|
||||
import aiohttp
|
||||
import zipfile
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock
|
||||
from tests.utils import AsyncioMagicMock, AsyncioBytesIO
|
||||
@ -417,3 +418,42 @@ def test_export_images_from_vm(tmpdir, project, async_run, controller):
|
||||
with myzip.open("images/dynamips/test.image") as myfile:
|
||||
content = myfile.read()
|
||||
assert content == b"IMAGE"
|
||||
|
||||
|
||||
def test_export_with_ignoring_snapshots(tmpdir, project, async_run):
|
||||
with open(os.path.join(project.path, "test.gns3"), 'w+') as f:
|
||||
data = {
|
||||
"topology": {
|
||||
"computes": [
|
||||
{
|
||||
"compute_id": "6b7149c8-7d6e-4ca0-ab6b-daa8ab567be0",
|
||||
"host": "127.0.0.1",
|
||||
"name": "Remote 1",
|
||||
"port": 8001,
|
||||
"protocol": "http"
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"compute_id": "6b7149c8-7d6e-4ca0-ab6b-daa8ab567be0",
|
||||
"node_type": "vpcs"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
json.dump(data, f)
|
||||
|
||||
# create snapshot directory
|
||||
snapshots_dir = os.path.join(project.path, 'snapshots')
|
||||
os.makedirs(snapshots_dir)
|
||||
Path(os.path.join(snapshots_dir, 'snap.gns3project')).touch()
|
||||
|
||||
z = async_run(export_project(project, str(tmpdir), keep_compute_id=True))
|
||||
|
||||
with open(str(tmpdir / 'zipfile.zip'), 'wb') as f:
|
||||
for data in z:
|
||||
f.write(data)
|
||||
|
||||
with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip:
|
||||
assert not os.path.join('snapshots', 'snap.gns3project') in [f.filename for f in myzip.filelist]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user