1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00

Qemu telnet support multiple client connected

Fix #770
This commit is contained in:
Julien Duponchelle 2016-11-09 09:47:48 +01:00
parent 69f154d9cc
commit bddf9ec2ac
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 30 additions and 26 deletions

View File

@ -65,7 +65,7 @@ class QemuVM(BaseNode):
def __init__(self, name, node_id, project, manager, linked_clone=True, qemu_path=None, console=None, console_type="telnet", platform=None): def __init__(self, name, node_id, project, manager, linked_clone=True, qemu_path=None, console=None, console_type="telnet", platform=None):
super().__init__(name, node_id, project, manager, console=console, console_type=console_type) super().__init__(name, node_id, project, manager, console=console, console_type=console_type, wrap_console=True)
server_config = manager.config.get_section_config("Server") server_config = manager.config.get_section_config("Server")
self._host = server_config.get("host", "127.0.0.1") self._host = server_config.get("host", "127.0.0.1")
self._monitor_host = server_config.get("monitor_host", "127.0.0.1") self._monitor_host = server_config.get("monitor_host", "127.0.0.1")
@ -908,6 +908,7 @@ class QemuVM(BaseNode):
if "-enable-kvm" in command_string: if "-enable-kvm" in command_string:
self._hw_virtualization = True self._hw_virtualization = True
yield from self.start_wrap_console()
def _termination_callback(self, returncode): def _termination_callback(self, returncode):
""" """
@ -936,7 +937,6 @@ class QemuVM(BaseNode):
self._hw_virtualization = False self._hw_virtualization = False
if self.is_running(): if self.is_running():
log.info('Stopping QEMU VM "{}" PID={}'.format(self._name, self._process.pid)) log.info('Stopping QEMU VM "{}" PID={}'.format(self._name, self._process.pid))
self.status = "stopped"
try: try:
if self.acpi_shutdown: if self.acpi_shutdown:
yield from self._control_vm("system_powerdown") yield from self._control_vm("system_powerdown")
@ -955,6 +955,7 @@ class QemuVM(BaseNode):
log.warn('QEMU VM "{}" PID={} is still running'.format(self._name, self._process.pid)) log.warn('QEMU VM "{}" PID={} is still running'.format(self._name, self._process.pid))
self._process = None self._process = None
self._stop_cpulimit() self._stop_cpulimit()
yield from super().stop()
@asyncio.coroutine @asyncio.coroutine
def _control_vm(self, command, expected=None): def _control_vm(self, command, expected=None):
@ -1255,7 +1256,7 @@ class QemuVM(BaseNode):
def _serial_options(self): def _serial_options(self):
if self._console: if self._console:
return ["-serial", "telnet:{}:{},server,nowait".format(self._manager.port_manager.console_host, self._console)] return ["-serial", "telnet:127.0.0.1:{},server,nowait".format(self._internal_console_port)]
else: else:
return [] return []

View File

@ -113,6 +113,7 @@ def test_is_running(vm, running_subprocess_mock):
def test_start(loop, vm, running_subprocess_mock): def test_start(loop, vm, running_subprocess_mock):
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock) as mock: with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock) as mock:
loop.run_until_complete(asyncio.async(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running() assert vm.is_running()
@ -127,6 +128,7 @@ def test_stop(loop, vm, running_subprocess_mock):
future.set_result(True) future.set_result(True)
process.wait.return_value = future process.wait.return_value = future
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.adapter_add_nio_binding(0, nio) vm.adapter_add_nio_binding(0, nio)
@ -213,6 +215,7 @@ def test_port_remove_nio_binding(vm, loop):
def test_close(vm, port_manager, loop): def test_close(vm, port_manager, loop):
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()): with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
loop.run_until_complete(asyncio.async(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
@ -434,7 +437,7 @@ def test_build_command(vm, loop, fake_qemu_binary, port_manager):
"-uuid", "-uuid",
vm.id, vm.id,
"-serial", "-serial",
"telnet:127.0.0.1:{},server,nowait".format(vm.console), "telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
"-net", "-net",
"none", "none",
"-device", "-device",
@ -478,7 +481,7 @@ def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_mana
"-uuid", "-uuid",
vm.id, vm.id,
"-serial", "-serial",
"telnet:127.0.0.1:{},server,nowait".format(vm.console), "telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
"-net", "-net",
"none", "none",
"-device", "-device",
@ -511,7 +514,7 @@ def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_
"-uuid", "-uuid",
vm.id, vm.id,
"-serial", "-serial",
"telnet:127.0.0.1:{},server,nowait".format(vm.console), "telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
"-net", "-net",
"none", "none",
"-device", "-device",
@ -547,7 +550,7 @@ def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager):
"-uuid", "-uuid",
vm.id, vm.id,
"-serial", "-serial",
"telnet:127.0.0.1:{},server,nowait".format(vm.console), "telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
"-net", "-net",
"none", "none",
"-device", "-device",