add a redfish schema
在redfish中添加自己的schema xml文件,需要以下几步:
- 在py脚本中添加
- 在index中添加
- 添加xml文件
- 修改hpp中的data.type
- 使用工具验证schema
1. 在py脚本中添加code
在python脚本中添加以下代码。在工具去验证schema的时候可以把文件从bmc下载到pc。
# build\workspace\sources\bmcweb\scripts\update_schemas.py
metadata_index.write(
" <edmx:Reference Uri=\"/redfish/v1/schema/OemService_v1.xml\">\n")
metadata_index.write(" <edmx:Include Namespace=\"OemService\"/>\n")
metadata_index.write(" <edmx:Include Namespace=\"OemService.v1_0_0\"/>\n")
metadata_index.write(" </edmx:Reference>\n")
2. 在index中添加code
这里相当于添加头文件,指定文件,指定namespace。
build\workspace\sources\bmcweb\static\redfish\v1\$metadata\index.xml
<edmx:Reference Uri="/redfish/v1/schema/OemService_v1.xml">
<edmx:Include Namespace="OemService"/>
<edmx:Include Namespace="OemService.v1_0_0"/>
</edmx:Reference>
3. 添加xml文件
把自己的文件添加进来,注意其中的namespace等
build\workspace\sources\bmcweb\static\redfish\v1\schema\OemService_v1.xml
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="Org.OData.Core.V1.xml">
<edmx:Include Namespace="Org.OData.Core.V1" Alias="OData"/>
</edmx:Reference>
<edmx:Reference Uri="Org.OData.Measures.V1.xml">
<edmx:Include Namespace="Org.OData.Measures.V1" Alias="Measures"/>
</edmx:Reference>
<edmx:Reference Uri="RedfishExtensions_v1.xml">
<edmx:Include Namespace="RedfishExtensions.v1_0_0" Alias="Redfish"/>
<edmx:Include Namespace="Validation.v1_0_0" Alias="Validation"/>
</edmx:Reference>
<edmx:Reference Uri="Resource_v1.xml">
<edmx:Include Namespace="Resource"/>
<edmx:Include Namespace="Resource.v1_0_0"/>
</edmx:Reference>
<!--# Include schemas for referred resources-->
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/SoftwareInventory_v1.xml">
<edmx:Include Namespace="SoftwareInventory"/>
<edmx:Include Namespace="SoftwareInventory.v1_0_0"/>
<edmx:Include Namespace="SoftwareInventory.v1_1_0"/>
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="OemService">
<ComplexType Name="SoftwareInventory" Type="OemService.SoftwareInventory">
<Property Name="LastUpdateTime" Type="Edm.String"/>
<Property Name="UpdateState" Type="Edm.String">
<Annotation Term="OData.Description" String="This indicates the software update state"/>
<Annotation Term="OData.LongDescription" String="This indicates the software update state of the software inventory resource."/>
</Property>
<Property Name="Status" Type="Edm.String">
<Annotation Term="OData.Description" String="This indicates whether the under the software list is valid."/>
<Annotation Term="OData.LongDescription" String="This indicates whether the under the software list is valid."/>
</Property>
</ComplexType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
4. 修改hpp中的data.type
在文件中修改odata.type。注意json文件的组织需要与schme中的code对应。
// build\workspace\sources\bmcweb\redfish-core\lib\software_service.hpp
asyncResp->res.jsonValue["Oem"]["SoftwareInventory"]["@odata.type"] =
"#OemService.SoftwareInventory";
以下是redfish get到的json数据,注意一个json里面可以有两种odata.type。数据的验证是通过type指定的命名空间查找xml中的数据。
{
"@odata.context": "/redfish/v1/$metadata#SoftwareInventory.SoftwareInventory",
"@odata.id": "/redfish/v1/UpdateService/SoftwareInventory/AdvancedSystemManagementKey",
"@odata.type": "#SoftwareInventory.v1_1_0.SoftwareInventory",
"Actions": {
"Oem": {
}
},
"Description": "Upload your key to activate advanced system management features",
"Id": "AdvancedSystemManagementKey",
"Name": "Software Inventory",
"Oem": {
"SoftwareInventory": {
"@odata.type": "#OemService.SoftwareInventory",
"LastUpdateTime": "Thu Jan 1 00:04:30 1970",
"Status": "ACTIVED",
"UpdateState": "Idle"
}
}
}
5. 使用工具验证schema
5.1 安装、配置工具
Redfish-Service-Validator-master
该工具到github上下载zip包即可,之后解压。https://github.com/DMTF/Redfish-Service-Validator
安装python等。注意python脚本,目前3.8.1可以快速安装whl包。
用cmd在代码目录下执行以下命令。
pip3 install -r requirements.txt
pip3 install beautifulsoup4 --upgrade
配置文件
在工具目录下新建文件夹config,在文件夹中添加config.ini 文件。
需要注意:
- TargetIP 是bmc的ip,每次执行前需要确认该ip
- MetadataFilePath 是schema的存放路径
- LocalOnlyMode置位false,ServiceMode 为true
- LogPath 输出结果的存放路径
[SystemInformation]
TargetIP = 10.112.108.153
SystemInfo = Test Config, place your own description of target system here
UserName = root
Password = 0penBmc
AuthType = Session
ForceAuth = False
Token =
UseSSL = True
CertificateCheck = False
CertificateBundle =
[Options]
MetadataFilePath = ./SchemaFiles/metadata
Schema_Pack =
OemCheck = True
CacheMode = Off
CacheFilePath =
SchemaSuffix = _v1.xml
Timeout = 150
HttpProxy =
HttpsProxy =
LocalOnlyMode = False
ServiceMode = True
PreferOnline = False
LinkLimit = LogEntry:1
Sample = 0
VersionCheck =
[Validator]
PayloadMode = Default
PayloadFilePath =
LogPath = ./logs
实际使用中只需要注意修改IP即可。
5.2 工具使用
工具配置完成后,用cmd在工具代码目录下执行以下命令,等待完成(十几分钟)。
RedfishServiceValidator.py -c config/config.ini
执行完成后会有结果提示。
5.3 查看结果
在代码目录下的logs文件夹中找到最新的时间命名的html文件,在浏览器中打开即可查看结果,
最上面可以查看到存在问题的url。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-X6arJgrD-1623291534619)(C:\Users\penghu4x\AppData\Roaming\Typora\typora-user-images\image-20210610095347716.png)]
之后修改xml或者hpp代码,知道测试通过。