From 68636087a6435a4f773da6621ddb57c6c9782205 Mon Sep 17 00:00:00 2001 From: Weiyi Feng Date: Thu, 9 Jun 2022 18:23:16 +0800 Subject: [PATCH] config_tools: add SyntacticValidationStage before save scenario add SyntacticValidationStage before save scenario Tracked-On: #6691 Signed-off-by: Weiyi Feng --- .../packages/configurator/src/lib/acrn.ts | 4 +- .../configurator/src/pages/Config.vue | 46 +++++++++++++++++-- .../configurator/pyodide/validateScenario.py | 15 +++--- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts b/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts index 1eee4e1ea..c064cecd5 100644 --- a/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts +++ b/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts @@ -39,8 +39,8 @@ class PythonObject { return this.api('validateScenarioStructure', 'plaintext', scenarioXMLText) } - validateScenario(boardXMLText, scenarioXMLText) { - return this.api('validateScenario', 'json', boardXMLText, scenarioXMLText) + validateScenario(boardXMLText, scenarioXMLText, completed_verify = false) { + return this.api('validateScenario', 'json', boardXMLText, scenarioXMLText, completed_verify) } generateLaunchScript(boardXMLText, scenarioXMLText) { diff --git a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue index 9e4f794d7..fc7b61731 100644 --- a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue +++ b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue @@ -114,6 +114,7 @@ export default { window.getCurrentFormSchemaData = this.getCurrentFormSchemaData window.getCurrentScenarioData = this.getCurrentScenarioData window.getBoardData = this.getBoardData + window.getErrors = this.getErrors this.showFlag = this.isNewConfig === 'true' }, data() { @@ -142,6 +143,9 @@ export default { } }, methods: { + getErrors() { + return this.errors + }, back() { this.$router.back() }, @@ -216,7 +220,11 @@ export default { } else { if (this.schemas.ServiceVM.BasicConfigType.properties.hasOwnProperty('vm_type') === false) { this.schemas.ServiceVM.BasicConfigType.properties.vm_type = - {$ref: '#/definitions/BasicVMType', title: 'VM type', description: '

Select the VM type. A standard VM ('} + { + $ref: '#/definitions/BasicVMType', + title: 'VM type', + description: '

Select the VM type. A standard VM (' + } } } } @@ -379,11 +387,33 @@ export default { let scenarioWithDefault = configurator.pythonObject.populateDefaultValues(scenarioXMLData) scenarioWithDefault = scenarioWithDefault.json['acrn-config'] - if (scenarioWithDefault.hv.FEATURES.RDT.RDT_ENABLED === 'n') { + if ((!scenarioWithDefault.hv.FEATURES.hasOwnProperty('RDT')) || scenarioWithDefault.hv.FEATURES.RDT.RDT_ENABLED === 'n') { delete scenarioWithDefault.hv.CACHE_REGION } return scenarioWithDefault }, + translateErrors() { + let messageRegex = [ + { + regex: /The content of element '(.+?)' is not complete. Tag '(.+?)' expected./, + replace: '"$2" field in "$1" is required.' + }, + { + regex: /Unexpected child with tag 'VBDF' at position 1. Tag 'VM_NAME' expected./, + replace: '"VM name" in "InterVM shared memory region" is required.' + } + ] + const translate = (error) => { + for (const messageRegexKey in messageRegex) { + if (messageRegex[messageRegexKey].regex.test(error.message)) { + error.message = error.message.replace(messageRegex[messageRegexKey].regex, messageRegex[messageRegexKey].replace) + } + } + } + this.errors.map((error) => { + translate(error) + }) + }, saveScenario() { if (_.isEmpty(this.scenario.vm)) { alert("Please add at least one VM") @@ -424,13 +454,21 @@ export default { } // begin write down and verify + this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData, false) + // noinspection ExceptionCaughtLocallyJS + if (this.errors.length !== 0) { + this.translateErrors() + alert('Scenario have struct error, save failed!') + return; + } configurator.writeFile(this.WorkingFolder + 'scenario.xml', scenarioXMLData) .then(() => { stepDone = 1 console.log("validate settings...") - this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) + this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData, true) // noinspection ExceptionCaughtLocallyJS if (this.errors.length !== 0) { + this.translateErrors() throw new Error("validation failed") } console.log("validation ok") @@ -444,8 +482,6 @@ export default { writeDone.push(configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename])) } return Promise.all(writeDone) - } else { - return } }) .then((result) => { diff --git a/misc/config_tools/configurator/pyodide/validateScenario.py b/misc/config_tools/configurator/pyodide/validateScenario.py index 0509cf04b..90261531f 100644 --- a/misc/config_tools/configurator/pyodide/validateScenario.py +++ b/misc/config_tools/configurator/pyodide/validateScenario.py @@ -12,13 +12,11 @@ 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): +def main(board, scenario, completed_verify=False): pipeline = PipelineEngine(["board_path", "scenario_path", "schema_path", "datachecks_path"]) stages = [ ValidatorConstructionByFileStage(), @@ -27,11 +25,10 @@ def main(board, scenario): XMLLoadStage("board"), XMLLoadStage("scenario"), DefaultValuePopulatingStage(), - SemanticValidationStage(), + SyntacticValidationStage() ] - # - # if is_debug: - # stages.append(SyntacticValidationStage()) + if completed_verify: + stages.append(SemanticValidationStage()) pipeline.add_stages(stages) with TemporaryDirectory() as tmpdir: @@ -50,7 +47,9 @@ def main(board, scenario): ) pipeline.run(obj) - validate_result = obj.get("semantic_errors") + validate_result: list = obj.get("syntactic_errors") + if completed_verify: + validate_result.extend(obj.get("semantic_errors")) return convert_result(validate_result)