mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 06:41:13 +02:00
1 parent
0f15e4b56a
commit
f041697311
15 files changed
+248
-16
No files matched your search
@@ -156,6 +156,10 @@ def test_upload_vm(server, tmpdir):
|
||||
with open(str(tmpdir / "test2")) as f:
|
||||
assert f.read() == "TEST"
|
||||
|
||||
with open(str(tmpdir / "test2.md5sum")) as f:
|
||||
checksum = f.read()
|
||||
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
|
||||
|
||||
|
||||
def test_upload_vm_permission_denied(server, tmpdir):
|
||||
with open(str(tmpdir / "test2"), "w+") as f:
|
||||
|
||||
@@ -301,6 +301,7 @@ def test_get_configs_without_configs_file(server, vm):
|
||||
assert "startup_config" not in response.json
|
||||
assert "private_config" not in response.json
|
||||
|
||||
|
||||
def test_get_configs_with_startup_config_file(server, project, vm):
|
||||
|
||||
path = startup_config_file(project, vm)
|
||||
@@ -328,6 +329,10 @@ def test_upload_vm(server, tmpdir):
|
||||
with open(str(tmpdir / "test2")) as f:
|
||||
assert f.read() == "TEST"
|
||||
|
||||
with open(str(tmpdir / "test2.md5sum")) as f:
|
||||
checksum = f.read()
|
||||
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
|
||||
|
||||
|
||||
def test_upload_vm_permission_denied(server, tmpdir):
|
||||
with open(str(tmpdir / "test2"), "w+") as f:
|
||||
|
||||
@@ -88,10 +88,10 @@ def test_qemu_create_platform(server, project, base_params, fake_qemu_bin):
|
||||
assert response.json["platform"] == "x86_64"
|
||||
|
||||
|
||||
def test_qemu_create_with_params(server, project, base_params):
|
||||
def test_qemu_create_with_params(server, project, base_params, fake_qemu_vm):
|
||||
params = base_params
|
||||
params["ram"] = 1024
|
||||
params["hda_disk_image"] = "/tmp/hda"
|
||||
params["hda_disk_image"] = fake_qemu_vm
|
||||
|
||||
response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), params, example=True)
|
||||
assert response.status == 201
|
||||
@@ -99,7 +99,7 @@ def test_qemu_create_with_params(server, project, base_params):
|
||||
assert response.json["name"] == "PC TEST 1"
|
||||
assert response.json["project_id"] == project.id
|
||||
assert response.json["ram"] == 1024
|
||||
assert response.json["hda_disk_image"] == "/tmp/hda"
|
||||
assert response.json["hda_disk_image"] == fake_qemu_vm
|
||||
|
||||
|
||||
def test_qemu_get(server, project, vm):
|
||||
@@ -152,18 +152,18 @@ def test_qemu_delete(server, vm):
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_qemu_update(server, vm, tmpdir, free_console_port, project):
|
||||
def test_qemu_update(server, vm, tmpdir, free_console_port, project, fake_qemu_vm):
|
||||
params = {
|
||||
"name": "test",
|
||||
"console": free_console_port,
|
||||
"ram": 1024,
|
||||
"hdb_disk_image": "/tmp/hdb"
|
||||
"hdb_disk_image": fake_qemu_vm
|
||||
}
|
||||
response = server.put("/projects/{project_id}/qemu/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), params, example=True)
|
||||
assert response.status == 200
|
||||
assert response.json["name"] == "test"
|
||||
assert response.json["console"] == free_console_port
|
||||
assert response.json["hdb_disk_image"] == "/tmp/hdb"
|
||||
assert response.json["hdb_disk_image"] == fake_qemu_vm
|
||||
assert response.json["ram"] == 1024
|
||||
|
||||
|
||||
@@ -225,6 +225,10 @@ def test_upload_vm(server, tmpdir):
|
||||
with open(str(tmpdir / "test2")) as f:
|
||||
assert f.read() == "TEST"
|
||||
|
||||
with open(str(tmpdir / "test2.md5sum")) as f:
|
||||
checksum = f.read()
|
||||
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
|
||||
|
||||
|
||||
def test_upload_vm_permission_denied(server, tmpdir):
|
||||
with open(str(tmpdir / "test2"), "w+") as f:
|
||||
|
||||
@@ -21,12 +21,23 @@ import os
|
||||
from unittest.mock import patch
|
||||
from gns3server.config import Config
|
||||
|
||||
def test_index_upload(server):
|
||||
|
||||
def test_index_upload(server, tmpdir):
|
||||
|
||||
Config.instance().set("Server", "images_path", str(tmpdir))
|
||||
|
||||
open(str(tmpdir / "alpha"), "w+").close()
|
||||
open(str(tmpdir / "alpha.md5sum"), "w+").close()
|
||||
open(str(tmpdir / ".beta"), "w+").close()
|
||||
|
||||
response = server.get('/upload', api_version=None)
|
||||
assert response.status == 200
|
||||
html = response.html
|
||||
assert "GNS3 Server" in html
|
||||
assert "Select & Upload" in html
|
||||
assert "alpha" in html
|
||||
assert ".beta" not in html
|
||||
assert "alpha.md5sum" not in html
|
||||
|
||||
|
||||
def test_upload(server, tmpdir):
|
||||
@@ -40,9 +51,43 @@ def test_upload(server, tmpdir):
|
||||
body.add_field("file", open(str(tmpdir / "test"), "rb"), content_type="application/iou", filename="test2")
|
||||
|
||||
Config.instance().set("Server", "images_path", str(tmpdir))
|
||||
|
||||
response = server.post('/upload', api_version=None, body=body, raw=True)
|
||||
|
||||
assert "test2" in response.body.decode("utf-8")
|
||||
|
||||
with open(str(tmpdir / "QEMU" / "test2")) as f:
|
||||
assert f.read() == content
|
||||
|
||||
with open(str(tmpdir / "QEMU" / "test2.md5sum")) as f:
|
||||
checksum = f.read()
|
||||
assert checksum == "ae187e1febee2a150b64849c32d566ca"
|
||||
|
||||
|
||||
def test_upload_previous_checksum(server, tmpdir):
|
||||
|
||||
content = ''.join(['a' for _ in range(0, 1025)])
|
||||
|
||||
with open(str(tmpdir / "test"), "w+") as f:
|
||||
f.write(content)
|
||||
body = aiohttp.FormData()
|
||||
body.add_field("type", "QEMU")
|
||||
body.add_field("file", open(str(tmpdir / "test"), "rb"), content_type="application/iou", filename="test2")
|
||||
|
||||
Config.instance().set("Server", "images_path", str(tmpdir))
|
||||
|
||||
os.makedirs(str(tmpdir / "QEMU"))
|
||||
|
||||
with open(str(tmpdir / "QEMU" / "test2.md5sum"), 'w+') as f:
|
||||
f.write("FAKE checksum")
|
||||
|
||||
response = server.post('/upload', api_version=None, body=body, raw=True)
|
||||
|
||||
assert "test2" in response.body.decode("utf-8")
|
||||
|
||||
with open(str(tmpdir / "QEMU" / "test2")) as f:
|
||||
assert f.read() == content
|
||||
|
||||
with open(str(tmpdir / "QEMU" / "test2.md5sum")) as f:
|
||||
checksum = f.read()
|
||||
assert checksum == "ae187e1febee2a150b64849c32d566ca"
|
||||
@@ -125,7 +125,7 @@ def test_get_relative_image_path(qemu, tmpdir):
|
||||
|
||||
def test_list_images(loop, qemu, tmpdir):
|
||||
|
||||
fake_images = ["a.bin", "b.bin", ".blu.bin"]
|
||||
fake_images = ["a.bin", "b.bin", ".blu.bin", "a.bin.md5sum"]
|
||||
for image in fake_images:
|
||||
with open(str(tmpdir / image), "w+") as f:
|
||||
f.write("1")
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
|
||||
from gns3server.utils.images import md5sum, remove_checksum
|
||||
|
||||
|
||||
def test_md5sum(tmpdir):
|
||||
fake_img = str(tmpdir / 'hello')
|
||||
|
||||
with open(fake_img, 'w+') as f:
|
||||
f.write('hello')
|
||||
|
||||
assert md5sum(fake_img) == '5d41402abc4b2a76b9719d911017c592'
|
||||
with open(str(tmpdir / 'hello.md5sum')) as f:
|
||||
assert f.read() == '5d41402abc4b2a76b9719d911017c592'
|
||||
|
||||
|
||||
def test_md5sum_existing_digest(tmpdir):
|
||||
fake_img = str(tmpdir / 'hello')
|
||||
|
||||
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
|
||||
f.write('aaaaa02abc4b2a76b9719d911017c592')
|
||||
|
||||
assert md5sum(fake_img) == 'aaaaa02abc4b2a76b9719d911017c592'
|
||||
|
||||
|
||||
def test_md5sum_none(tmpdir):
|
||||
assert md5sum(None) is None
|
||||
|
||||
|
||||
def test_remove_checksum(tmpdir):
|
||||
|
||||
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
|
||||
f.write('aaaaa02abc4b2a76b9719d911017c592')
|
||||
remove_checksum(str(tmpdir / 'hello'))
|
||||
|
||||
assert not os.path.exists(str(tmpdir / 'hello.md5sum'))
|
||||
|
||||
remove_checksum(str(tmpdir / 'not_exists'))
|
||||
Reference in new issue
Block a user