mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Merge remote-tracking branch 'origin/asyncio' into asyncio
This commit is contained in:
commit
061d3223a7
@ -20,5 +20,5 @@ X-ROUTE: /vpcs
|
|||||||
"name": "PC TEST 1",
|
"name": "PC TEST 1",
|
||||||
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
|
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
|
||||||
"script_file": null,
|
"script_file": null,
|
||||||
"uuid": "12171ed6-4234-4ba7-9ef5-db3631a3a2e4"
|
"uuid": "a4809caf-bfba-4f34-ad78-1d054c8b7e5a"
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ class VPCSVM(BaseVM):
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._kill_process()
|
self._kill_process()
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
def _check_requirements(self):
|
def _check_requirements(self):
|
||||||
"""
|
"""
|
||||||
Check if VPCS is available with the correct version
|
Check if VPCS is available with the correct version
|
||||||
@ -97,7 +98,7 @@ class VPCSVM(BaseVM):
|
|||||||
if not os.access(self._path, os.X_OK):
|
if not os.access(self._path, os.X_OK):
|
||||||
raise VPCSError("VPCS program '{}' is not executable".format(self._path))
|
raise VPCSError("VPCS program '{}' is not executable".format(self._path))
|
||||||
|
|
||||||
self._check_vpcs_version()
|
yield from self._check_vpcs_version()
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
|
|
||||||
@ -144,14 +145,14 @@ class VPCSVM(BaseVM):
|
|||||||
new_name=new_name))
|
new_name=new_name))
|
||||||
BaseVM.name = new_name
|
BaseVM.name = new_name
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
def _check_vpcs_version(self):
|
def _check_vpcs_version(self):
|
||||||
"""
|
"""
|
||||||
Checks if the VPCS executable version is >= 0.5b1.
|
Checks if the VPCS executable version is >= 0.5b1.
|
||||||
"""
|
"""
|
||||||
# TODO: should be async
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output([self._path, "-v"], cwd=self.working_dir)
|
output = yield from self._get_vpcs_welcome()
|
||||||
match = re.search("Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)", output.decode("utf-8"))
|
match = re.search("Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)", output)
|
||||||
if match:
|
if match:
|
||||||
version = match.group(1)
|
version = match.group(1)
|
||||||
if parse_version(version) < parse_version("0.5b1"):
|
if parse_version(version) < parse_version("0.5b1"):
|
||||||
@ -161,13 +162,19 @@ class VPCSVM(BaseVM):
|
|||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise VPCSError("Error while looking for the VPCS version: {}".format(e))
|
raise VPCSError("Error while looking for the VPCS version: {}".format(e))
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def _get_vpcs_welcome(self):
|
||||||
|
proc = yield from asyncio.create_subprocess_exec(' '.join([self._path, "-v"]), stdout=asyncio.subprocess.PIPE, cwd=self.working_dir)
|
||||||
|
out = yield from proc.stdout.readline()
|
||||||
|
return out.decode("utf-8")
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
Starts the VPCS process.
|
Starts the VPCS process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._check_requirements()
|
yield from self._check_requirements()
|
||||||
|
|
||||||
if not self.is_running():
|
if not self.is_running():
|
||||||
if not self._ethernet_adapter.get_nio(0):
|
if not self._ethernet_adapter.get_nio(0):
|
||||||
|
@ -84,3 +84,13 @@ def test_vpcs_delete_nio(server, vm):
|
|||||||
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
|
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
|
||||||
|
|
||||||
|
|
||||||
|
def test_vpcs_start():
|
||||||
|
# assert True == False
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_vpcs_stop():
|
||||||
|
# assert True == False
|
||||||
|
pass
|
||||||
|
@ -36,20 +36,19 @@ def manager():
|
|||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
@patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.6".encode("utf-8"))
|
|
||||||
def test_vm(project, manager):
|
def test_vm(project, manager):
|
||||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||||
assert vm.name == "test"
|
assert vm.name == "test"
|
||||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||||
|
|
||||||
|
|
||||||
@patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.1".encode("utf-8"))
|
|
||||||
def test_vm_invalid_vpcs_version(project, manager, loop):
|
def test_vm_invalid_vpcs_version(project, manager, loop):
|
||||||
with pytest.raises(VPCSError):
|
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._get_vpcs_welcome", return_value="Welcome to Virtual PC Simulator, version 0.1"):
|
||||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
with pytest.raises(VPCSError):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||||
assert vm.name == "test"
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
assert vm.name == "test"
|
||||||
|
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.config.Config.get_section_config", return_value={"path": "/bin/test_fake"})
|
@patch("gns3server.config.Config.get_section_config", return_value={"path": "/bin/test_fake"})
|
||||||
@ -61,28 +60,28 @@ def test_vm_invalid_vpcs_path(project, manager, loop):
|
|||||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True)
|
|
||||||
def test_start(project, loop, manager):
|
def test_start(project, loop, manager):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||||
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||||
|
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True)
|
|
||||||
def test_stop(project, loop, manager):
|
def test_stop(project, loop, manager):
|
||||||
process = MagicMock()
|
process = MagicMock()
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||||
|
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
process.terminate.assert_called_with()
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
def test_add_nio_binding_udp(manager, project):
|
def test_add_nio_binding_udp(manager, project):
|
||||||
|
Loading…
Reference in New Issue
Block a user