mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch 'unstable' into api_list_images
Conflicts: gns3server/handlers/api/iou_handler.py
This commit is contained in:
commit
40ce22222e
17 files changed
+238
-35
No files matched your search
@@ -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))
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# -*- 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
|
||||
@@ -81,11 +81,11 @@ def test_vm(project, manager):
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
def test_vm_initial_config(project, manager):
|
||||
def test_vm_initial_config_content(project, manager):
|
||||
vm = IOUVM("test", "00010203-0405-0607-0808-0a0b0c0d0e0f", project, manager)
|
||||
vm.initial_config = "hostname %h"
|
||||
vm.initial_config_content = "hostname %h"
|
||||
assert vm.name == "test"
|
||||
assert vm.initial_config == "hostname test"
|
||||
assert vm.initial_config_content == "hostname test"
|
||||
assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@@ -287,10 +287,10 @@ def test_update_initial_config_empty(vm):
|
||||
assert f.read() == content
|
||||
|
||||
|
||||
def test_update_initial_config_h(vm):
|
||||
def test_update_initial_config_content_hostname(vm):
|
||||
content = "hostname %h\n"
|
||||
vm.name = "pc1"
|
||||
vm.initial_config = content
|
||||
vm.initial_config_content = content
|
||||
with open(vm.initial_config_file) as f:
|
||||
assert f.read() == "hostname pc1\n"
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_get_qemu_version(loop):
|
||||
|
||||
def test_binary_list(loop):
|
||||
|
||||
files_to_create = ["qemu-system-x86", "qemu-system-x42", "hello"]
|
||||
files_to_create = ["qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"]
|
||||
|
||||
for file_to_create in files_to_create:
|
||||
path = os.path.join(os.environ["PATH"], file_to_create)
|
||||
@@ -44,6 +44,7 @@ def test_binary_list(loop):
|
||||
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list()))
|
||||
|
||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": "2.2.0"} in qemus
|
||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": "2.2.0"} in qemus
|
||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": "2.2.0"} in qemus
|
||||
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": "2.2.0"} not in qemus
|
||||
|
||||
|
||||
Reference in new issue
Block a user