Update VPCS instance

This commit is contained in:
Julien Duponchelle committed 2015-01-21 21:46:16 +01:00
1 parent 7abb426d04
commit 368d1ff70b
13 files changed
+144 -29

No files matched your search

+4 -2
View File
@@ -45,6 +45,9 @@ class Query:
def post(self, path, body={}, **kwargs):
return self._fetch("POST", path, body, **kwargs)
def put(self, path, body={}, **kwargs):
return self._fetch("PUT", path, body, **kwargs)
def get(self, path, **kwargs):
return self._fetch("GET", path, **kwargs)
@@ -147,11 +150,10 @@ def loop(request):
@pytest.fixture(scope="session")
def server(request, loop):
def server(request, loop, port_manager):
port = _get_unused_port()
host = "localhost"
app = web.Application()
port_manager = PortManager("127.0.0.1", False)
for method, route, handler in Route.get_routes():
app.router.add_route(method, route, handler)
for module in MODULES:
+1 -1
View File
@@ -20,7 +20,7 @@ This test suite check /project endpoint
"""
from tests.utils import asyncio_patch
from tests.utils import asyncio_patch, port_manager
from tests.api.base import server, loop
from gns3server.version import __version__
+1 -1
View File
@@ -20,7 +20,7 @@ This test suite check /version endpoint
It's also used for unittest the HTTP implementation.
"""
from tests.utils import asyncio_patch
from tests.utils import asyncio_patch, port_manager
from tests.api.base import server, loop
from gns3server.version import __version__
+1 -1
View File
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from tests.api.base import server, loop, project
from tests.utils import asyncio_patch
from tests.utils import asyncio_patch, port_manager
from gns3server.modules.virtualbox.virtualbox_vm import VirtualBoxVM
+19 -4
View File
@@ -18,7 +18,7 @@
import pytest
import os
from tests.api.base import server, loop, project
from tests.utils import asyncio_patch
from tests.utils import asyncio_patch, free_console_port, port_manager
from unittest.mock import patch, Mock
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
@@ -68,13 +68,13 @@ def test_vpcs_create_startup_script(server, project):
assert response.json["startup_script"] == "ip 192.168.1.2\necho TEST"
def test_vpcs_create_port(server, project):
response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid, "console": 4242})
def test_vpcs_create_port(server, project, free_console_port):
response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid, "console": free_console_port})
assert response.status == 200
assert response.route == "/vpcs"
assert response.json["name"] == "PC TEST 1"
assert response.json["project_uuid"] == project.uuid
assert response.json["console"] == 4242
assert response.json["console"] == free_console_port
def test_vpcs_nio_create_udp(server, vm):
@@ -119,3 +119,18 @@ def test_vpcs_stop(server, vm):
response = server.post("/vpcs/{}/stop".format(vm["uuid"]))
assert mock.called
assert response.status == 200
def test_vpcs_update(server, vm, tmpdir, free_console_port):
path = os.path.join(str(tmpdir), 'startup2.vpcs')
with open(path, 'w+') as f:
f.write(path)
response = server.put("/vpcs/{}".format(vm["uuid"]), {"name": "test",
"console": free_console_port,
"script_file": path,
"startup_script": "ip 192.168.1.1"})
assert response.status == 200
assert response.json["name"] == "test"
assert response.json["console"] == free_console_port
assert response.json["script_file"] == path
assert response.json["startup_script"] == "ip 192.168.1.1"
+26 -1
View File
@@ -18,7 +18,7 @@
import pytest
import asyncio
import os
from tests.utils import asyncio_patch
from tests.utils import asyncio_patch, port_manager, free_console_port
# TODO: Move loop to util
from tests.api.base import loop, project
@@ -136,3 +136,28 @@ def test_get_startup_script(vm):
content = "echo GNS3 VPCS\nip 192.168.1.2\n"
vm.startup_script = content
assert vm.startup_script == content
def test_change_console_port(vm, free_console_port):
vm.console = free_console_port
vm.console = free_console_port + 1
assert vm.console == free_console_port
PortManager.instance().reserve_console_port(free_console_port + 1)
def test_change_name(vm, tmpdir):
path = os.path.join(str(tmpdir), 'startup.vpcs')
vm.name = "world"
with open(path, 'w+') as f:
f.write("name world")
vm.script_file = path
vm.name = "hello"
assert vm.name == "hello"
with open(path) as f:
assert f.read() == "name hello"
def test_change_script_file(vm, tmpdir):
path = os.path.join(str(tmpdir), 'startup2.vpcs')
vm.script_file = path
assert vm.script_file == path
+18
View File
@@ -16,7 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import pytest
from unittest.mock import patch
from gns3server.modules.project_manager import ProjectManager
from gns3server.modules.port_manager import PortManager
class _asyncio_patch:
@@ -54,3 +57,18 @@ class _asyncio_patch:
def asyncio_patch(function, *args, **kwargs):
return _asyncio_patch(function, *args, **kwargs)
@pytest.fixture(scope="session")
def port_manager():
return PortManager("127.0.0.1", False)
@pytest.fixture(scope="function")
def free_console_port(request, port_manager):
# In case of already use ports we will raise an exception
port = port_manager.get_free_console_port()
# We release the port immediately in order to allow
# the test do whatever the test want
port_manager.release_console_port(port)
return port