When importing a project fix the GNS3 version

This commit is contained in:
Julien Duponchelle committed 2016-07-22 11:52:59 +02:00
1 parent 9b499dc51e
commit 94a262cd46
7 files changed
+98 -13

No files matched your search

+18
View File
@@ -261,6 +261,14 @@ def test_streamFile(project, async_run, compute):
mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/stream/test/titi".format(project.id), auth=None)
def test_downloadFile(project, async_run, compute):
response = MagicMock()
response.status = 200
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
async_run(compute.download_file(project, "test/titi"))
mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/files/test/titi".format(project.id), auth=None)
def test_close(compute, async_run):
assert compute.connected is True
async_run(compute.close())
@@ -318,3 +326,13 @@ def test_images(compute, async_run, images_dir):
mock.assert_called_with("GET", "https://example.com:84/v2/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=False)
assert images == [{"filename": "linux.qcow2", "path": "linux.qcow2"}, {"filename": "asa.qcow2", "path": "asa.qcow2"}]
def test_list_files(project, async_run, compute):
res = [{"path": "test"}]
response = AsyncioMagicMock()
response.read = AsyncioMagicMock(return_value=json.dumps(res).encode())
response.status = 200
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
assert async_run(compute.list_files(project)) == res
mock.assert_any_call("GET", "https://example.com:84/v2/compute/projects/{}/files".format(project.id), auth=None, chunked=False, data=None, headers={'content-type': 'application/json'})
+40 -1
View File
@@ -24,9 +24,10 @@ import zipfile
from unittest.mock import patch
from unittest.mock import MagicMock
from tests.utils import AsyncioMagicMock
from tests.utils import AsyncioMagicMock, AsyncioBytesIO
from gns3server.controller.project import Project
from gns3server.controller.compute import Compute
from gns3server.controller.export_project import export_project, _filter_files
@@ -90,6 +91,44 @@ def test_export(tmpdir, project, async_run):
assert 'vm-1/dynamips/test_log.txt' not in myzip.namelist()
def test_export_vm(tmpdir, project, async_run, controller):
"""
If data is on a remote server export it locally before
sending it in the archive.
"""
compute = MagicMock()
compute.id = "vm"
compute.list_files = AsyncioMagicMock(return_value=[{"path": "vm-1/dynamips/test"}])
# Fake file that will be download from the vm
file_content = AsyncioBytesIO()
async_run(file_content.write(b"HELLO"))
file_content.seek(0)
compute.download_file = AsyncioMagicMock(return_value=file_content)
project._project_created_on_compute.add(compute)
path = project.path
os.makedirs(os.path.join(path, "vm-1", "dynamips"))
# The .gns3 should be renamed project.gns3 in order to simplify import
with open(os.path.join(path, "test.gns3"), 'w+') as f:
f.write("{}")
z = async_run(export_project(project, str(tmpdir)))
assert compute.list_files.called
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:
with myzip.open("vm-1/dynamips/test") as myfile:
content = myfile.read()
assert content == b"HELLO"
def test_export_disallow_running(tmpdir, project, node, async_run):
"""
Dissallow export when a node is running
+27 -2
View File
@@ -23,6 +23,7 @@ import zipfile
from gns3server.controller.project import Project
from gns3server.controller.import_project import import_project
from gns3server.version import __version__
def test_import_project(async_run, tmpdir, controller):
@@ -66,6 +67,32 @@ def test_import_project(async_run, tmpdir, controller):
assert project.name != "test"
def test_import_upgrade(async_run, tmpdir, controller):
project_id = str(uuid.uuid4())
topology = {
"project_id": str(uuid.uuid4()),
"name": "test",
"topology": {
},
"version": "1.4.2"
}
with open(str(tmpdir / "project.gns3"), 'w+') as f:
json.dump(topology, f)
zip_path = str(tmpdir / "project.zip")
with zipfile.ZipFile(zip_path, 'w') as myzip:
myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
with open(zip_path, "rb") as f:
project = async_run(import_project(controller, project_id, f))
with open(os.path.join(project.path, "test.gns3")) as f:
topo = json.load(f)
assert topo["version"] == __version__
def test_import_with_images(tmpdir, async_run, controller):
project_id = str(uuid.uuid4())
@@ -92,8 +119,6 @@ def test_import_with_images(tmpdir, async_run, controller):
with open(zip_path, "rb") as f:
project = async_run(import_project(controller, project_id, f))
print(project._config().get("images_path"))
# TEST import images
assert not os.path.exists(os.path.join(project.path, "images/IOS/test.image"))
path = os.path.join(project._config().get("images_path"), "IOS", "test.image")