Revert "Merge branch 'unstable'"

This reverts commit 929c337e8b, reversing
changes made to b9bc73fd01.
This commit is contained in:
Julien Duponchelle committed 2015-04-30 16:43:30 +02:00
1 parent d18293ae7c
commit 359abb0286
24 files changed
+217 -677

No files matched your search

+2 -2
View File
@@ -44,7 +44,7 @@ class Query:
def delete(self, path, **kwargs):
return self._fetch("DELETE", path, **kwargs)
def get_url(self, path, version):
def _get_url(self, path, version):
if version is None:
return "http://{}:{}{}".format(self._host, self._port, path)
return "http://{}:{}/v{}{}".format(self._host, self._port, version, path)
@@ -62,7 +62,7 @@ class Query:
@asyncio.coroutine
def go(future):
response = yield from aiohttp.request(method, self.get_url(path, api_version), data=body)
response = yield from aiohttp.request(method, self._get_url(path, api_version), data=body)
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future))
-23
View File
@@ -16,10 +16,6 @@
# 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
@@ -127,22 +123,3 @@ 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"}]
-62
View File
@@ -1,62 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 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/>.
"""
This test suite check /files endpoint
"""
import json
import asyncio
import aiohttp
from gns3server.version import __version__
def test_stream(server, tmpdir, loop):
with open(str(tmpdir / "test"), 'w+') as f:
f.write("hello")
def go(future):
query = json.dumps({"location": str(tmpdir / "test")})
headers = {'content-type': 'application/json'}
response = yield from aiohttp.request("GET", server.get_url("/files/stream", 1), data=query, headers=headers)
response.body = yield from response.content.read(5)
with open(str(tmpdir / "test"), 'a') as f:
f.write("world")
response.body += yield from response.content.read(5)
response.close()
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future))
response = loop.run_until_complete(future)
assert response.status == 200
assert response.body == b'helloworld'
def test_stream_file_not_found(server, tmpdir, loop):
def go(future):
query = json.dumps({"location": str(tmpdir / "test")})
headers = {'content-type': 'application/json'}
response = yield from aiohttp.request("GET", server.get_url("/files/stream", 1), data=query, headers=headers)
response.close()
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future))
response = loop.run_until_complete(future)
assert response.status == 404
-8
View File
@@ -309,11 +309,3 @@ 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"}]
-28
View File
@@ -32,32 +32,12 @@ 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)
@@ -192,11 +172,3 @@ 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"}]
+15 -3
View File
@@ -40,7 +40,11 @@ def iou(port_manager):
return iou
def test_get_application_id(loop, project, iou):
def test_get_application_id(loop, project, port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
vm1_id = str(uuid.uuid4())
vm2_id = str(uuid.uuid4())
vm3_id = str(uuid.uuid4())
@@ -54,7 +58,11 @@ def test_get_application_id(loop, project, iou):
assert iou.get_application_id(vm3_id) == 1
def test_get_application_id_multiple_project(loop, iou):
def test_get_application_id_multiple_project(loop, port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
vm1_id = str(uuid.uuid4())
vm2_id = str(uuid.uuid4())
vm3_id = str(uuid.uuid4())
@@ -68,7 +76,11 @@ def test_get_application_id_multiple_project(loop, iou):
assert iou.get_application_id(vm3_id) == 3
def test_get_application_id_no_id_available(loop, project, iou):
def test_get_application_id_no_id_available(loop, project, port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
with pytest.raises(IOUError):
for i in range(1, 513):
vm_id = str(uuid.uuid4())
+38 -55
View File
@@ -22,33 +22,33 @@ from unittest.mock import patch
from gns3server.modules.vpcs import VPCS
from gns3server.modules.iou import IOU
from gns3server.modules.qemu import Qemu
@pytest.fixture(scope="function")
def vpcs(port_manager):
def qemu(port_manager):
Qemu._instance = None
qemu = Qemu.instance()
qemu.port_manager = port_manager
return qemu
def test_create_vm_new_topology(loop, project, port_manager):
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
return vpcs
@pytest.fixture(scope="function")
def iou(port_manager):
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
return iou
def test_create_vm_new_topology(loop, project, vpcs):
vm_id = str(uuid.uuid4())
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm_id))
assert vm in project.vms
def test_create_twice_same_vm_new_topology(loop, project, vpcs):
def test_create_twice_same_vm_new_topology(loop, project, port_manager):
project._vms = set()
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
vm_id = str(uuid.uuid4())
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm_id, console=2222))
assert vm in project.vms
@@ -57,13 +57,17 @@ def test_create_twice_same_vm_new_topology(loop, project, vpcs):
assert len(project.vms) == 1
def test_create_vm_new_topology_without_uuid(loop, project, vpcs):
def test_create_vm_new_topology_without_uuid(loop, project, port_manager):
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, None))
assert vm in project.vms
assert len(vm.id) == 36
def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
with patch("gns3server.modules.project.Project.is_local", return_value=True):
# Create an old topology directory
@@ -75,6 +79,9 @@ def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
with open(os.path.join(vm_dir, "startup.vpc"), "w+") as f:
f.write("1")
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
vm_id = 1
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm_id))
assert len(vm.id) == 36
@@ -86,55 +93,31 @@ def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
assert f.read() == "1"
def test_get_abs_image_path(iou, tmpdir):
os.makedirs(str(tmpdir / "IOU"))
def test_get_abs_image_path(qemu, tmpdir):
os.makedirs(str(tmpdir / "QEMU"))
path1 = str(tmpdir / "test1.bin")
open(path1, 'w+').close()
path2 = str(tmpdir / "IOU" / "test2.bin")
path2 = str(tmpdir / "QEMU" / "test2.bin")
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_abs_image_path(path1) == path1
assert iou.get_abs_image_path(path2) == path2
assert iou.get_abs_image_path("test2.bin") == path2
assert iou.get_abs_image_path("../test1.bin") == path1
assert qemu.get_abs_image_path(path1) == path1
assert qemu.get_abs_image_path(path2) == path2
assert qemu.get_abs_image_path("test2.bin") == path2
assert qemu.get_abs_image_path("../test1.bin") == path1
def test_get_relative_image_path(iou, tmpdir):
os.makedirs(str(tmpdir / "IOU"))
def test_get_relative_image_path(qemu, tmpdir):
os.makedirs(str(tmpdir / "QEMU"))
path1 = str(tmpdir / "test1.bin")
open(path1, 'w+').close()
path2 = str(tmpdir / "IOU" / "test2.bin")
path2 = str(tmpdir / "QEMU" / "test2.bin")
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_relative_image_path(path1) == path1
assert iou.get_relative_image_path(path2) == "test2.bin"
assert iou.get_relative_image_path("test2.bin") == "test2.bin"
assert iou.get_relative_image_path("../test1.bin") == path1
def test_list_images(loop, iou, tmpdir):
fake_images = ["a.bin", "b.bin", ".blu.bin"]
for image in fake_images:
with open(str(tmpdir / image), "w+") as f:
f.write("1")
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(iou.list_images()) == [
{"filename": "a.bin"},
{"filename": "b.bin"}
]
def test_list_images_empty(loop, iou, tmpdir):
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(iou.list_images()) == []
def test_list_images_directory_not_exist(loop, iou):
with patch("gns3server.modules.IOU.get_images_directory", return_value="/bla"):
assert loop.run_until_complete(iou.list_images()) == []
assert qemu.get_relative_image_path(path1) == path1
assert qemu.get_relative_image_path(path2) == "test2.bin"
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
assert qemu.get_relative_image_path("../test1.bin") == path1