mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-03 20:01:20 +00:00
Ignore VirtualBox VM Name with a carriage return in name
Add tests for get_list of VirtualBox Fix #200
This commit is contained in:
parent
ea67f4aeb9
commit
ecf4e91e55
@ -168,6 +168,8 @@ class VirtualBox(BaseManager):
|
|||||||
vms = []
|
vms = []
|
||||||
result = yield from self.execute("list", ["vms"])
|
result = yield from self.execute("list", ["vms"])
|
||||||
for line in result:
|
for line in result:
|
||||||
|
if line[0] != '"' or line[-1:] != "}":
|
||||||
|
continue # Broken output (perhaps a carriage return in VM name
|
||||||
vmname, _ = line.rsplit(' ', 1)
|
vmname, _ = line.rsplit(' ', 1)
|
||||||
vmname = vmname.strip('"')
|
vmname = vmname.strip('"')
|
||||||
if vmname == "<inaccessible>":
|
if vmname == "<inaccessible>":
|
||||||
|
@ -20,10 +20,14 @@ import pytest
|
|||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from gns3server.modules.virtualbox import VirtualBox
|
from gns3server.modules.virtualbox import VirtualBox
|
||||||
from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError
|
from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError
|
||||||
from unittest.mock import patch
|
from tests.utils import asyncio_patch
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
@ -65,3 +69,31 @@ def test_vboxmanage_path(manager, tmpdir):
|
|||||||
tmpfile = tempfile.NamedTemporaryFile()
|
tmpfile = tempfile.NamedTemporaryFile()
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": path}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": path}):
|
||||||
assert manager.find_vboxmanage() == path
|
assert manager.find_vboxmanage() == path
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_list(manager, loop):
|
||||||
|
vm_list = ['"Windows 8.1" {27b4d095-ff5f-4ac4-bb9d-5f2c7861c1f1}',
|
||||||
|
'"Carriage',
|
||||||
|
'Return" {27b4d095-ff5f-4ac4-bb9d-5f2c7861c1f1}',
|
||||||
|
'"<inaccessible>" {42b4d095-ff5f-4ac4-bb9d-5f2c7861c1f1}',
|
||||||
|
'"Linux Microcore 4.7.1" {ccd8c50b-c172-457d-99fa-dd69371ede0e}'
|
||||||
|
]
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def execute_mock(cmd, args):
|
||||||
|
if cmd == "list":
|
||||||
|
return vm_list
|
||||||
|
else:
|
||||||
|
if args[0] == "Windows 8.1":
|
||||||
|
return ["memory=512"]
|
||||||
|
elif args[0] == "Linux Microcore 4.7.1":
|
||||||
|
return ["memory=256"]
|
||||||
|
assert False, "Unknow {} {}".format(cmd, args)
|
||||||
|
|
||||||
|
with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute") as mock:
|
||||||
|
mock.side_effect = execute_mock
|
||||||
|
vms = loop.run_until_complete(asyncio.async(manager.get_list()))
|
||||||
|
assert vms == [
|
||||||
|
{"vmname": "Windows 8.1", "ram": 512},
|
||||||
|
{"vmname": "Linux Microcore 4.7.1", "ram": 256}
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user