1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

When a qemu VM crash send the log to the client.

Fix #243
This commit is contained in:
Julien Duponchelle 2015-06-26 14:41:58 +02:00
parent ccd3224490
commit e8805d3fdc
3 changed files with 52 additions and 0 deletions

View File

@ -199,3 +199,15 @@ to the nature of the multiple supported VM it's easy for an user to
upload and run code on your machine. upload and run code on your machine.
Notifications
=============
You can receive notification from the server if you listen the HTTP stream /notifications.
The available notification are:
* ping
* vm.created
* vm.started
* vm.stopped
* log.error

View File

@ -704,6 +704,7 @@ class QemuVM(BaseVM):
self._stdout_file = os.path.join(self.working_dir, "qemu.log") self._stdout_file = os.path.join(self.working_dir, "qemu.log")
log.info("logging to {}".format(self._stdout_file)) log.info("logging to {}".format(self._stdout_file))
with open(self._stdout_file, "w", encoding="utf-8") as fd: with open(self._stdout_file, "w", encoding="utf-8") as fd:
fd.write("Start QEMU with {}\n\nExecution log:\n".format(command_string))
self._process = yield from asyncio.create_subprocess_exec(*self._command, self._process = yield from asyncio.create_subprocess_exec(*self._command,
stdout=fd, stdout=fd,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -732,6 +733,8 @@ class QemuVM(BaseVM):
log.info("QEMU process has stopped, return code: %d", returncode) log.info("QEMU process has stopped, return code: %d", returncode)
self.status = "stopped" self.status = "stopped"
self._process = None self._process = None
if returncode != 0:
self.project.emit("log.error", "QEMU process has stopped, return code: {}\n{}".format(returncode, self.read_stdout()))
@asyncio.coroutine @asyncio.coroutine
def stop(self): def stop(self):

View File

@ -114,6 +114,43 @@ def test_stop(loop, vm, running_subprocess_mock):
process.terminate.assert_called_with() process.terminate.assert_called_with()
def test_termination_callback(vm):
vm.status = "started"
queue = vm.project.get_listen_queue()
vm._termination_callback(0)
assert vm.status == "stopped"
(action, event) = queue.get_nowait()
assert action == "vm.stopped"
assert event == vm
with pytest.raises(asyncio.queues.QueueEmpty):
queue.get_nowait()
def test_termination_callback_error(vm, tmpdir):
with open(str(tmpdir / "qemu.log"), "w+") as f:
f.write("BOOMM")
vm.status = "started"
vm._stdout_file = str(tmpdir / "qemu.log")
queue = vm.project.get_listen_queue()
vm._termination_callback(1)
assert vm.status == "stopped"
(action, event) = queue.get_nowait()
assert action == "vm.stopped"
assert event == vm
(action, event) = queue.get_nowait()
assert action == "log.error"
assert event == "QEMU process has stopped, return code: 1\nBOOMM"
def test_reload(loop, vm): def test_reload(loop, vm):
with asyncio_patch("gns3server.modules.qemu.QemuVM._control_vm") as mock: with asyncio_patch("gns3server.modules.qemu.QemuVM._control_vm") as mock: