mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch '1.5' into 2.0
This commit is contained in:
3 files changed
+167
-5
No files matched your search
@@ -275,7 +275,7 @@ def test_emit(async_run):
|
||||
|
||||
|
||||
def test_export(tmpdir):
|
||||
project = Project()
|
||||
project = Project(project_id=str(uuid.uuid4()))
|
||||
path = project.path
|
||||
os.makedirs(os.path.join(path, "vm-1", "dynamips"))
|
||||
|
||||
@@ -308,9 +308,82 @@ def test_export(tmpdir):
|
||||
assert 'vm-1/dynamips/test_log.txt' not in myzip.namelist()
|
||||
|
||||
|
||||
def test_export(tmpdir):
|
||||
def test_export_fix_path(tmpdir):
|
||||
"""
|
||||
Fix absolute image path
|
||||
"""
|
||||
|
||||
project = Project(project_id=str(uuid.uuid4()))
|
||||
path = project.path
|
||||
|
||||
topology = {
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"properties": {
|
||||
"image": "/tmp/c3725-adventerprisek9-mz.124-25d.image"
|
||||
},
|
||||
"type": "C3725"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
with open(os.path.join(path, "test.gns3"), 'w+') as f:
|
||||
json.dump(topology, f)
|
||||
|
||||
z = project.export()
|
||||
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("project.gns3") as myfile:
|
||||
content = myfile.read().decode()
|
||||
topology = json.loads(content)
|
||||
assert topology["topology"]["nodes"][0]["properties"]["image"] == "c3725-adventerprisek9-mz.124-25d.image"
|
||||
|
||||
|
||||
def test_export_with_images(tmpdir):
|
||||
"""
|
||||
Fix absolute image path
|
||||
"""
|
||||
project = Project()
|
||||
path = project.path
|
||||
|
||||
os.makedirs(str(tmpdir / "IOS"))
|
||||
with open(str(tmpdir / "IOS" / "test.image"), "w+") as f:
|
||||
f.write("AAA")
|
||||
|
||||
topology = {
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"properties": {
|
||||
"image": "test.image"
|
||||
},
|
||||
"type": "C3725"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
with open(os.path.join(path, "test.gns3"), 'w+') as f:
|
||||
json.dump(topology, f)
|
||||
|
||||
with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir / "IOS"),):
|
||||
z = project.export(include_images=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:
|
||||
myzip.getinfo("images/IOS/test.image")
|
||||
|
||||
|
||||
def test_export_with_vm(tmpdir):
|
||||
project = Project()
|
||||
path = project.path
|
||||
os.makedirs(os.path.join(path, "vm-1", "dynamips"))
|
||||
|
||||
# The .gns3 should be renamed project.gns3 in order to simplify import
|
||||
@@ -409,3 +482,23 @@ def test_import(tmpdir):
|
||||
]
|
||||
assert content["topology"]["nodes"][0]["server_id"] == 1
|
||||
assert content["topology"]["nodes"][1]["server_id"] == 2
|
||||
|
||||
|
||||
def test_import_with_images(tmpdir):
|
||||
|
||||
project_id = str(uuid.uuid4())
|
||||
project = Project(name="test", project_id=project_id)
|
||||
|
||||
with open(str(tmpdir / "test.image"), 'w+') as f:
|
||||
f.write("B")
|
||||
|
||||
zip_path = str(tmpdir / "project.zip")
|
||||
with zipfile.ZipFile(zip_path, 'w') as myzip:
|
||||
myzip.write(str(tmpdir / "test.image"), "images/IOS/test.image")
|
||||
|
||||
with open(zip_path, "rb") as f:
|
||||
project.import_zip(f)
|
||||
|
||||
# TEST import images
|
||||
path = os.path.join(project._config().get("images_path"), "IOS", "test.image")
|
||||
assert os.path.exists(path), path
|
||||
Reference in new issue
Block a user