1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Try to fix VirtualBox create test.

This commit is contained in:
Jeremy 2015-01-20 15:28:40 -07:00
parent 984d47f9c8
commit 17f6223fb1
7 changed files with 29 additions and 10 deletions

View File

@ -40,9 +40,11 @@ class VirtualBoxHandler:
def create(request, response):
vbox_manager = VirtualBox.instance()
vm = yield from vbox_manager.create_vm(request.json["name"], request.json.get("uuid"))
vm = yield from vbox_manager.create_vm(request.json["name"], request.json["project_uuid"], request.json.get("uuid"))
print(vm)
response.json({"name": vm.name,
"uuid": vm.uuid})
"uuid": vm.uuid,
"project_uuid": vm.project.uuid})
@classmethod
@Route.post(

View File

@ -95,6 +95,7 @@ class BaseManager:
:param project_identifier UUID of Project
:param uuid Force UUID force VM
"""
project = ProjectManager.instance().get_project(project_identifier)
# TODO: support for old projects VM with normal IDs.

View File

@ -53,9 +53,9 @@ class VirtualBoxVM(BaseVM):
_instances = []
_allocated_console_ports = []
def __init__(self, name, uuid, manager):
def __init__(self, name, uuid, project, manager):
super().__init__(name, uuid, manager)
super().__init__(name, uuid, project, manager)
self._system_properties = {}

View File

@ -46,6 +46,13 @@ VBOX_CREATE_SCHEMA = {
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"project_uuid": {
"description": "Project UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
},
"additionalProperties": False,
"required": ["name", "vmname"],
@ -68,6 +75,13 @@ VBOX_OBJECT_SCHEMA = {
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"project_uuid": {
"description": "Project UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"console": {
"description": "console TCP port",
"minimum": 1,

View File

@ -35,7 +35,6 @@ from .modules.port_manager import PortManager
# TODO: get rid of * have something generic to automatically import handlers so the routes can be found
from gns3server.handlers import *
from gns3server.handlers.virtualbox_handler import VirtualBoxHandler
import logging
log = logging.getLogger(__name__)
@ -133,6 +132,9 @@ class Server:
Starts the server.
"""
logger = logging.getLogger("asyncio")
logger.setLevel(logging.WARNING)
# TODO: SSL support for Rackspace cloud integration (here or with nginx for instance).
self._loop = asyncio.get_event_loop()
app = aiohttp.web.Application()

View File

@ -120,7 +120,7 @@ class Query:
def _example_file_path(self, method, path):
path = re.sub('[^a-z0-9]', '', path)
return "docs/api/examples/{}_{}.txt".format(method.lower(), path) # FIXME: cannot find path when running tests
return "docs/api/examples/{}_{}.txt".format(method.lower(), path)
def _get_unused_port():

View File

@ -15,13 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from tests.api.base import server, loop
from tests.api.base import server, loop, project
from tests.utils import asyncio_patch
def test_vbox_create(server):
def test_vbox_create(server, project):
with asyncio_patch("gns3server.modules.VirtualBox.create_vm", return_value="61d61bdd-aa7d-4912-817f-65a9eb54d3ab"):
response = server.post("/virtualbox", {"name": "VM1"}, example=False)
response = server.post("/virtualbox", {"name": "VM1", "vmname": "VM1", "project_uuid": project.uuid}, example=False)
assert response.status == 400
assert response.route == "/virtualbox"
assert response.json["name"] == "VM1"
@ -39,4 +39,4 @@ def test_vbox_stop(server):
with asyncio_patch("gns3server.modules.VirtualBox.stop_vm", return_value=True):
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/stop", {}, example=False)
assert response.status == 200
assert response.route == "/virtualbox/{uuid}/stop"
assert response.route == "/virtualbox/{uuid}/stop"