Fix `MemberId` value error causes Validator to fail
The test using the latest Redfish verifier found the following errors
```
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/
Temperatures/0
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/
Temperatures/1
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/
Temperatures/2
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/0
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/1
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/2
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/3
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/4
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/5
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/6
1 badMemberId errors in /redfish/v1/Chassis/chassis/Thermal#/Fans/7
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/0
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/1
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/2
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/3
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/4
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/5
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/6
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/7
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/8
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/Voltages/9
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/
Voltages/10
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/
Voltages/11
1 badMemberId errors in /redfish/v1/Chassis/chassis/Power#/
Voltages/12
```
Because the Redfish verifier checks whether the MemberId matches the
last part of the URL [1]
```
Added validation of the last segment of the URI to ensure it matches
the Id property or MemberId property where appropriate.
```
[1] https://github.com/DMTF/Redfish-Service-Validator/blob/master/CHANGELOG.md#224---2023-02-05
Tested: Validator passes
curl -k -H "X-Auth-Token: $token" -X GET
https://${bmc}/redfish/v1/Chassis/chassis/Thermal
{
"@odata.id": "/redfish/v1/Chassis/chassis/Thermal",
"@odata.type": "#Thermal.v1_4_0.Thermal",
"Fans": [
{
"@odata.id": "/redfish/v1/Chassis/chassis/Thermal#/Fans/0",
"@odata.type": "#Thermal.v1_3_0.Fan",
"MemberId": "0",
...
},
{
"@odata.id": "/redfish/v1/Chassis/chassis/Thermal#/Fans/1",
"@odata.type": "#Thermal.v1_3_0.Fan",
"MemberId": "1",
...
},
{
"@odata.id": "/redfish/v1/Chassis/chassis/Thermal#/Fans/2",
"@odata.type": "#Thermal.v1_3_0.Fan",
"MemberId": "2",
...
},
{
"@odata.id": "/redfish/v1/Chassis/chassis/Thermal#/Fans/3",
"@odata.type": "#Thermal.v1_3_0.Fan",
"MemberId": "3",
...
},
...
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I12151a2b20475071ea9b3ed3296754d56a0fed53
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 1af3032..8189bdb 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -751,7 +751,6 @@
// Set MemberId and Name for non-power sensors. For PowerSupplies and
// PowerControl, those properties have more general values because
// multiple sensors can be stored in the same JSON object.
- sensorJson["MemberId"] = sensorName;
std::string sensorNameEs(sensorName);
std::replace(sensorNameEs.begin(), sensorNameEs.end(), '_', ' ');
sensorJson["Name"] = std::move(sensorNameEs);
@@ -1101,7 +1100,7 @@
auto schemaItem =
std::find_if(fanRedfish.begin(), fanRedfish.end(),
[itemName](const nlohmann::json& fan) {
- return fan["MemberId"] == itemName;
+ return fan["Name"] == itemName;
});
if (schemaItem != fanRedfish.end())
{
@@ -1136,7 +1135,6 @@
redundancy["@odata.id"] = std::move(url);
redundancy["@odata.type"] = "#Redundancy.v1_3_2.Redundancy";
redundancy["MinNumNeeded"] = minNumNeeded;
- redundancy["MemberId"] = name;
redundancy["Mode"] = "N+m";
redundancy["Name"] = name;
redundancy["RedundancySet"] = redfishCollection;
@@ -1182,6 +1180,7 @@
if (value != nullptr)
{
*value += "/" + std::to_string(count);
+ sensorJson["MemberId"] = std::to_string(count);
count++;
sensorsAsyncResp->updateUri(sensorJson["Name"], *value);
}
@@ -2192,7 +2191,7 @@
// Check if matching PowerSupply object already exists in JSON array
for (nlohmann::json& powerSupply : powerSupplyArray)
{
- if (powerSupply["MemberId"] == inventoryItem.name)
+ if (powerSupply["Name"] == inventoryItem.name)
{
return powerSupply;
}
@@ -2205,7 +2204,6 @@
"redfish", "v1", "Chassis", chassisId, "Power");
url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
powerSupply["@odata.id"] = std::move(url);
- powerSupply["MemberId"] = inventoryItem.name;
powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " ");
powerSupply["Manufacturer"] = inventoryItem.manufacturer;
powerSupply["Model"] = inventoryItem.model;