From 18835974fb5691e1c51bad32b7f46c96da5965fa Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 11 Apr 2017 10:57:01 +0200 Subject: [PATCH] Fix required field in schema not use Fix #972 --- gns3server/schemas/atm_switch.py | 3 ++- gns3server/schemas/cloud.py | 3 ++- gns3server/schemas/compute.py | 5 +++-- gns3server/schemas/ethernet_hub.py | 3 ++- gns3server/schemas/ethernet_switch.py | 3 ++- gns3server/schemas/frame_relay_switch.py | 3 ++- gns3server/schemas/node.py | 3 ++- tests/controller/test_import_project.py | 7 +++++++ 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/gns3server/schemas/atm_switch.py b/gns3server/schemas/atm_switch.py index e6a12f97..17cb109b 100644 --- a/gns3server/schemas/atm_switch.py +++ b/gns3server/schemas/atm_switch.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy ATM_SWITCH_CREATE_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -81,5 +82,5 @@ ATM_SWITCH_OBJECT_SCHEMA = { "required": ["name", "node_id", "project_id"] } -ATM_SWITCH_UPDATE_SCHEMA = ATM_SWITCH_OBJECT_SCHEMA +ATM_SWITCH_UPDATE_SCHEMA = copy.deepcopy(ATM_SWITCH_OBJECT_SCHEMA) del ATM_SWITCH_UPDATE_SCHEMA["required"] diff --git a/gns3server/schemas/cloud.py b/gns3server/schemas/cloud.py index a67d8d35..aaf58467 100644 --- a/gns3server/schemas/cloud.py +++ b/gns3server/schemas/cloud.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy from .port import PORT_OBJECT_SCHEMA HOST_INTERFACE_SCHEMA = { @@ -136,5 +137,5 @@ CLOUD_OBJECT_SCHEMA = { "required": ["name", "node_id", "project_id", "ports_mapping"] } -CLOUD_UPDATE_SCHEMA = CLOUD_OBJECT_SCHEMA +CLOUD_UPDATE_SCHEMA = copy.deepcopy(CLOUD_OBJECT_SCHEMA) del CLOUD_UPDATE_SCHEMA["required"] diff --git a/gns3server/schemas/compute.py b/gns3server/schemas/compute.py index 7d0d65ab..8e44de50 100644 --- a/gns3server/schemas/compute.py +++ b/gns3server/schemas/compute.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy from .capabilities import CAPABILITIES_SCHEMA COMPUTE_CREATE_SCHEMA = { @@ -52,10 +53,10 @@ COMPUTE_CREATE_SCHEMA = { } }, "additionalProperties": False, - "required": ["compute_id", "protocol", "host", "port"] + "required": ["protocol", "host", "port"] } -COMPUTE_UPDATE_SCHEMA = COMPUTE_CREATE_SCHEMA +COMPUTE_UPDATE_SCHEMA = copy.deepcopy(COMPUTE_CREATE_SCHEMA) del COMPUTE_UPDATE_SCHEMA["required"] COMPUTE_OBJECT_SCHEMA = { diff --git a/gns3server/schemas/ethernet_hub.py b/gns3server/schemas/ethernet_hub.py index e24b33e0..363ad470 100644 --- a/gns3server/schemas/ethernet_hub.py +++ b/gns3server/schemas/ethernet_hub.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy ETHERNET_HUB_CREATE_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -129,5 +130,5 @@ ETHERNET_HUB_OBJECT_SCHEMA = { "required": ["name", "node_id", "project_id", "ports_mapping"] } -ETHERNET_HUB_UPDATE_SCHEMA = ETHERNET_HUB_OBJECT_SCHEMA +ETHERNET_HUB_UPDATE_SCHEMA = copy.deepcopy(ETHERNET_HUB_OBJECT_SCHEMA) del ETHERNET_HUB_UPDATE_SCHEMA["required"] diff --git a/gns3server/schemas/ethernet_switch.py b/gns3server/schemas/ethernet_switch.py index 1a92a111..40dd2baa 100644 --- a/gns3server/schemas/ethernet_switch.py +++ b/gns3server/schemas/ethernet_switch.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy ETHERNET_SWITCH_CREATE_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -153,5 +154,5 @@ ETHERNET_SWITCH_OBJECT_SCHEMA = { "required": ["name", "node_id", "project_id"] } -ETHERNET_SWITCH_UPDATE_SCHEMA = ETHERNET_SWITCH_OBJECT_SCHEMA +ETHERNET_SWITCH_UPDATE_SCHEMA = copy.deepcopy(ETHERNET_SWITCH_OBJECT_SCHEMA) del ETHERNET_SWITCH_UPDATE_SCHEMA["required"] diff --git a/gns3server/schemas/frame_relay_switch.py b/gns3server/schemas/frame_relay_switch.py index 5d4967af..0f99508c 100644 --- a/gns3server/schemas/frame_relay_switch.py +++ b/gns3server/schemas/frame_relay_switch.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy FRAME_RELAY_SWITCH_CREATE_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -81,5 +82,5 @@ FRAME_RELAY_SWITCH_OBJECT_SCHEMA = { "required": ["name", "node_id", "project_id"] } -FRAME_RELAY_SWITCH_UPDATE_SCHEMA = FRAME_RELAY_SWITCH_OBJECT_SCHEMA +FRAME_RELAY_SWITCH_UPDATE_SCHEMA = copy.deepcopy(FRAME_RELAY_SWITCH_OBJECT_SCHEMA) del FRAME_RELAY_SWITCH_UPDATE_SCHEMA["required"] diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index a832c8cf..6e8f4e2a 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy from .label import LABEL_OBJECT_SCHEMA NODE_TYPE_SCHEMA = { @@ -234,5 +235,5 @@ NODE_OBJECT_SCHEMA = { } NODE_CREATE_SCHEMA = NODE_OBJECT_SCHEMA -NODE_UPDATE_SCHEMA = NODE_OBJECT_SCHEMA +NODE_UPDATE_SCHEMA = copy.deepcopy(NODE_OBJECT_SCHEMA) del NODE_UPDATE_SCHEMA["required"] diff --git a/tests/controller/test_import_project.py b/tests/controller/test_import_project.py index 7f8740c3..23d09457 100644 --- a/tests/controller/test_import_project.py +++ b/tests/controller/test_import_project.py @@ -181,6 +181,7 @@ def test_import_iou_linux_no_vm(linux_platform, async_run, tmpdir, controller): { "compute_id": "local", "node_type": "iou", + "name": "test", "properties": {} } ], @@ -224,6 +225,7 @@ def test_import_iou_linux_with_vm(linux_platform, async_run, tmpdir, controller) "compute_id": "local", "node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b", "node_type": "iou", + "name": "test", "properties": {} } ], @@ -267,11 +269,13 @@ def test_import_iou_non_linux(windows_platform, async_run, tmpdir, controller): "compute_id": "local", "node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b", "node_type": "iou", + "name": "test", "properties": {} }, { "compute_id": "local", "node_type": "vpcs", + "name": "test2", "properties": {} } ], @@ -319,12 +323,14 @@ def test_import_node_id(linux_platform, async_run, tmpdir, controller): "compute_id": "local", "node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b", "node_type": "iou", + "name": "test", "properties": {} }, { "compute_id": "local", "node_id": "c3ae286c-c81f-40d9-a2d0-5874b2f2478d", "node_type": "iou", + "name": "test2", "properties": {} } ], @@ -409,6 +415,7 @@ def test_import_keep_compute_id(windows_platform, async_run, tmpdir, controller) "compute_id": "local", "node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b", "node_type": "iou", + "name": "test", "properties": {} } ],