mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Reorganize how appliance creation is validated against JSON schemas.
This allows for clearer error messages when validation fails.
This commit is contained in:
1 parent
71fcf855b4
commit
499ab9844a
19 files changed
+1524
-1325
No files matched your search
@@ -15,6 +15,9 @@
|
||||
# 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
|
||||
import jsonschema
|
||||
|
||||
from gns3server.controller.appliance import Appliance
|
||||
|
||||
|
||||
@@ -26,42 +29,25 @@ def test_appliance_json():
|
||||
"category": 0,
|
||||
"symbol": "qemu.svg",
|
||||
"server": "local",
|
||||
"platform": None
|
||||
"platform": "i386"
|
||||
})
|
||||
assert a.__json__() == {
|
||||
"appliance_id": a.id,
|
||||
"appliance_type": "qemu",
|
||||
"builtin": False,
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": "router",
|
||||
"symbol": "qemu.svg",
|
||||
"compute_id": "local",
|
||||
"platform": None
|
||||
}
|
||||
settings = a.__json__()
|
||||
assert settings["appliance_id"] == a.id
|
||||
assert settings["appliance_type"] == "qemu"
|
||||
assert settings["builtin"] == False
|
||||
|
||||
|
||||
def test_appliance_json_with_not_known_category():
|
||||
a = Appliance(None, {
|
||||
"node_type": "qemu",
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": 'Not known',
|
||||
"symbol": "qemu.svg",
|
||||
"server": "local",
|
||||
"platform": None
|
||||
})
|
||||
assert a.__json__() == {
|
||||
"appliance_id": a.id,
|
||||
"appliance_type": "qemu",
|
||||
"builtin": False,
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": "Not known",
|
||||
"symbol": "qemu.svg",
|
||||
"compute_id": "local",
|
||||
"platform": None
|
||||
}
|
||||
with pytest.raises(jsonschema.ValidationError):
|
||||
a = Appliance(None, {
|
||||
"node_type": "qemu",
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": 'Not known',
|
||||
"symbol": "qemu.svg",
|
||||
"server": "local",
|
||||
"platform": "i386"
|
||||
})
|
||||
|
||||
|
||||
def test_appliance_json_with_platform():
|
||||
@@ -71,20 +57,15 @@ def test_appliance_json_with_platform():
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": 0,
|
||||
"symbol": "dynamips.svg",
|
||||
"image": "IOS_image.bin",
|
||||
"server": "local",
|
||||
"platform": "c3725"
|
||||
})
|
||||
assert a.__json__() == {
|
||||
"appliance_id": a.id,
|
||||
"appliance_type": "dynamips",
|
||||
"builtin": False,
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": "router",
|
||||
"symbol": "dynamips.svg",
|
||||
"compute_id": "local",
|
||||
"platform": "c3725"
|
||||
}
|
||||
settings = a.__json__()
|
||||
assert settings["appliance_id"] == a.id
|
||||
assert settings["appliance_type"] == "dynamips"
|
||||
assert settings["builtin"] == False
|
||||
assert settings["platform"] == "c3725"
|
||||
|
||||
|
||||
def test_appliance_fix_linked_base():
|
||||
|
||||
@@ -213,14 +213,10 @@ def test_add_node_from_appliance(async_run, controller):
|
||||
project = Project(controller=controller, name="Test")
|
||||
controller._notification = MagicMock()
|
||||
appliance = Appliance(str(uuid.uuid4()), {
|
||||
"server": "local",
|
||||
"compute_id": "local",
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"appliance_type": "vpcs",
|
||||
"builtin": False,
|
||||
"properties": {
|
||||
"a": 1
|
||||
}
|
||||
})
|
||||
controller._appliances[appliance.id] = appliance
|
||||
controller._computes["local"] = compute
|
||||
@@ -230,30 +226,15 @@ def test_add_node_from_appliance(async_run, controller):
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
node = async_run(project.add_node_from_appliance(appliance.id, x=23, y=12))
|
||||
|
||||
compute.post.assert_any_call('/projects', data={
|
||||
"name": project._name,
|
||||
"project_id": project._id,
|
||||
"path": project._path
|
||||
})
|
||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
data={'node_id': node.id,
|
||||
'name': 'Test-1',
|
||||
'a': 1,
|
||||
},
|
||||
timeout=1200)
|
||||
|
||||
assert compute in project._project_created_on_compute
|
||||
controller.notification.project_emit.assert_any_call("node.created", node.__json__())
|
||||
|
||||
# Make sure we can call twice the node creation
|
||||
node = async_run(project.add_node_from_appliance(appliance.id, x=13, y=12))
|
||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
data={'node_id': node.id,
|
||||
'name': 'Test-2',
|
||||
'a': 1
|
||||
},
|
||||
timeout=1200)
|
||||
|
||||
|
||||
def test_delete_node(async_run, controller):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user