Raise a VirtualBox error if adapter doesn't exists

Fix #195
This commit is contained in:
Julien Duponchelle 2015-05-27 16:38:57 +02:00
parent ecf4e91e55
commit 7cad25eb1a
2 changed files with 10 additions and 4 deletions

View File

@ -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))

View File

@ -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)))