mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch 'master' into 1.5
This commit is contained in:
8 files changed
+102
-13
No files matched your search
@@ -27,15 +27,15 @@ from gns3server.version import __version__
|
||||
|
||||
|
||||
def test_stream(server, tmpdir, loop):
|
||||
with open(str(tmpdir / "test"), 'w+') as f:
|
||||
with open(str(tmpdir / "test.pcap"), 'w+') as f:
|
||||
f.write("hello")
|
||||
|
||||
def go(future):
|
||||
query = json.dumps({"location": str(tmpdir / "test")})
|
||||
query = json.dumps({"location": str(tmpdir / "test.pcap")})
|
||||
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:
|
||||
with open(str(tmpdir / "test.pcap"), 'a') as f:
|
||||
f.write("world")
|
||||
response.body += yield from response.content.read(5)
|
||||
response.close()
|
||||
@@ -48,7 +48,7 @@ def test_stream(server, tmpdir, loop):
|
||||
assert response.body == b'helloworld'
|
||||
|
||||
|
||||
def test_stream_file_not_found(server, tmpdir, loop):
|
||||
def test_stream_file_not_pcap(server, tmpdir, loop):
|
||||
def go(future):
|
||||
query = json.dumps({"location": str(tmpdir / "test")})
|
||||
headers = {'content-type': 'application/json'}
|
||||
@@ -56,6 +56,20 @@ def test_stream_file_not_found(server, tmpdir, loop):
|
||||
response.close()
|
||||
future.set_result(response)
|
||||
|
||||
future = asyncio.Future()
|
||||
asyncio.async(go(future))
|
||||
response = loop.run_until_complete(future)
|
||||
assert response.status == 403
|
||||
|
||||
|
||||
def test_stream_file_not_found(server, tmpdir, loop):
|
||||
def go(future):
|
||||
query = json.dumps({"location": str(tmpdir / "test.pcap")})
|
||||
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)
|
||||
|
||||
@@ -443,6 +443,49 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary):
|
||||
assert "-nographic" in cmd
|
||||
|
||||
|
||||
def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager):
|
||||
|
||||
vm.adapters = 2
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
||||
assert cmd == [
|
||||
fake_qemu_binary,
|
||||
"-name",
|
||||
"test",
|
||||
"-m",
|
||||
"256M",
|
||||
"-smp",
|
||||
"cpus=1",
|
||||
"-boot",
|
||||
"order=c",
|
||||
"-serial",
|
||||
"telnet:127.0.0.1:{},server,nowait".format(vm.console),
|
||||
"-net",
|
||||
"none",
|
||||
"-device",
|
||||
"e1000,mac=00:00:ab:0e:0f:00",
|
||||
"-device",
|
||||
"e1000,mac=00:00:ab:0e:0f:01",
|
||||
"-nographic"
|
||||
]
|
||||
|
||||
|
||||
def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port_manager):
|
||||
|
||||
vm.adapters = 2
|
||||
vm.mac_address = "00:00:ab:0e:0f:09"
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
||||
assert "e1000,mac=00:00:ab:0e:0f:09" in cmd
|
||||
assert "e1000,mac=00:00:ab:0e:0f:0a" in cmd
|
||||
|
||||
vm.mac_address = "00:00:ab:0e:0f:0a"
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
||||
assert "e1000,mac=00:00:ab:0e:0f:0a" in cmd
|
||||
assert "e1000,mac=00:00:ab:0e:0f:0b" in cmd
|
||||
|
||||
|
||||
# Windows accept this kind of mistake
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
|
||||
|
||||
+9
-1
@@ -16,10 +16,18 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from gns3server.utils import force_unix_path
|
||||
from gns3server.utils import force_unix_path, macaddress_to_int, int_to_macaddress
|
||||
|
||||
|
||||
def test_force_unix_path():
|
||||
assert force_unix_path("a/b") == "a/b"
|
||||
assert force_unix_path("a\\b") == "a/b"
|
||||
assert force_unix_path("a\\b\\..\\c") == "a/c"
|
||||
|
||||
|
||||
def test_macaddress_to_int():
|
||||
assert macaddress_to_int("00:0c:29:11:b0:0a") == 52228632586
|
||||
|
||||
|
||||
def test_int_to_macaddress():
|
||||
assert int_to_macaddress(52228632586) == "00:0c:29:11:b0:0a"
|
||||
Reference in new issue
Block a user