Support for sendings settings for the GNS3VM from the GUI

Ref https://github.com/GNS3/gns3-gui/issues/1441
This commit is contained in:
Julien Duponchelle committed 2016-08-25 09:32:06 +02:00
1 parent 6cad685a08
commit 21b99ad9f9
14 files changed
+301 -173

No files matched your search

+12 -9
View File
@@ -38,6 +38,7 @@ def test_save(controller, controller_config_path):
assert data["computes"] == []
assert data["version"] == __version__
assert data["settings"] == {}
assert data["gns3vm"] == controller.gns3vm.__json__()
def test_load(controller, controller_config_path, async_run):
@@ -55,6 +56,7 @@ def test_load(controller, controller_config_path, async_run):
}
]
data["settings"] = {"IOU": True}
data["gns3vm"] = {"vmname": "Test VM"}
with open(controller_config_path, "w+") as f:
json.dump(data, f)
async_run(controller.load())
@@ -70,6 +72,7 @@ def test_load(controller, controller_config_path, async_run):
"cpu_usage_percent": None,
"memory_usage_percent": None
}
assert controller.gns3vm.settings["vmname"] == "Test VM"
def test_import_computes(controller, controller_config_path, async_run):
@@ -135,29 +138,29 @@ def test_addCompute(controller, controller_config_path, async_run):
controller._notification = MagicMock()
c = async_run(controller.add_compute(compute_id="test1"))
controller._notification.emit.assert_called_with("compute.created", c.__json__())
assert len(controller.computes) == 2
assert len(controller.computes) == 1
async_run(controller.add_compute(compute_id="test1"))
controller._notification.emit.assert_called_with("compute.updated", c.__json__())
assert len(controller.computes) == 2
assert len(controller.computes) == 1
async_run(controller.add_compute(compute_id="test2"))
assert len(controller.computes) == 3
assert len(controller.computes) == 2
def test_addDuplicateCompute(controller, controller_config_path, async_run):
controller._notification = MagicMock()
c = async_run(controller.add_compute(compute_id="test1", name="Test"))
assert len(controller.computes) == 2
assert len(controller.computes) == 1
with pytest.raises(aiohttp.web.HTTPConflict):
async_run(controller.add_compute(compute_id="test2", name="Test"))
def test_deleteCompute(controller, controller_config_path, async_run):
c = async_run(controller.add_compute(compute_id="test1"))
assert len(controller.computes) == 2
assert len(controller.computes) == 1
controller._notification = MagicMock()
c._connected = True
async_run(controller.delete_compute("test1"))
assert len(controller.computes) == 1
assert len(controller.computes) == 0
controller._notification.emit.assert_called_with("compute.deleted", c.__json__())
with open(controller_config_path) as f:
data = json.load(f)
@@ -167,7 +170,7 @@ def test_deleteCompute(controller, controller_config_path, async_run):
def test_addComputeConfigFile(controller, controller_config_path, async_run):
async_run(controller.add_compute(compute_id="test1", name="Test"))
assert len(controller.computes) == 2
assert len(controller.computes) == 1
with open(controller_config_path) as f:
data = json.load(f)
assert data["computes"] == [
@@ -249,10 +252,10 @@ def test_getProject(controller, async_run):
assert controller.get_project("dsdssd")
def test_close(controller, async_run):
def test_stop(controller, async_run):
c = async_run(controller.add_compute(compute_id="test1"))
c._connected = True
async_run(controller.close())
async_run(controller.stop())
assert c.connected is False
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python
#
# Copyright (C) 2016 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,
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from tests.utils import asyncio_patch
from gns3server.controller.gns3vm import GNS3VM
def test_list(async_run, controller):
vm = GNS3VM(controller)
with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.list", return_value=[{"vmname": "test", "vmx_path": "test"}]):
res = async_run(vm.list("vmware"))
assert res == [{"vmname": "test"}] # Informations specific to vmware are stripped
with asyncio_patch("gns3server.controller.gns3vm.virtualbox_gns3_vm.VirtualBoxGNS3VM.list", return_value=[{"vmname": "test"}]):
res = async_run(vm.list("virtualbox"))
assert res == [{"vmname": "test"}]
with pytest.raises(NotImplementedError):
async_run(vm.list("hyperv"))
def test_json(controller):
vm = GNS3VM(controller)
assert vm.__json__() == vm._settings
@@ -35,7 +35,7 @@ def test_compute_create_without_id(http_controller, controller):
assert response.json["compute_id"] is not None
assert "password" not in response.json
assert len(controller.computes) == 2
assert len(controller.computes) == 1
assert controller.computes[response.json["compute_id"]].host == "example.com"
@@ -55,7 +55,7 @@ def test_compute_create_with_id(http_controller, controller):
assert response.json["user"] == "julien"
assert "password" not in response.json
assert len(controller.computes) == 2
assert len(controller.computes) == 1
assert controller.computes["my_compute_id"].host == "example.com"
@@ -148,13 +148,13 @@ def test_compute_delete(http_controller, controller):
assert response.status == 201
response = http_controller.get("/computes")
assert len(response.json) == 2
assert len(response.json) == 1
response = http_controller.delete("/computes/my_compute_id")
assert response.status == 204
response = http_controller.get("/computes")
assert len(response.json) == 1
assert len(response.json) == 0
def test_compute_list_images(http_controller, controller):
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 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,
# 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.
#
# 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.utils import asyncio_patch
def test_list_vms(http_controller):
with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.list", return_value=[{"vmname": "test"}]):
response = http_controller.get('/gns3vm/engines/vmware/vms', example=True)
assert response.status == 200
assert response.json == [
{
"vmname": "test"
}
]
def test_engines(http_controller):
response = http_controller.get('/gns3vm/engines', example=True)
assert response.status == 200
assert len(response.json) > 0
def test_put_gns3vm(http_controller):
response = http_controller.put('/gns3vm', {
"vmname": "TEST VM"
}, example=True)
assert response.status == 201
assert response.json["vmname"] == "TEST VM"
def test_get_gns3vm(http_controller):
response = http_controller.get('/gns3vm', example=True)
assert response.status == 200
print(response.json)