mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Create VPCS VM on controller
This commit is contained in:
13 files changed
+76
-34
No files matched your search
@@ -79,7 +79,7 @@ def test_addProject_with_hypervisor(controller, async_run):
|
||||
|
||||
hypervisor = Hypervisor("test1")
|
||||
hypervisor.post = MagicMock()
|
||||
controller._hypervisors = {"test1": hypervisor }
|
||||
controller._hypervisors = {"test1": hypervisor}
|
||||
|
||||
project1 = async_run(controller.addProject(project_id=uuid1))
|
||||
hypervisor.post.assert_called_with("/projects", project1)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import pytest
|
||||
import json
|
||||
import aiohttp
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
@@ -58,6 +59,15 @@ def test_hypervisor_httpQuery(hypervisor, async_run):
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/hypervisor/projects", data='{"a": "b"}', headers={'content-type': 'application/json'})
|
||||
|
||||
|
||||
def test_hypervisor_httpQueryError(hypervisor, async_run):
|
||||
response = MagicMock()
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
response.status = 409
|
||||
|
||||
with pytest.raises(aiohttp.errors.HttpProcessingError):
|
||||
async_run(hypervisor.post("/projects", {"a": "b"}))
|
||||
|
||||
|
||||
def test_hypervisor_httpQuery_project(hypervisor, async_run):
|
||||
response = MagicMock()
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
|
||||
@@ -38,5 +38,10 @@ def test_json(tmpdir):
|
||||
def test_addVM(async_run):
|
||||
hypervisor = MagicMock()
|
||||
project = Project()
|
||||
vm = async_run(project.addVM(hypervisor, None, name="test", vm_type="vpcs", startup_config="test.cfg"))
|
||||
hypervisor.post.assert_called_with('/projects/{}/vpcs/vms'.format(project.id), data={'console': None, 'vm_id': vm.id, 'console_type': 'telnet', 'startup_config': 'test.cfg'})
|
||||
vm = async_run(project.addVM(hypervisor, None, name="test", vm_type="vpcs", properties= {"startup_config": "test.cfg"}))
|
||||
hypervisor.post.assert_called_with('/projects/{}/vpcs/vms'.format(project.id),
|
||||
data={'console': None,
|
||||
'vm_id': vm.id,
|
||||
'console_type': 'telnet',
|
||||
'startup_config': 'test.cfg',
|
||||
'name': 'test'})
|
||||
@@ -38,13 +38,15 @@ def vm(hypervisor):
|
||||
name="demo",
|
||||
vm_id=str(uuid.uuid4()),
|
||||
vm_type="vpcs",
|
||||
console_type="vnc")
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"})
|
||||
return vm
|
||||
|
||||
|
||||
def test_json(vm, hypervisor):
|
||||
assert vm.__json__() == {
|
||||
"hypervisor_id": hypervisor.id,
|
||||
"project_id": vm.project.id,
|
||||
"vm_id": vm.id,
|
||||
"vm_type": vm.vm_type,
|
||||
"name": "demo",
|
||||
@@ -66,6 +68,8 @@ def test_create(vm, hypervisor, project, async_run):
|
||||
data = {
|
||||
"console": None,
|
||||
"console_type": "vnc",
|
||||
"vm_id": vm.id
|
||||
"vm_id": vm.id,
|
||||
"startup_script": "echo test",
|
||||
"name": "demo"
|
||||
}
|
||||
hypervisor.post.assert_called_with("/projects/{}/vpcs/vms".format(vm.project.id), data=data)
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
@@ -47,7 +47,13 @@ def project(http_controller, async_run):
|
||||
|
||||
|
||||
def test_create_vm(http_controller, tmpdir, project, hypervisor):
|
||||
response = http_controller.post("/projects/{}/vms".format(project.id), {"name": "test", "vm_type": "vpcs", "hypervisor_id": "example.com"}, example=True)
|
||||
response = http_controller.post("/projects/{}/vms".format(project.id), {
|
||||
"name": "test",
|
||||
"vm_type": "vpcs",
|
||||
"hypervisor_id": "example.com",
|
||||
"properties": {
|
||||
"startup_script": "echo test"
|
||||
}
|
||||
}, example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == "test"
|
||||
|
||||
Reference in new issue
Block a user