config_tools: add SyntacticValidationStage before save scenario
add SyntacticValidationStage before save scenario Tracked-On: #6691 Signed-off-by: Weiyi Feng <weiyix.feng@intel.com>
This commit is contained in:
parent
4376b169c3
commit
68636087a6
|
@ -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) {
|
||||
|
|
|
@ -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: '<p>Select the VM type. A standard VM (<span class=…ial features for time-sensitive applications.</p>'}
|
||||
{
|
||||
$ref: '#/definitions/BasicVMType',
|
||||
title: 'VM type',
|
||||
description: '<p>Select the VM type. A standard VM (<span class=…ial features for time-sensitive applications.</p>'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue