mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-04-30 12:44:07 +00:00
Today we are using, in the configurator, the complete scenario XML schema to validate XML files given by users. While this helps identify invalid XMLs at an early stage, such checks are too strict because the configurator users may save invalid XMLs if they keep some errors in the forms unresolved, and we do allow them to save anytime they want. As a result, users may save something that they cannot load back anymore. This patch introduces a tailored version of the scenario XML schema which only verifies the existence of the top-level nodes that the configurator assumes to exist. This seems to be a good balance that blocks XMLs that are broken or using old formats but permits those that has local and fixable data issues. Tracked-On: #6691 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
54 lines
1.5 KiB
Python
54 lines
1.5 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, SyntacticValidationStage
|
|
from scenario_config.xml_loader import XMLLoadStage
|
|
|
|
from .pyodide import (
|
|
convert_result, write_temp_file,
|
|
nuc11_scenario, schema_dir
|
|
)
|
|
|
|
|
|
def main(scenario):
|
|
pipeline = PipelineEngine(["scenario_path", "schema_path", "datachecks_path"])
|
|
pipeline.add_stages([
|
|
ValidatorConstructionByFileStage(),
|
|
XMLLoadStage("schema"),
|
|
XMLLoadStage("scenario"),
|
|
DefaultValuePopulatingStage(),
|
|
SyntacticValidationStage(),
|
|
])
|
|
|
|
try:
|
|
with TemporaryDirectory() as tmpdir:
|
|
write_temp_file(tmpdir, {
|
|
'scenario.xml': scenario
|
|
})
|
|
scenario_file_path = Path(tmpdir) / 'scenario.xml'
|
|
|
|
obj = PipelineObject(
|
|
scenario_path=scenario_file_path,
|
|
schema_path=schema_dir / 'scenario_structure.xsd',
|
|
datachecks_path=None
|
|
)
|
|
pipeline.run(obj)
|
|
|
|
validate_result = obj.get("syntactic_errors")
|
|
return "\n\n".join(map(lambda x: x["message"], validate_result))
|
|
except Exception as e:
|
|
return str(e)
|
|
|
|
|
|
def test():
|
|
print(main(nuc11_scenario))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test()
|