mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-25 06:51:49 +00:00
config-tools: add validate_scenario_schema
add validate_scenario_schema to validate_scenario_setting and update the excption handling. Tracked-On: #5672 Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
This commit is contained in:
parent
1b255b7f51
commit
9ca32590dd
@ -91,7 +91,7 @@ def get_scenario_item_values(board_info, scenario_info):
|
|||||||
return scenario_item_values
|
return scenario_item_values
|
||||||
|
|
||||||
|
|
||||||
def validate_scenario_setting(board_info, scenario_info):
|
def validate_scenario_schema(scenario_info):
|
||||||
"""
|
"""
|
||||||
Validate settings in scenario xml if there is scenario schema
|
Validate settings in scenario xml if there is scenario schema
|
||||||
:param xsd_doc: scenario schema
|
:param xsd_doc: scenario schema
|
||||||
@ -99,18 +99,43 @@ def validate_scenario_setting(board_info, scenario_info):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import xmlschema
|
import xmlschema
|
||||||
|
except ImportError:
|
||||||
|
return
|
||||||
|
|
||||||
# XMLSchema does not process XInclude. Use lxml to expand the schema which is feed to XMLSchema as a string.
|
"""
|
||||||
xsd_doc = SCENARIO_SCHEMA_FILE
|
XMLSchema does not process XInclude.
|
||||||
|
Use lxml to expand the schema which is feed to XMLSchema as a string.
|
||||||
|
"""
|
||||||
|
xsd_doc = etree.parse(common.SCENARIO_SCHEMA_FILE)
|
||||||
xsd_doc.xinclude()
|
xsd_doc.xinclude()
|
||||||
my_schema = xmlschema.XMLSchema11(etree.tostring(xsd_doc, encoding="unicode"))
|
my_schema = xmlschema.XMLSchema11(etree.tostring(xsd_doc, encoding="unicode"))
|
||||||
|
|
||||||
it = my_schema.iter_errors(scenario_info)
|
it = my_schema.iter_errors(scenario_info)
|
||||||
for idx, validation_error in enumerate(it, start=1):
|
for idx, validation_error in enumerate(it, start=1):
|
||||||
print(f'[{idx}] path: {validation_error.path} | reason: {validation_error.reason}')
|
key = ""
|
||||||
print(validation_error)
|
if not validation_error:
|
||||||
except:
|
continue
|
||||||
pass
|
else:
|
||||||
|
path = str(validation_error.path).split("/")
|
||||||
|
cnt = 0
|
||||||
|
for p in path:
|
||||||
|
if '[' in p:
|
||||||
|
idx = int(p.split("[")[1].split("]")[0]) - 1
|
||||||
|
p = p.split("[")[0] + ":id=" + str(idx)
|
||||||
|
path[cnt] = p
|
||||||
|
cnt = cnt + 1
|
||||||
|
key =','.join(path[2:])
|
||||||
|
element = "'" + path[-1] + "' "
|
||||||
|
reason = validation_error.reason + ": last call: " + str(validation_error.obj)
|
||||||
|
scenario_cfg_lib.ERR_LIST[key] = element + reason
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def validate_scenario_setting(board_info, scenario_info):
|
||||||
|
hv_cfg_lib.ERR_LIST = {}
|
||||||
|
scenario_cfg_lib.ERR_LIST = {}
|
||||||
|
|
||||||
|
validate_scenario_schema(scenario_info)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Validate settings in scenario xml
|
Validate settings in scenario xml
|
||||||
@ -118,8 +143,6 @@ def validate_scenario_setting(board_info, scenario_info):
|
|||||||
:param scenario_info: scenario file
|
:param scenario_info: scenario file
|
||||||
:return: return a dictionary that contains errors
|
:return: return a dictionary that contains errors
|
||||||
"""
|
"""
|
||||||
hv_cfg_lib.ERR_LIST = {}
|
|
||||||
scenario_cfg_lib.ERR_LIST = {}
|
|
||||||
common.BOARD_INFO_FILE = board_info
|
common.BOARD_INFO_FILE = board_info
|
||||||
common.SCENARIO_INFO_FILE = scenario_info
|
common.SCENARIO_INFO_FILE = scenario_info
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user