From 45af721164990ce7266e60dcbcf0205a39862e8a Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 28 Jul 2016 18:11:52 +0200 Subject: [PATCH] Support convertsion of 1.5 snapshots Fix #618 --- gns3server/controller/topology.py | 37 ++++++++++++- tests/test_topologies.py | 9 +++ .../1_5_snapshot/after/1_5_snapshot.gns3 | 45 +++++++++++++++ .../startup.vpc | 1 + .../onedevice_280716_174116.gns3project | Bin 0 -> 4632 bytes .../1_5_snapshot/before/1_5_snapshot.gns3 | 52 ++++++++++++++++++ .../startup.vpc | 1 + .../onedevice_280716_174116/screenshot.png | Bin 0 -> 3758 bytes .../onedevice_280716_174116/testsnapshot.gns3 | 52 ++++++++++++++++++ .../startup.vpc | 1 + 10 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 tests/topologies/1_5_snapshot/after/1_5_snapshot.gns3 create mode 100644 tests/topologies/1_5_snapshot/after/project-files/vpcs/992c28fd-4bc3-4508-9300-48600148f64a/startup.vpc create mode 100644 tests/topologies/1_5_snapshot/after/snapshots/onedevice_280716_174116.gns3project create mode 100644 tests/topologies/1_5_snapshot/before/1_5_snapshot.gns3 create mode 100644 tests/topologies/1_5_snapshot/before/project-files/snapshots/onedevice_280716_174116/project-files/vpcs/992c28fd-4bc3-4508-9300-48600148f64a/startup.vpc create mode 100644 tests/topologies/1_5_snapshot/before/project-files/snapshots/onedevice_280716_174116/screenshot.png create mode 100644 tests/topologies/1_5_snapshot/before/project-files/snapshots/onedevice_280716_174116/testsnapshot.gns3 create mode 100644 tests/topologies/1_5_snapshot/before/project-files/vpcs/992c28fd-4bc3-4508-9300-48600148f64a/startup.vpc diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index bf6eb7f6..46a235dc 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -17,10 +17,12 @@ import os import json -import jsonschema import uuid import shutil +import zipfile import aiohttp +import jsonschema + from ..version import __version__ from ..schemas.topology import TOPOLOGY_SCHEMA @@ -108,6 +110,8 @@ def _convert_1_3_later(topo, topo_path): """ topo_dir = os.path.dirname(topo_path) + _convert_snapshots(topo_dir) + new_topo = { "type": "topology", "revision": GNS3_FILE_FORMAT_REVISION, @@ -448,3 +452,34 @@ def _create_cloud(node, old_node, icon): node["properties"]["ports"] = ports node["properties"]["interfaces"] = [] + + +def _convert_snapshots(topo_dir): + """ + Convert 1.x snapshot to the new format + """ + old_snapshots_dir = os.path.join(topo_dir, "project-files", "snapshots") + if os.path.exists(old_snapshots_dir): + new_snapshots_dir = os.path.join(topo_dir, "snapshots") + os.makedirs(new_snapshots_dir) + + for snapshot in os.listdir(old_snapshots_dir): + snapshot_dir = os.path.join(old_snapshots_dir, snapshot) + if os.path.isdir(snapshot_dir): + is_gns3_topo = False + + # In .gns3project fileformat the .gns3 should be name project.gns3 + for file in os.listdir(snapshot_dir): + if file.endswith(".gns3"): + shutil.move(os.path.join(snapshot_dir, file), os.path.join(snapshot_dir, "project.gns3")) + is_gns3_topo = True + + if is_gns3_topo: + snapshot_arc = os.path.join(new_snapshots_dir, snapshot + ".gns3project") + with zipfile.ZipFile(snapshot_arc, 'w') as myzip: + for root, dirs, files in os.walk(snapshot_dir): + for file in files: + myzip.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), snapshot_dir), compress_type=zipfile.ZIP_DEFLATED) + shutil.copy(snapshot_arc, "/tmp/test.zip") + + shutil.rmtree(old_snapshots_dir) diff --git a/tests/test_topologies.py b/tests/test_topologies.py index 322aa127..7a1186eb 100644 --- a/tests/test_topologies.py +++ b/tests/test_topologies.py @@ -81,6 +81,15 @@ def test_convert(directory, tmpdir): if not file_path.endswith(".gns3"): assert os.stat(file_path).st_size == os.stat(os.path.join(os.path.join(root, file))).st_size, "File {} is different".format(os.path.join(directory, file)) + # Check if we don't have unexpected file in work directory + for root, dirs, files in os.walk(work_directory): + for file in files: + directory = os.path.relpath(root, work_directory) + file_path = os.path.join(after_directory, directory, file) + # .backup are created by the conversion process + if not file.endswith(".backup"): + assert os.path.exists(file_path), "{} should not be here".format(os.path.join(directory, file)) + compare_dict("/", work_topology, after_topology) diff --git a/tests/topologies/1_5_snapshot/after/1_5_snapshot.gns3 b/tests/topologies/1_5_snapshot/after/1_5_snapshot.gns3 new file mode 100644 index 00000000..dd611145 --- /dev/null +++ b/tests/topologies/1_5_snapshot/after/1_5_snapshot.gns3 @@ -0,0 +1,45 @@ +{ + "type" : "topology", + "version" : "2.0.0dev1", + "topology" : { + "nodes" : [ + { + "compute_id" : "local", + "z" : 1, + "y" : -51, + "node_id" : "992c28fd-4bc3-4508-9300-48600148f64a", + "x" : -128, + "console" : 5000, + "node_type" : "vpcs", + "name" : "PC1", + "symbol" : ":/symbols/vpcs_guest.svg", + "console_type" : "telnet", + "properties" : { + "startup_script_path" : "startup.vpc" + }, + "label" : { + "y" : -25, + "style" : "font-family: TypeWriter;font-size: 10;font-weight: bold;fill: #000000;fill-opacity: 1.0;", + "x" : 18, + "text" : "PC1", + "rotation" : 0 + } + } + ], + "links" : [], + "drawings" : [], + "computes" : [ + { + "name" : "Local", + "host" : "127.0.0.1", + "compute_id" : "local", + "protocol" : "http", + "port" : 3080 + } + ] + }, + "revision" : 5, + "name" : "1_5_snapshot", + "project_id" : "17912669-dd40-4843-b348-689b8f34f09d", + "auto_start" : false +} diff --git a/tests/topologies/1_5_snapshot/after/project-files/vpcs/992c28fd-4bc3-4508-9300-48600148f64a/startup.vpc b/tests/topologies/1_5_snapshot/after/project-files/vpcs/992c28fd-4bc3-4508-9300-48600148f64a/startup.vpc new file mode 100644 index 00000000..d46a9c6f --- /dev/null +++ b/tests/topologies/1_5_snapshot/after/project-files/vpcs/992c28fd-4bc3-4508-9300-48600148f64a/startup.vpc @@ -0,0 +1 @@ +set pcname PC1 diff --git a/tests/topologies/1_5_snapshot/after/snapshots/onedevice_280716_174116.gns3project b/tests/topologies/1_5_snapshot/after/snapshots/onedevice_280716_174116.gns3project new file mode 100644 index 0000000000000000000000000000000000000000..64330d85c4e539e99bc88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