7d03d906030e35ece1453c34fe68f7ca9436ed0a
[osm/NBI.git] / osm_nbi / validation.py
1 # -*- coding: utf-8 -*-
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from jsonschema import validate as js_v, exceptions as js_e
17 from http import HTTPStatus
18 from copy import deepcopy
19
20 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
21 __version__ = "0.1"
22 version_date = "Mar 2018"
23
24 """
25 Validator of input data using JSON schemas for those items that not contains an OSM yang information model
26 """
27
28 # Basis schemas
29 patern_name = "^[ -~]+$"
30 nameshort_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"}
31 passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
32 name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
33 string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
34 xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
35 description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
36 id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
37 bool_schema = {"type": "boolean"}
38 null_schema = {"type": "null"}
39 # "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}$"
40 id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
41 time_schema = {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
42 pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
43 # allows [] for wildcards. For that reason huge length limit is set
44 pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
45 http_schema = {"type": "string", "pattern": "^https?://[^'\"=]+$"}
46 bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
47 memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
48 integer0_schema = {"type": "integer", "minimum": 0}
49 integer1_schema = {"type": "integer", "minimum": 1}
50 path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
51 vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
52 vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
53 mac_schema = {"type": "string",
54 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
55 dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
56 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
57 ip_schema = {"type": "string",
58 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"}
59 ip_prefix_schema = {"type": "string",
60 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
61 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
62 port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
63 object_schema = {"type": "object"}
64 schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
65 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
66 log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
67 checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
68 size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
69 array_edition_schema = {
70 "type": "object",
71 "patternProperties": {
72 "^\\$": "Any"
73 },
74 "additionalProperties": False,
75 "minProperties": 1,
76 }
77 nameshort_list_schema = {
78 "type": "array",
79 "minItems": 1,
80 "items": nameshort_schema,
81 }
82
83
84 ns_instantiate_vdu = {
85 "title": "ns action instantiate input schema for vdu",
86 "$schema": "http://json-schema.org/draft-04/schema#",
87 "type": "object",
88 "properties": {
89 "id": name_schema,
90 "volume": {
91 "type": "array",
92 "minItems": 1,
93 "items": {
94 "type": "object",
95 "properties": {
96 "name": name_schema,
97 "vim-volume-id": name_schema,
98 },
99 "required": ["name", "vim-volume-id"],
100 "additionalProperties": False
101 }
102 },
103 "interface": {
104 "type": "array",
105 "minItems": 1,
106 "items": {
107 "type": "object",
108 "properties": {
109 "name": name_schema,
110 "ip-address": ip_schema,
111 "mac-address": mac_schema,
112 "floating-ip-required": bool_schema,
113 },
114 "required": ["name"],
115 "additionalProperties": False
116 }
117 }
118 },
119 "required": ["id"],
120 "additionalProperties": False
121 }
122
123 ip_profile_dns_schema = {
124 "type": "array",
125 "minItems": 1,
126 "items": {
127 "type": "object",
128 "properties": {
129 "address": ip_schema,
130 },
131 "required": ["address"],
132 "additionalProperties": False
133 }
134 }
135
136 ip_profile_dhcp_schema = {
137 "type": "object",
138 "properties": {
139 "enabled": {"type": "boolean"},
140 "count": integer1_schema,
141 "start-address": ip_schema
142 },
143 "additionalProperties": False,
144 }
145
146 ip_profile_schema = {
147 "title": "ip profile validation schame",
148 "$schema": "http://json-schema.org/draft-04/schema#",
149 "type": "object",
150 "properties": {
151 "ip-version": {"enum": ["ipv4", "ipv6"]},
152 "subnet-address": ip_prefix_schema,
153 "gateway-address": ip_schema,
154 "dns-server": ip_profile_dns_schema,
155 "dhcp-params": ip_profile_dhcp_schema,
156 }
157 }
158
159 ip_profile_update_schema = {
160 "title": "ip profile validation schame",
161 "$schema": "http://json-schema.org/draft-04/schema#",
162 "type": "object",
163 "properties": {
164 "ip-version": {"enum": ["ipv4", "ipv6"]},
165 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
166 "gateway-address": {"oneOf": [null_schema, ip_schema]},
167 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
168
169 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
170 },
171 "additionalProperties": False
172 }
173
174 ns_instantiate_internal_vld = {
175 "title": "ns action instantiate input schema for vdu",
176 "$schema": "http://json-schema.org/draft-04/schema#",
177 "type": "object",
178 "properties": {
179 "name": name_schema,
180 "vim-network-name": name_schema,
181 "vim-network-id": name_schema,
182 "ip-profile": ip_profile_update_schema,
183 "internal-connection-point": {
184 "type": "array",
185 "minItems": 1,
186 "items": {
187 "type": "object",
188 "properties": {
189 "id-ref": name_schema,
190 "ip-address": ip_schema,
191 # "mac-address": mac_schema,
192 },
193 "required": ["id-ref"],
194 "minProperties": 2,
195 "additionalProperties": False
196 },
197 }
198 },
199 "required": ["name"],
200 "minProperties": 2,
201 "additionalProperties": False
202 }
203
204 ns_instantiate = {
205 "title": "ns action instantiate input schema",
206 "$schema": "http://json-schema.org/draft-04/schema#",
207 "type": "object",
208 "properties": {
209 "lcmOperationType": string_schema,
210 "nsInstanceId": id_schema,
211 "netsliceInstanceId": id_schema,
212 "nsName": name_schema,
213 "nsDescription": {"oneOf": [description_schema, {"type": "null"}]},
214 "nsdId": id_schema,
215 "vimAccountId": id_schema,
216 "additionalParamsForNs": object_schema,
217 "additionalParamsForVnf": {
218 "type": "array",
219 "items": {
220 "type": "object",
221 "properties": {
222 "member-vnf-index": name_schema,
223 "additionalParams": object_schema,
224 },
225 "required": ["member-vnf-index", "additionalParams"]
226 }
227 },
228 "ssh_keys": {"type": "array", "items": {"type": "string"}},
229 "nsr_id": id_schema,
230 "vduImage": name_schema,
231 "vnf": {
232 "type": "array",
233 "minItems": 1,
234 "items": {
235 "type": "object",
236 "properties": {
237 "member-vnf-index": name_schema,
238 "vimAccountId": id_schema,
239 "vdu": {
240 "type": "array",
241 "minItems": 1,
242 "items": ns_instantiate_vdu,
243 },
244 "internal-vld": {
245 "type": "array",
246 "minItems": 1,
247 "items": ns_instantiate_internal_vld
248 }
249 },
250 "required": ["member-vnf-index"],
251 "minProperties": 2,
252 "additionalProperties": False
253 }
254 },
255 "vld": {
256 "type": "array",
257 "minItems": 1,
258 "items": {
259 "type": "object",
260 "properties": {
261 "name": string_schema,
262 "vim-network-name": {"OneOf": [string_schema, object_schema]},
263 "vim-network-id": {"OneOf": [string_schema, object_schema]},
264 "ip-profile": object_schema,
265 "vnfd-connection-point-ref": {
266 "type": "array",
267 "minItems": 1,
268 "items": {
269 "type": "object",
270 "properties": {
271 "member-vnf-index-ref": name_schema,
272 "vnfd-connection-point-ref": name_schema,
273 "ip-address": ip_schema,
274 # "mac-address": mac_schema,
275 },
276 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
277 "minProperties": 3,
278 "additionalProperties": False
279 },
280 }
281 },
282 "required": ["name"],
283 "additionalProperties": False
284 }
285 },
286 },
287 "required": ["nsName", "nsdId", "vimAccountId"],
288 "additionalProperties": False
289 }
290
291 ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
292 "title": "ns action input schema",
293 "$schema": "http://json-schema.org/draft-04/schema#",
294 "type": "object",
295 "properties": {
296 "lcmOperationType": string_schema,
297 "nsInstanceId": id_schema,
298 "member_vnf_index": name_schema,
299 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
300 "vdu_id": name_schema,
301 "primitive": name_schema,
302 "primitive_params": {"type": "object"},
303 },
304 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
305 "additionalProperties": False
306 }
307 ns_scale = { # TODO for the moment it is only VDU-scaling
308 "title": "ns scale input schema",
309 "$schema": "http://json-schema.org/draft-04/schema#",
310 "type": "object",
311 "properties": {
312 "lcmOperationType": string_schema,
313 "nsInstanceId": id_schema,
314 "scaleType": {"enum": ["SCALE_VNF"]},
315 "scaleVnfData": {
316 "type": "object",
317 "properties": {
318 "vnfInstanceId": name_schema,
319 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
320 "scaleByStepData": {
321 "type": "object",
322 "properties": {
323 "scaling-group-descriptor": name_schema,
324 "member-vnf-index": name_schema,
325 "scaling-policy": name_schema,
326 },
327 "required": ["scaling-group-descriptor", "member-vnf-index"],
328 "additionalProperties": False
329 },
330 },
331 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
332 "additionalProperties": False
333 },
334 "scaleTime": time_schema,
335 },
336 "required": ["scaleType", "scaleVnfData"],
337 "additionalProperties": False
338 }
339
340
341 schema_version = {"type": "string", "enum": ["1.0"]}
342 schema_type = {"type": "string"}
343 vim_account_edit_schema = {
344 "title": "vim_account edit input schema",
345 "$schema": "http://json-schema.org/draft-04/schema#",
346 "type": "object",
347 "properties": {
348 "name": name_schema,
349 "description": description_schema,
350 "type": nameshort_schema,
351 "vim": name_schema,
352 "datacenter": name_schema,
353 "vim_url": description_schema,
354 "vim_url_admin": description_schema,
355 "vim_tenant": name_schema,
356 "vim_tenant_name": name_schema,
357 "vim_username": nameshort_schema,
358 "vim_password": passwd_schema,
359 "config": {"type": "object"}
360 },
361 "additionalProperties": False
362 }
363
364 vim_account_new_schema = {
365 "title": "vim_account creation input schema",
366 "$schema": "http://json-schema.org/draft-04/schema#",
367 "type": "object",
368 "properties": {
369 "schema_version": schema_version,
370 "schema_type": schema_type,
371 "name": name_schema,
372 "description": description_schema,
373 "vim": name_schema,
374 "datacenter": name_schema,
375 "vim_type": {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws"]},
376 "vim_url": description_schema,
377 # "vim_url_admin": description_schema,
378 # "vim_tenant": name_schema,
379 "vim_tenant_name": name_schema,
380 "vim_user": nameshort_schema,
381 "vim_password": passwd_schema,
382 "config": {"type": "object"}
383 },
384 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
385 "additionalProperties": False
386 }
387
388 wim_account_edit_schema = {
389 "title": "wim_account edit input schema",
390 "$schema": "http://json-schema.org/draft-04/schema#",
391 "type": "object",
392 "properties": {
393 "name": name_schema,
394 "description": description_schema,
395 "type": nameshort_schema,
396 "wim": name_schema,
397 "wim_url": description_schema,
398 "user": nameshort_schema,
399 "password": passwd_schema,
400 "config": {"type": "object"}
401 },
402 "additionalProperties": False
403 }
404
405 wim_account_new_schema = {
406 "title": "wim_account creation input schema",
407 "$schema": "http://json-schema.org/draft-04/schema#",
408 "type": "object",
409 "properties": {
410 "schema_version": schema_version,
411 "schema_type": schema_type,
412 "name": name_schema,
413 "description": description_schema,
414 "wim": name_schema,
415 "wim_type": {"enum": ["tapi", "onos", "odl", "dynpac"]},
416 "wim_url": description_schema,
417 "user": nameshort_schema,
418 "password": passwd_schema,
419 "config": {"type": "object"}
420 },
421 "required": ["name", "wim_url", "wim_type"],
422 "additionalProperties": False
423 }
424
425 sdn_properties = {
426 "name": name_schema,
427 "description": description_schema,
428 "dpid": dpid_Schema,
429 "ip": ip_schema,
430 "port": port_schema,
431 "type": {"type": "string", "enum": ["opendaylight", "floodlight", "onos"]},
432 "version": {"type": "string", "minLength": 1, "maxLength": 12},
433 "user": nameshort_schema,
434 "password": passwd_schema
435 }
436 sdn_new_schema = {
437 "title": "sdn controller information schema",
438 "$schema": "http://json-schema.org/draft-04/schema#",
439 "type": "object",
440 "properties": sdn_properties,
441 "required": ["name", "port", 'ip', 'dpid', 'type'],
442 "additionalProperties": False
443 }
444 sdn_edit_schema = {
445 "title": "sdn controller update information schema",
446 "$schema": "http://json-schema.org/draft-04/schema#",
447 "type": "object",
448 "properties": sdn_properties,
449 # "required": ["name", "port", 'ip', 'dpid', 'type'],
450 "additionalProperties": False
451 }
452 sdn_port_mapping_schema = {
453 "$schema": "http://json-schema.org/draft-04/schema#",
454 "title": "sdn port mapping information schema",
455 "type": "array",
456 "items": {
457 "type": "object",
458 "properties": {
459 "compute_node": nameshort_schema,
460 "ports": {
461 "type": "array",
462 "items": {
463 "type": "object",
464 "properties": {
465 "pci": pci_extended_schema,
466 "switch_port": nameshort_schema,
467 "switch_mac": mac_schema
468 },
469 "required": ["pci"]
470 }
471 }
472 },
473 "required": ["compute_node", "ports"]
474 }
475 }
476 sdn_external_port_schema = {
477 "$schema": "http://json-schema.org/draft-04/schema#",
478 "title": "External port information",
479 "type": "object",
480 "properties": {
481 "port": {"type": "string", "minLength": 1, "maxLength": 60},
482 "vlan": vlan_schema,
483 "mac": mac_schema
484 },
485 "required": ["port"]
486 }
487
488 # PDUs
489 pdu_interface = {
490 "type": "object",
491 "properties": {
492 "name": nameshort_schema,
493 "mgmt": bool_schema,
494 "type": {"enum": ["overlay", 'underlay']},
495 "ip-address": ip_schema,
496 # TODO, add user, password, ssh-key
497 "mac-address": mac_schema,
498 "vim-network-name": nameshort_schema, # interface is connected to one vim network, or switch port
499 "vim-network-id": nameshort_schema,
500 # # provide this in case SDN assist must deal with this interface
501 # "switch-dpid": dpid_Schema,
502 # "switch-port": nameshort_schema,
503 # "switch-mac": nameshort_schema,
504 # "switch-vlan": vlan_schema,
505 },
506 "required": ["name", "mgmt", "ip-address"],
507 "additionalProperties": False
508 }
509 pdu_new_schema = {
510 "title": "pdu creation input schema",
511 "$schema": "http://json-schema.org/draft-04/schema#",
512 "type": "object",
513 "properties": {
514 "name": nameshort_schema,
515 "type": nameshort_schema,
516 "description": description_schema,
517 "shared": bool_schema,
518 "vims": nameshort_list_schema,
519 "vim_accounts": nameshort_list_schema,
520 "interfaces": {
521 "type": "array",
522 "items": pdu_interface,
523 "minItems": 1
524 }
525 },
526 "required": ["name", "type", "interfaces"],
527 "additionalProperties": False
528 }
529
530 pdu_edit_schema = {
531 "title": "pdu edit input schema",
532 "$schema": "http://json-schema.org/draft-04/schema#",
533 "type": "object",
534 "properties": {
535 "name": nameshort_schema,
536 "type": nameshort_schema,
537 "description": description_schema,
538 "shared": bool_schema,
539 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
540 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
541 "interfaces": {"oneOf": [
542 array_edition_schema,
543 {
544 "type": "array",
545 "items": pdu_interface,
546 "minItems": 1
547 }
548 ]}
549 },
550 "additionalProperties": False,
551 "minProperties": 1
552 }
553
554 # USERS
555 user_new_schema = {
556 "$schema": "http://json-schema.org/draft-04/schema#",
557 "title": "New user schema",
558 "type": "object",
559 "properties": {
560 "username": nameshort_schema,
561 "password": passwd_schema,
562 "projects": nameshort_list_schema,
563 },
564 "required": ["username", "password", "projects"],
565 "additionalProperties": False
566 }
567 user_edit_schema = {
568 "$schema": "http://json-schema.org/draft-04/schema#",
569 "title": "User edit schema for administrators",
570 "type": "object",
571 "properties": {
572 "password": passwd_schema,
573 "projects": {
574 "oneOf": [
575 nameshort_list_schema,
576 array_edition_schema
577 ]
578 },
579 },
580 "minProperties": 1,
581 "additionalProperties": False
582 }
583
584 # PROJECTS
585 project_new_schema = {
586 "$schema": "http://json-schema.org/draft-04/schema#",
587 "title": "New project schema for administrators",
588 "type": "object",
589 "properties": {
590 "name": nameshort_schema,
591 "admin": bool_schema,
592 },
593 "required": ["name"],
594 "additionalProperties": False
595 }
596 project_edit_schema = {
597 "$schema": "http://json-schema.org/draft-04/schema#",
598 "title": "Project edit schema for administrators",
599 "type": "object",
600 "properties": {
601 "admin": bool_schema,
602 },
603 "additionalProperties": False,
604 "minProperties": 1
605 }
606
607 # GLOBAL SCHEMAS
608
609 nbi_new_input_schemas = {
610 "users": user_new_schema,
611 "projects": project_new_schema,
612 "vim_accounts": vim_account_new_schema,
613 "sdns": sdn_new_schema,
614 "ns_instantiate": ns_instantiate,
615 "ns_action": ns_action,
616 "ns_scale": ns_scale,
617 "pdus": pdu_new_schema,
618 }
619
620 nbi_edit_input_schemas = {
621 "users": user_edit_schema,
622 "projects": project_edit_schema,
623 "vim_accounts": vim_account_edit_schema,
624 "sdns": sdn_edit_schema,
625 "pdus": pdu_edit_schema,
626 }
627
628 # NETSLICE SCHEMAS
629 nsi_slice_instantiate = deepcopy(ns_instantiate)
630 nsi_slice_instantiate["title"] = "netslice subnet instantiation params input schema"
631 nsi_slice_instantiate["properties"]["id"] = name_schema
632 del nsi_slice_instantiate["required"]
633
634 nsi_vld_instantiate = {
635 "title": "netslice vld instantiation params input schema",
636 "$schema": "http://json-schema.org/draft-04/schema#",
637 "type": "object",
638 "properties": {
639 "name": string_schema,
640 "vim-network-name": {"OneOf": [string_schema, object_schema]},
641 "vim-network-id": {"OneOf": [string_schema, object_schema]},
642 "ip-profile": object_schema,
643 },
644 "required": ["name"],
645 "additionalProperties": False
646 }
647
648 nsi_instantiate = {
649 "title": "netslice action instantiate input schema",
650 "$schema": "http://json-schema.org/draft-04/schema#",
651 "type": "object",
652 "properties": {
653 "lcmOperationType": string_schema,
654 "nsiInstanceId": id_schema,
655 "nsiName": name_schema,
656 "nsiDescription": {"oneOf": [description_schema, {"type": "null"}]},
657 "nstId": string_schema,
658 "vimAccountId": id_schema,
659 "ssh_keys": {"type": "string"},
660 "nsi_id": id_schema,
661 "netslice-subnet": {
662 "type": "array",
663 "minItems": 1,
664 "items": nsi_slice_instantiate
665 },
666 "netslice-vld": {
667 "type": "array",
668 "minItems": 1,
669 "items": nsi_vld_instantiate
670 },
671 },
672 "required": ["nsiName", "nstId", "vimAccountId"],
673 "additionalProperties": False
674 }
675
676 nsi_action = {
677
678 }
679
680 nsi_terminate = {
681
682 }
683
684
685 class ValidationError(Exception):
686 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
687 self.http_code = http_code
688 Exception.__init__(self, message)
689
690
691 def validate_input(indata, schema_to_use):
692 """
693 Validates input data against json schema
694 :param indata: user input data. Should be a dictionary
695 :param schema_to_use: jsonschema to test
696 :return: None if ok, raises ValidationError exception on error
697 """
698 try:
699 if schema_to_use:
700 js_v(indata, schema_to_use)
701 return None
702 except js_e.ValidationError as e:
703 if e.path:
704 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
705 else:
706 error_pos = ""
707 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
708 except js_e.SchemaError:
709 raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)