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>
This commit is contained in:
Junjie Mao 2022-06-10 15:18:36 +08:00 committed by acrnsi-robot
parent 5fcb58a4b2
commit fbfa81a665
2 changed files with 9 additions and 8 deletions

View File

@ -183,7 +183,8 @@ export default {
},
scenarioUpdate(scenarioData) {
let scenarioXMLData = this.scenarioToXML(scenarioData)
this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData)
let all_errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData)
this.errors = all_errors.semantic_errors
this.scenario = scenarioData;
this.showFlag = false;
this.updateCurrentFormSchema()
@ -428,9 +429,10 @@ export default {
.then(() => {
stepDone = 1
console.log("validate settings...")
this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData)
let all_errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData)
this.errors = all_errors.semantic_errors
// noinspection ExceptionCaughtLocallyJS
if (this.errors.length !== 0) {
if (all_errors.syntactic_errors.length !== 0 || all_errors.semantic_errors.length !== 0) {
throw new Error("validation failed")
}
console.log("validation ok")

View File

@ -27,11 +27,9 @@ def main(board, scenario):
XMLLoadStage("board"),
XMLLoadStage("scenario"),
DefaultValuePopulatingStage(),
SyntacticValidationStage(),
SemanticValidationStage(),
]
#
# if is_debug:
# stages.append(SyntacticValidationStage())
pipeline.add_stages(stages)
with TemporaryDirectory() as tmpdir:
@ -50,8 +48,9 @@ def main(board, scenario):
)
pipeline.run(obj)
validate_result = obj.get("semantic_errors")
return convert_result(validate_result)
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():