config_tools: relax the checks of scenario XMLs from users

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>
This commit is contained in:
Junjie Mao 2022-06-10 15:13:43 +08:00 committed by acrnsi-robot
parent 6b6f961088
commit 5fcb58a4b2
3 changed files with 32 additions and 3 deletions

View File

@ -129,7 +129,8 @@ class Configurator {
return this.readFile(path).then((fileContent) => {
let syntactical_errors = this.pythonObject.validateScenarioStructure(fileContent);
if (syntactical_errors !== "") {
throw Error("The file has broken structure.\n" + syntactical_errors);
throw Error("The loaded file does not look like a valid ACRN scenario XML.\n\n" +
"If that file is used with ACRN 2.x, try upgrading it following the instructions at https://projectacrn.github.io/latest/tutorials/upgrading_configuration.html.\n");
}
return this.pythonObject.loadScenario(fileContent)
})

View File

@ -11,7 +11,7 @@ from scenario_config.xml_loader import XMLLoadStage
from .pyodide import (
convert_result, write_temp_file,
nuc11_scenario, scenario_xml_schema_path, datachecks_xml_schema_path
nuc11_scenario, schema_dir
)
@ -34,7 +34,7 @@ def main(scenario):
obj = PipelineObject(
scenario_path=scenario_file_path,
schema_path=scenario_xml_schema_path,
schema_path=schema_dir / 'scenario_structure.xsd',
datachecks_path=None
)
pipeline.run(obj)

View File

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This is a tailored version of the schema of scenario XML files and is used by the configurator to ensure files
from users have the basic structure of a valid scenario XML. We do not use the full-fledged schema here because
users are allowed to save a scenario XML with some data inconsistencies. -->
<xs:element name="acrn-config">
<xs:complexType>
<xs:all>
<xs:element name="hv">
<xs:complexType>
<xs:all>
<xs:any maxOccurs="unbounded" processContents="skip" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="vm" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="load_order" type="xs:string" />
<xs:any maxOccurs="unbounded" processContents="skip" />
</xs:all>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>