mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
API in order to get the list of IOU, Dynamips, Qemu images
This commit is contained in:
1 parent
5a4ffae6a2
commit
bca90bc563
14 files changed
+218
-36
No files matched your search
@@ -16,6 +16,10 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import os
|
||||
import stat
|
||||
from unittest.mock import patch
|
||||
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
@@ -123,3 +127,22 @@ from tests.utils import asyncio_patch
|
||||
# assert response.status == 200
|
||||
# assert response.json["name"] == "test"
|
||||
# assert response.json["console"] == free_console_port
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_dynamips(tmpdir):
|
||||
"""Create a fake IOU image on disk"""
|
||||
|
||||
path = str(tmpdir / "7200.bin")
|
||||
with open(path, "w+") as f:
|
||||
f.write('1')
|
||||
os.chmod(path, stat.S_IREAD)
|
||||
return path
|
||||
|
||||
|
||||
def test_vms(server, tmpdir, fake_dynamips):
|
||||
|
||||
with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir), example=True):
|
||||
response = server.get("/dynamips/vms")
|
||||
assert response.status == 200
|
||||
assert response.json == [{"filename": "7200.bin"}]
|
||||
@@ -284,3 +284,11 @@ def test_get_initial_config_with_config_file(server, project, vm):
|
||||
response = server.get("/projects/{project_id}/iou/vms/{vm_id}/initial_config".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
||||
assert response.status == 200
|
||||
assert response.json["content"] == "TEST"
|
||||
|
||||
|
||||
def test_vms(server, vm, tmpdir, fake_iou_bin):
|
||||
|
||||
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir), example=True):
|
||||
response = server.get("/iou/vms")
|
||||
assert response.status == 200
|
||||
assert response.json == [{"filename": "iou.bin"}]
|
||||
@@ -32,12 +32,32 @@ def fake_qemu_bin():
|
||||
return bin_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_qemu_vm(tmpdir):
|
||||
|
||||
bin_path = os.path.join(str(tmpdir / "linux.img"))
|
||||
with open(bin_path, "w+") as f:
|
||||
f.write("1")
|
||||
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||
return bin_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def base_params(tmpdir, fake_qemu_bin):
|
||||
"""Return standard parameters"""
|
||||
return {"name": "PC TEST 1", "qemu_path": fake_qemu_bin}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_qemu_bin():
|
||||
|
||||
bin_path = os.path.join(os.environ["PATH"], "qemu_x42")
|
||||
with open(bin_path, "w+") as f:
|
||||
f.write("1")
|
||||
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||
return bin_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vm(server, project, base_params):
|
||||
response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), base_params)
|
||||
@@ -175,3 +195,11 @@ def test_qemu_list_binaries(server, vm):
|
||||
assert mock.called
|
||||
assert response.status == 200
|
||||
assert response.json == ret
|
||||
|
||||
|
||||
def test_vms(server, tmpdir, fake_qemu_vm):
|
||||
|
||||
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir), example=True):
|
||||
response = server.get("/qemu/vms")
|
||||
assert response.status == 200
|
||||
assert response.json == [{"filename": "linux.img"}]
|
||||
Reference in new issue
Block a user