From 026fe3df9b627b68407c9cb5fdf94f49866f75cd Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 31 Mar 2015 22:14:08 +0200 Subject: [PATCH] Catch error when qemu additional options are invalid Fix #119 --- gns3server/modules/qemu/qemu_vm.py | 5 ++++- tests/modules/qemu/test_qemu_vm.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index 0949e04c..46727cad 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -1068,7 +1068,10 @@ class QemuVM(BaseVM): command.extend(self._monitor_options()) additional_options = self._options.strip() if additional_options: - command.extend(shlex.split(additional_options)) + try: + command.extend(shlex.split(additional_options)) + except ValueError as e: + QemuError("Invalid additional options: {} error {}".format(additional_options, e)) command.extend(self._network_options()) command.extend(self._graphic()) return command diff --git a/tests/modules/qemu/test_qemu_vm.py b/tests/modules/qemu/test_qemu_vm.py index f05e78c4..52ddd17a 100644 --- a/tests/modules/qemu/test_qemu_vm.py +++ b/tests/modules/qemu/test_qemu_vm.py @@ -280,6 +280,13 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary): assert "-nographic" in cmd +def test_build_command_witht_invalid_options(vm, loop, fake_qemu_binary): + + vm.options = "'test" + with pytest.raises(QemuError): + cmd = loop.run_until_complete(asyncio.async(vm._build_command())) + + def test_hda_disk_image(vm, tmpdir): with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):