diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index 320ed9c7..b9b91424 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -799,7 +799,7 @@ class VirtualBoxVM(BaseVM): try: adapter = self._ethernet_adapters[adapter_number] - except IndexError: + except KeyError: raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name, adapter_number=adapter_number)) @@ -830,7 +830,7 @@ class VirtualBoxVM(BaseVM): try: adapter = self._ethernet_adapters[adapter_number] - except IndexError: + except KeyError: raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name, adapter_number=adapter_number)) @@ -861,7 +861,7 @@ class VirtualBoxVM(BaseVM): try: adapter = self._ethernet_adapters[adapter_number] - except IndexError: + except KeyError: raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name, adapter_number=adapter_number)) @@ -883,7 +883,7 @@ class VirtualBoxVM(BaseVM): try: adapter = self._ethernet_adapters[adapter_number] - except IndexError: + except KeyError: raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name, adapter_number=adapter_number)) diff --git a/tests/modules/virtualbox/test_virtualbox_vm.py b/tests/modules/virtualbox/test_virtualbox_vm.py index 8b91431e..58540e49 100644 --- a/tests/modules/virtualbox/test_virtualbox_vm.py +++ b/tests/modules/virtualbox/test_virtualbox_vm.py @@ -54,3 +54,9 @@ def test_vm_invalid_virtualbox_api_version(loop, project, manager): with pytest.raises(VirtualBoxError): vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False) loop.run_until_complete(asyncio.async(vm.create())) + + +def test_vm_adapter_add_nio_binding_adapter_not_exist(loop, vm, manager, free_console_port): + nio = manager.create_nio(manager.vboxmanage_path, {"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "192.168.1.2"}) + with pytest.raises(VirtualBoxError): + loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(15, nio)))