已开启
修复映射器检查工具 #1507
HuangJiayi创建于 10 天前
修复映射器检查工具 #1507
已开启
HuangJiayi创建于 10 天前
5 个文件变更+101-18
@@ -62,7 +62,7 @@ class AppConan(ConanBase):
62 tools_path = os.path.join(self.source_folder, "tools")62 tools_path = os.path.join(self.source_folder, "tools")
63 sys.path.append(tools_path)63 sys.path.append(tools_path)
64 from mapper_check import MapperCheck64 from mapper_check import MapperCheck
65- MapperCheck.check()65+ MapperCheck.check(str(self.options.oem))
66 schema_check = str(self.options.schema_check)66 schema_check = str(self.options.schema_check)
67 if schema_check == "true":67 if schema_check == "true":
68 from schema_check.schema_checker import SchemaChecker68 from schema_check.schema_checker import SchemaChecker
@@ -45,11 +45,11 @@ class ErrorlogPrinter:
45 self.error_ruleinfo_table['6-3'] = 'AutoPagingEnabled只允许在redfish接口中配置'45 self.error_ruleinfo_table['6-3'] = 'AutoPagingEnabled只允许在redfish接口中配置'
46 46 
47 def get_relpath_under_rackmount(self, path):47 def get_relpath_under_rackmount(self, path):
48- start_index = path.find('interface_config')48+ start_indexes = [path.find(root) for root in ('interface_config', 'oem')]
49- if start_index != -1:49+ start_indexes = [index for index in start_indexes if index != -1]
50- return path[start_index:]50+ if not start_indexes:
51- else:
52 return ''51 return ''
52+ return path[min(start_indexes):]
53 53 
54 def default_error(self):54 def default_error(self):
55 return '未定义的Rule序号'55 return '未定义的Rule序号'
@@ -63,15 +63,24 @@ def get_abspath_under_rackmount(path):
63 return os.path.join(os.getcwd(), path)63 return os.path.join(os.getcwd(), path)
64 64 
65 65 
66-def load_custom_config():66+def load_custom_config(oem=None):
67 # 读取批量替换字段的关键字,在检查时进行替换避免校验失败67 # 读取批量替换字段的关键字,在检查时进行替换避免校验失败
68 for interface_name in ReplaceDict:68 for interface_name in ReplaceDict:
69- replace_config_path = 'interface_config/{}/config.json'.format(interface_name)69+ ReplaceDict[interface_name] = {}
70- if os.path.exists(replace_config_path):70+ replace_config_paths = [
71+ 'interface_config/{}/config.json'.format(interface_name)
72+ ]
73+ if oem:
74+ replace_config_paths.append(
75+ 'oem/{}/{}/config.json'.format(oem, interface_name)
76+ )
77+ for replace_config_path in replace_config_paths:
78+ if not os.path.exists(replace_config_path):
79+ continue
71 with open(replace_config_path, 'r') as f:80 with open(replace_config_path, 'r') as f:
72 config = json.load(f)81 config = json.load(f)
73 if config and isinstance(config.get('GlobalVariable'), dict):82 if config and isinstance(config.get('GlobalVariable'), dict):
74- ReplaceDict[interface_name] = config.get('GlobalVariable')83+ ReplaceDict[interface_name].update(config.get('GlobalVariable'))
75 84 
76 85 
77def remove_array_subscript(member):86def remove_array_subscript(member):
@@ -744,9 +753,22 @@ class ReferenceChecker:
744 753 
745 754 
746class MapperChecker:755class MapperChecker:
747- def __init__(self):756+ def __init__(self, oem=None):
748 self.schema_path = os.path.abspath('tools/mapper_check/data_mapping_schema.json')757 self.schema_path = os.path.abspath('tools/mapper_check/data_mapping_schema.json')
749 self.is_success = True758 self.is_success = True
759+ self.oem = oem
760+ 
761+ def get_target_dirs(self, check_component_name):
762+ target_dirs = list(TargetDirs[check_component_name])
763+ if not self.oem:
764+ return target_dirs
765+ 
766+ for target_dir in TargetDirs[check_component_name]:
767+ relative_dir = os.path.relpath(target_dir, 'interface_config')
768+ oem_target_dir = os.path.join('oem', self.oem, relative_dir)
769+ if os.path.isdir(oem_target_dir):
770+ target_dirs.append(oem_target_dir)
771+ return target_dirs
750 772 
751 @staticmethod773 @staticmethod
752 def get_target_dir(check_component_name, dir_type):774 def get_target_dir(check_component_name, dir_type):
@@ -825,7 +847,7 @@ class MapperChecker:
825 self.get_plugin_file(check_component_name)847 self.get_plugin_file(check_component_name)
826 848 
827 schema_json = load_json(self.schema_path)849 schema_json = load_json(self.schema_path)
828- for target_dir in TargetDirs[check_component_name]:850+ for target_dir in self.get_target_dirs(check_component_name):
829 # 各类型接口的Uri记录相互独立,包括ipmcget和ipmcset851 # 各类型接口的Uri记录相互独立,包括ipmcget和ipmcset
830 UriDic.clear()852 UriDic.clear()
831 target_dir = get_abspath_under_rackmount(target_dir)853 target_dir = get_abspath_under_rackmount(target_dir)
@@ -862,14 +884,14 @@ class MapperChecker:
862 'NULL')884 'NULL')
863 885 
864 886 
865-def check():887+def check(oem=None):
866 global ErrorlogPath888 global ErrorlogPath
867 ErrorlogPath = get_abspath_under_rackmount(ErrorlogPath)889 ErrorlogPath = get_abspath_under_rackmount(ErrorlogPath)
868 if os.path.exists(ErrorlogPath):890 if os.path.exists(ErrorlogPath):
869 os.remove(ErrorlogPath)891 os.remove(ErrorlogPath)
870 # 加载定制文件892 # 加载定制文件
871- load_custom_config()893+ load_custom_config(oem)
872- checker = MapperChecker()894+ checker = MapperChecker(oem)
873 checker.check_component('web_backend')895 checker.check_component('web_backend')
874 checker.check_component('redfish')896 checker.check_component('redfish')
875 checker.check_component('cli')897 checker.check_component('cli')
@@ -35,13 +35,14 @@ rackmount
35 35 
36### 运行方法36### 运行方法
37检查工具脚本已集成至构建脚本`build.py`中,执行`python3 build.py`构建时会自动先运行检查工具。若检查失败报错,会终止构建;若无报错,则开始构建。37检查工具脚本已集成至构建脚本`build.py`中,执行`python3 build.py`构建时会自动先运行检查工具。若检查失败报错,会终止构建;若无报错,则开始构建。
38+通过Conan构建时,检查工具会根据`oem`选项同时扫描`oem/<oem>`下对应的映射配置。
38 39 
39### 文件结构40### 文件结构
40执行检查及构建时,请按照上方的文件结构,尽量不要做改动!!41执行检查及构建时,请按照上方的文件结构,尽量不要做改动!!
41 42 
42`build.py``mapper_check`文件下引入了`MapperCheck`模块,而`MapperCheck`模块检查时会依赖于`data_mapping_schema.json`语法检查配置文件,代码中规定了该配置文件的相对位置在`mapper_check`文件下,因此请勿移动`build.py``MapperCheck.py``data_mapping_schema.json`的位置。43`build.py``mapper_check`文件下引入了`MapperCheck`模块,而`MapperCheck`模块检查时会依赖于`data_mapping_schema.json`语法检查配置文件,代码中规定了该配置文件的相对位置在`mapper_check`文件下,因此请勿移动`build.py``MapperCheck.py``data_mapping_schema.json`的位置。
43 44 
44-同样的,在检查命令json配置、命令调用的插件、脚本合法性过程中,依赖于各组件`mapping_config`(cli的为`ipmcget`和`ipmcset`)下的配置文件、`plugins`下的插件和`script`下的脚本,而在代码中规定了这些文件的相对位都在`interface_config`下的各自组件下,因此请勿移动这些文件的相对位置。45+同样的,在检查命令json配置、命令调用的插件、脚本合法性过程中,依赖于各组件`mapping_config`(cli的为`ipmcget`和`ipmcset`)下的配置文件、`plugins`下的插件和`script`下的脚本。基础配位于`interface_config`下,OEM映射配置位于`oem/<oem>`下,请勿移动这些文件的相对位置。
45 46 
46此外,获取绝对位置时会搜索`/rackmount`所在位置,因此也请不要将代码移出`rackmount`仓。47此外,获取绝对位置时会搜索`/rackmount`所在位置,因此也请不要将代码移出`rackmount`仓。
47 48 
@@ -1069,9 +1069,69 @@
1069 },1069 },
1070 "ReqBody": {1070 "ReqBody": {
1071 "type": "object",1071 "type": "object",
1072- "items": {1072+ "properties": {
1073- "$ref": "#/definitions/PropertiesItem"1073+ "Name": {
1074- }1074+ "type": "string"
1075+ },
1076+ "Type": {
1077+ "oneOf": [
1078+ {
1079+ "type": "string"
1080+ },
1081+ {
1082+ "type": "array",
1083+ "items": {
1084+ "type": "string"
1085+ }
1086+ }
1087+ ]
1088+ },
1089+ "Required": {
1090+ "type": "boolean"
1091+ },
1092+ "Sensitive": {
1093+ "type": "boolean"
1094+ },
1095+ "LockdownAllow": {
1096+ "type": "boolean"
1097+ },
1098+ "Validator": {
1099+ "type": "array"
1100+ },
1101+ "minItems": {
1102+ "type": "integer"
1103+ },
1104+ "maxItems": {
1105+ "type": "integer"
1106+ },
1107+ "uniqueItems": {
1108+ "type": "boolean"
1109+ },
1110+ "Description": {
1111+ "type": "string"
1112+ },
1113+ "DataType": false,
1114+ "Properties": {
1115+ "type": "object",
1116+ "additionalProperties": {
1117+ "$ref": "#/definitions/ReqBody"
1118+ }
1119+ },
1120+ "Items": {
1121+ "oneOf": [
1122+ {
1123+ "$ref": "#/definitions/ReqBody"
1124+ },
1125+ {
1126+ "type": "array",
1127+ "items": {
1128+ "$ref": "#/definitions/ReqBody"
1129+ }
1130+ }
1131+ ]
1132+ }
1133+ },
1134+ "additionalProperties": false
1075 },1135 },
1076 "RspBody": {1136 "RspBody": {
1077 "oneOf": [1137 "oneOf": [