acrn-hypervisor/misc/config_tools/configurator/pyodide/validateScenario.py
Junjie Mao fbfa81a665 config_tools: conduct full validation on save
This patch makes the configurator validate both syntactically and
semantically the resulting scenario XML everytime users save their
configurations. This allows the validation to catch all errors and report
status properly.

While a full validation is conducted, the syntactic errors are not shown
at the top of the forms in the same way as the semantic ones. This is
because syntactic rules are already built into the JSON schema and
will be warned real-time under the corresponding widgets. There is
no need to duplicate such errors. At the same time, the messages of
syntactic errors are generated by xmlschema which may not look
friendly to end users who do not have knowledge about the internal
structures of scenario XMLs.

Tracked-On: #6691
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2022-06-29 13:53:42 +08:00

62 lines
1.9 KiB
Python

#!/usr/bin/env python3
__package__ = 'configurator.pyodide'
from pathlib import Path
from tempfile import TemporaryDirectory
from scenario_config.default_populator import DefaultValuePopulatingStage
from scenario_config.pipeline import PipelineObject, PipelineEngine
from scenario_config.validator import ValidatorConstructionByFileStage, SemanticValidationStage, \
SyntacticValidationStage
from scenario_config.xml_loader import XMLLoadStage
from .pyodide import (
convert_result, write_temp_file,
# Todo: add debug switch
# is_debug,
nuc11_board, nuc11_scenario, scenario_xml_schema_path, datachecks_xml_schema_path
)
def main(board, scenario):
pipeline = PipelineEngine(["board_path", "scenario_path", "schema_path", "datachecks_path"])
stages = [
ValidatorConstructionByFileStage(),
XMLLoadStage("schema"),
XMLLoadStage("board"),
XMLLoadStage("scenario"),
DefaultValuePopulatingStage(),
SyntacticValidationStage(),
SemanticValidationStage(),
]
pipeline.add_stages(stages)
with TemporaryDirectory() as tmpdir:
write_temp_file(tmpdir, {
'board.xml': board,
'scenario.xml': scenario
})
board_file_path = Path(tmpdir) / 'board.xml'
scenario_file_path = Path(tmpdir) / 'scenario.xml'
obj = PipelineObject(
board_path=board_file_path,
scenario_path=scenario_file_path,
schema_path=scenario_xml_schema_path,
datachecks_path=datachecks_xml_schema_path
)
pipeline.run(obj)
syntactic_errors = obj.get("syntactic_errors")
semantic_errors = obj.get("semantic_errors")
return convert_result({"syntactic_errors": syntactic_errors, "semantic_errors": semantic_errors})
def test():
main(nuc11_board, nuc11_scenario)
if __name__ == '__main__':
test()