summaryrefslogtreecommitdiff
path: root/test/redfish-core/include/utils
AgeCommit message (Collapse)AuthorFilesLines
2026-08-19utils: Map Available to UnavailableOfflineJustin Nguyen1-0/+250
- State `Available` will be mapped to `UnavailableOffline` for Status.State for resources that are present but unavailable - Added a utility function to reduce code duplication for retrieving resource's Status.State (`getResourceState`) and Status.Health (`getResourceHealth`) Tested: - Compiles and builds - Unit tests pass Change-Id: I1164a9412cbd4e1ab8938366ffc7ea9c7fe58786 Signed-off-by: Justin Nguyen <justinnanguyen@gmail.com>
2026-06-25Change a few message responses as errorsMyung Bae1-1/+1
Some of messages are not currently reported as errors, although they are the results as Redfish request errors. Those include - PropertyDuplicate - ResourceAlreadyExists - CreateFailedMissingReqProperties - PropertyValueFormatError - PropertyValueNotInList - PropertyValueTypeError - PropertyValueError - PropertyNotWritable - PropertyValueModified - PropertyMissing For example, PropertyValueFormatError is currently not treated as an error. It shows like ``` curl -k -X PATCH "${bmc}/redfish/v1/AccountService/Accounts/admin" \ -H "Content-Type: application/json" \ -d '{ "Password": "" }' "Password@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The value 'null' for the property Password is not a format that the property can accept.", "MessageArgs": [ "null", "Password" ], "MessageId": "Base.1.19.PropertyValueFormatError", "MessageSeverity": "Warning", "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed." } ] ``` After making it as an error, it will be like ``` { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The value 'null' for the property Password is not a format that the property can accept.", "MessageArgs": [ "null", "Password" ], "MessageId": "Base.1.19.PropertyValueFormatError", "MessageSeverity": "Warning", "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed." } ], "code": "Base.1.19.PropertyValueFormatError", "message": "The value 'null' for the property Password is not a format that the property can accept." } } ``` Tested: - Check those response messages Change-Id: I746c55e42e8f0cde205a3800e3da17cd78cf7e34 Signed-off-by: Myung Bae <myungbae@us.ibm.com>
2026-06-12sensor: add charge type supportJagpal Singh Gill1-0/+12
Add ChargeAh ReadingType and Ah units mapping for charge sensors exposed under /sensors/charge/ D-Bus path. This enables battery backup unit remaining and full charge sensors to appear in Redfish. Unit test added for charge sensor type. Tested: 1. Sensor Query using curl - ``` { "@odata.id": "/redfish/v1/Chassis/BBU_SHELF_1/Sensors/charge_BBU_SHELF_1_BBU5_REMAINING_CHARGE_AH", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "charge_BBU_SHELF_1_BBU5_REMAINING_CHARGE_AH", "Name": "BBU SHELF 1 BBU5 REMAINING CHARGE AH", "Reading": 10477.0, "ReadingType": "ChargeAh", "ReadingUnits": "Ah", "Status": { "Health": "OK", "State": "Enabled" }, ... } ``` 2. Redfish Validation passed using Redfish Validator. Signed-off-by: Jagpal Singh Gill <paligill@gmail.com> Change-Id: I9b7180cb8597378a1b42f9da73335ca96b20d55a
2026-04-21Add helper function for Location and `LocationType`Ed Tanous1-0/+38
The location_util::getLocation is used to find the `LocationCode` interface used for `ServiceLabel`. Also added logic to look for the Inventory.Connector.X interfaces to populate `LocationType`. The helper function is added to serve as the common location helper and remove the same method call in each individual resource files. For example, `Inventory.Connector.Embedded` means LocationType of Embedded type. Currently only support LocationType of - Slot - Embedded Tested: No changes to redfish tree yet Added unit tests Change-Id: I7f2a8d6172e37dd72881fbfb5a9dfeaf83b2db09 Signed-off-by: Zhenwei Chen <zhenweichen0207@gmail.com> Signed-off-by: Willy Tu <wltu@google.com> Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-04-21Remove time_tEd Tanous1-28/+37
time_t is less specific than using the equivalents in std::chono. In practice, most of the time we end up converting the time_t to some std::chrono class anyway. Avoid the intermediate conversion and just use the std::chrono version of time. Tested: Unit tests pass. Good Coverage Change-Id: I2e3eca78760e158feaaf4b91793631343e417f15 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-04-11Expose date/time in local timezoneIgor Kanyuka1-52/+119
BMC now exposes DateTime property under the Manager/<ID> in timezone configured on the BMC (local TZ) and not in UTC, but the other date time properties are still in UTC. Convert date time fields to local timezone. Tested: 1. Redfish service validator 2. Built Facebook's Catalina image with this change, ran in QEMU and checked manually varioius endpoints. 3. Ran automated tests [1] from openbmc-test-automation repo. 4. Unit tests [1] https://gerrit.openbmc.org/c/openbmc/openbmc-test-automation/+/88659 Change-Id: I8e587c7a1030deff8e6a550651c5e62719fe5299 Signed-off-by: Igor Kanyuka <ifelmail@gmail.com> Signed-off-by: Ed Tanous <ed@tanous.net>
2026-04-10Add unit tests for GetDateTimeOffsetNowEd Tanous1-0/+15
Not a lot we can do here, but at least we can check the regex matches. Tested: Unit test passes Change-Id: Ib6058042c725169e90b971bd15851f16d621ac0e Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-03-26Add ast-grep rules for common errorsDavy Marrero1-0/+1
docs/COMMON_ERRORS.md documents patterns that are easy to introduce and hard to catch in review. This adds machine-enforceable ast-grep rules for those patterns so they get caught in CI instead of review. Rules cover unsafe integer parsing, throwing JSON APIs, throwing filesystem APIs, wildcard lambda captures, blocking calls, missing trailing slashes on routes, and route string concatenation. Tested: ast-grep scan --error exits 0. Change-Id: I7ae24b52ac5b120826d29bb3ac6fce8f30199c15 Signed-off-by: Davy Marrero <dmarrero@nvidia.com>
2026-03-20Allow to set Manager TZ and show its time in localIgor Kanyuka1-0/+65
Current code always return Date time in UTC, despite local timezone may differ. This change allows to set manager timezone via redfish and show manager's TZ and offset in manager's local timezone. When the DateTime is being patched, the provided date time gets converted from the provided TZ to the local timezone, but configured TZ does not get changed. A user must explicitly patch TimeZoneName to change Manager's TZ. Tested: 1. Built an image, ran in QEMU, changed TZ to PST8PDT (negative offset), UTC (0 offset), and Tokyo (positive offset). Made sure the patch works and all the touched fields have correct values. See [1]. 2. Unit tests 3. Redfish validator [1] ``` $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-03-19T11:03:16-07:00" "-07:00" "PST8PDT" $ curl -i -k -H 'Content-type: application/json' -u root:0penBmc -d '{"TimeZoneName": "UTC"}' -X PATCH https://localhost:8443/redfish/v1/Managers/bmc HTTP/1.1 204 No Content Allow: GET, PATCH OData-Version: 4.0 Strict-Transport-Security: max-age=31536000; includeSubdomains Pragma: no-cache Cache-Control: no-store, max-age=0 X-Content-Type-Options: nosniff Date: Thu, 19 Mar 2026 18:03:28 GMT Content-Length: 0 $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-03-19T18:03:53+00:00" "+00:00" "UTC" $ curl -i -k -H 'Content-type: application/json' -u root:0penBmc -d '{"TimeZoneName": "Asia/Tokyo"}' -X PATCH https://localhost:8443/redfish/v1/Managers/bmc HTTP/1.1 204 No Content Allow: GET, PATCH OData-Version: 4.0 Strict-Transport-Security: max-age=31536000; includeSubdomains Pragma: no-cache Cache-Control: no-store, max-age=0 X-Content-Type-Options: nosniff Date: Thu, 19 Mar 2026 18:04:20 GMT Content-Length: 0 $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-03-20T03:04:32+09:00" "+09:00" "Asia/Tokyo" $ curl -i -k -H 'Content-type: application/json' -u root:0penBmc -d '{"DateTime": "2026-01-02T11:03:16-07:00"}' -X PATCH https://localhost:8443/redfish/v1/Managers/bmc HTTP/1.1 204 No Content Allow: GET, PATCH OData-Version: 4.0 Strict-Transport-Security: max-age=31536000; includeSubdomains Pragma: no-cache Cache-Control: no-store, max-age=0 X-Content-Type-Options: nosniff Date: Fri, 02 Jan 2026 18:03:16 GMT Content-Length: 0 $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-01-03T03:03:21+09:00" "+09:00" "Asia/Tokyo" $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc/LogServices/Journal/Entries | jq '.Members[0]' { "@odata.id": "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/cz0zNTMzMTVkMTBjYWQ0ZTg5ODJiYjliZGVmOTc2NDE2MDtpPTE7Yj00YzU5NzY1NzQ0M2M0N2IzOWZjYTZiNzU1ZWVlY2NjOTttPTFlZjc1Yzg7dD02MzY0OGQxOTFhZTE0O3g9ZDU5MjYwNzJkZTgzMWYzYw==", "@odata.type": "#LogEntry.v1_9_0.LogEntry", "Created": "2025-05-29T16:30:41.794580+00:00", "EntryType": "Oem", "Id": "cz0zNTMzMTVkMTBjYWQ0ZTg5ODJiYjliZGVmOTc2NDE2MDtpPTE7Yj00YzU5NzY1NzQ0M2M0N2IzOWZjYTZiNzU1ZWVlY2NjOTttPTFlZjc1Yzg7dD02MzY0OGQxOTFhZTE0O3g9ZDU5MjYwNzJkZTgzMWYzYw==", "Message": "kernel: Booting Linux on physical CPU 0xf00", "Name": "BMC Journal Entry", "OemRecordFormat": "BMC Journal Entry", "Severity": "OK" } ``` Change-Id: I5a4567b9ca6a0f56dd9d1b971d418a19bf625a10 Signed-off-by: Igor Kanyuka <ifelmail@gmail.com>
2026-03-18Fix collection Members io_error regressionTony Ao1-1/+16
Keep existing Members on local I/O failures in the generic collection path, and ensure empty collections still return mandatory Members and Members@odata.count properties. Add a reusable JSON array helper and use it in both collection building and aggregator merge logic to avoid clearing the response on transient failures. Fixes common error #13.[1] [1] https://github.com/openbmc/bmcweb/blob/master/docs/COMMON_ERRORS.md#13-complete-replacement-of-the-response-object Tested: unit test passed; validator passed on empty collection URIs. Change-Id: I8e144f55b99e3f8017abcebb11c409fffebf38ad Signed-off-by: Tony Ao <tao@nvidia.com>
2026-03-17Collection: keep Members stable on io_error; add array helperTony Ao1-0/+147
The generic collection path could clear the "Members" array on a local I/O error, which breaks aggregated responses and can trigger Common Error #13 [1]. The aggregator merge logic also needed a small reusable helper to ensure a JSON value is an array. Add a generic JSON array "ensure" helper in utils/collection.hpp and use it from both the local collection builder and the aggregator merge path. This avoids resetting Members on transient failures and avoids relying on transitive includes for the helper. [1] https://github.com/openbmc/bmcweb/blob/master/docs/COMMON_ERRORS.md#13-complete-replacement-of-the-response-object Tested: Unit tests passed. Change-Id: Iddaa608916af661f75989b4aeae9b557d09eebe3 Signed-off-by: Tony Ao <tao@nvidia.com>
2026-03-05Add SpeedPercent information for FanGeorge Liu1-0/+7
Adds SpeedPercent and SecondarySpeedPercent information according to the Redfish Fan schema.[1] The schema only allows fans of ReadingType Percent to be reported in SpeedPercent and SecondarySpeedPercent. These new properties are accessed through the Redfish Uri for a particular fan on a particular chassis[2]: ``` /redfish/v1/Chassis/<chassisId>/ThermalSubsystem/Fans/<fanId> ``` The primary and secondary fan sensors connected to the fan are found by: 1) Find all sensors associated to fan using the 'sensors' endpoint.[3] 2) For each sensor get its priority using the 'xyz.openbmc_project.Common.Priority' interface.[4][5] 3) Retrieve the sensor excerpt and place into the response based on the priority of the sensor. Implementation Notes: - The utility function objectExcerptToJson() is used to populate the SensorFanExcerpt. - Guards are added to handle different cases of D-Bus sensors Priority settings: - Fan has only 1 sensor associated and the sensor has no priority. Fills SpeedPercent for response. - Fan has more than one sensor. Any sensor without priority will be skipped. - Fan has one or more sensors with priority. The priority setting determines which property will be filled for the response. If the priority is 0 it uses SpeedPercent. If the priority is 1 it uses SecondarySpeedPercent. Any other priority the sensor will not be included in the response. - Fan has two sensors with the same priority. The first one is in the response and the second one is skipped. [1] https://redfish.dmtf.org/schemas/v1/Fan.v1_6_0.json [2] https://www.dmtf.org/sites/default/files/standards/documents/DSP0268_2025.4.html#fan [3] https://github.com/openbmc/docs/blob/master/architecture/sensor-architecture.md#association-type-2-linking-a-low-level-hardware-item-to-its-sensors [4] https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/66779 [5] https://gerrit.openbmc.org/c/openbmc/phosphor-hwmon/+/67170 Tested (using p10bmc hardware simulator with fan configuration edits): - Redfish Service Validator passes - Tested various fan configurations with Percent fans: ``` /* Fan has two sensors both with priority set */ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0", "@odata.type": "#Fan.v1_6_0.Fan", ... "SecondarySpeedPercent": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_1", "Reading": 60, "SpeedRPM": 12036.0 }, ... "SpeedPercent": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "Reading": 100, "SpeedRPM": 18000.0 }, ... } /* Fan has two sensors neither with priority, both skipped */ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan1 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan1", "@odata.type": "#Fan.v1_6_0.Fan", ... "PartNumber": "XXXXXXX", "SerialNumber": "XXXXXXXXXXXX", "SparePartNumber": "XXXXXXX", "Status": { "Health": "OK", "State": "Enabled" } } /* Fan has one sensor without priority, shown as primary */ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan2 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan2", "@odata.type": "#Fan.v1_6_0.Fan", ... "SpeedPercent": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_0", "Reading": 50, "SpeedRPM": 18000.0 }, ... } /* Fan has two sensors. Both have priority 0. The first sensor is in the * response the second sensor is skipped. */ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan3 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan3", "@odata.type": "#Fan.v1_6_0.Fan", "Id": "fan3", "Location": { "PartLocation": { "ServiceLabel": "U78DA.ND0.1234567-A3" } }, "LocationIndicatorActive": false, "Manufacturer": "Delta", "Model": "7B5G", "Name": "Fan", "PartNumber": "02YK200", "SerialNumber": "YS10JP12V0TY", "SparePartNumber": "02YK237", "SpeedPercent": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_0", "Reading": null, "SpeedRPM": 18000.0 }, "Status": { "Health": "OK", "State": "Enabled" } } /* Fan has two sensors. One priority 0, other priority 2. Only the * primary is in the response. */ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan4 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan4", "@odata.type": "#Fan.v1_6_0.Fan", ... "PartNumber": "XXXXXXX", "SerialNumber": "XXXXXXXXXXXX", "SparePartNumber": "XXXXXXX", "SpeedPercent": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_0", "Reading": null, "SpeedRPM": 18000.0 }, ... } /* Fan has two sensors. One priority 1, other priority 2. Only the * secondary is in the response. */ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan5 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan5", "@odata.type": "#Fan.v1_6_0.Fan", ... "SecondarySpeedPercent": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan5_1", "Reading": null, "SpeedRPM": 12036.0 }, "SerialNumber": "XXXXXXXXXXXX", "SparePartNumber": "XXXXXXX", "Status": { "Health": "OK", "State": "Enabled" } } ``` - Tested with rotational fans the new fields are not in response: ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0 { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0", "@odata.type": "#Fan.v1_6_0.Fan", ... "PartNumber": "XXXXXXX", "SerialNumber": "XXXXXXXXXXXX", "SparePartNumber": "XXXXXXX", "Status": { "Health": "OK", "State": "Enabled" } } curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "@odata.type": "#Sensor.v1_11_1.Sensor", ... "ReadingType": "Rotational", ... } ``` Signed-off-by: George Liu <liuxiwei@inspur.com> Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com> Signed-off-by: Janet Adkins <janeta@us.ibm.com> Change-Id: Ic767de3bde8bfe14b31da23b67e17a8d04eefadb
2026-02-05Sensors: Convert fan_tach sensors to PercentJanet Adkins1-11/+179
Redfish 2025.3 clarified the reporting of fan sensors should always be as ReadingType Percent to address issue #6197. [1] The fan_tach sensors on D-Bus are Rotational sensors. Conversion is necessary for these sensor values to reflect Percent instead. [2] This is reflected in a published mockup. [3] The Redfish update includes an additional sentence for the ReadingType description: ``` "... Services should represent fan speed and pump speed sensors with the `ReadingType` value `Percent`." ``` The ReadingRangeMax and ReadingRangeMin properties also must be converted to percent basis as they are defined to reflect the range of the Reading property. ``` curl -s https://redfish.dmtf.org/schemas/v1/Sensor.v1_11_1.json | jq .definitions.Sensor.properties.ReadingRangeMax.longDescription "This property shall indicate the maximum possible value of the `Reading` property for this sensor. This value is the range of valid readings for this sensor. Values outside this range are discarded as reading errors." ``` A new compile option, redfish-allow-rotational-fans, will maintain the old behavior of reporting fan_tach sensors as Rotational. When the option is disabled they will be reported as Percent. This will allow time for distributions to make adjustments to handle Percent reported fan sensors. The SpeedRPM Redfish property contains the RPM value for these sensors whether this option is enabled or disabled. Clients wanting to use the RPM value should convert to use the SpeedRPM property instead of the Reading property. ``` curl -s https://redfish.dmtf.org/schemas/v1/Sensor.v1_11_1.json | jq .definitions.Sensor.properties.SpeedRPM { "description": "The rotational speed.", "excerpt": "SensorFan,SensorFanArray,SensorPump", "longDescription": "This property shall contain a reading of the rotational speed of the device in revolutions per minute (RPM) units.", "readonly": true, "type": [ "number", "null" ], "units": "{rev}/min", "versionAdded": "v1_2_0" } ``` With the compile option disabled the following differences will be reflected in the responses for /redfish/v1/Chassis/chassis/Sensors/{}: - ReadingRangeMax/ReadingRangeMin: Converted to percent range, (100,0) - ReadingType: "Percent" - ReadingUnits: "%" - Reading: Computed percent value. The computation is the percent of the RPM Value within the MaxValue to MinValue range as reported by D-Bus for the sensor. - Note: If the percent cannot be computed for any reason the Reading property is set to null. - Note: SpeedRPM: Remains unchanged, it continues to report the RPM value as reported by D-Bus. Implementation Notes: - The SensorFanExcerpt and SensorFanArrayExcerpt definitions also include the SpeedRPM property. So moved setting of this property to be handled for excerpts as well. - The Sensor schema version has been updated regardless of the compile option setting. [1] https://github.com/DMTF/Redfish/issues/6197 [2] https://redfish.dmtf.org/schemas/v1/Sensor.v1_11_1.json [3] https://github.com/DMTF/Redfish-Publications/blob/main/mockups/public-rackmount1/Chassis/1U/Sensors/CPUFan1/index.json Tested: - Added new unit tests for new function getFanPercent() - Adjusted existing unit tests for Sensors to reflect changes for fan_tach sensors. - Redfish Service Validator passes (with option enabled and disabled) - Using hardware simulator hand-edited values for the min/max of the fan_tach sensors: - Option enabled: confirmed Redfish response same before and after code changes. - Option disabled: Confirmed Redfish responses and percent calculation. Example responses with compile option disabled: ``` // D-Bus: "Value" d 18000 "MaxValue" d 18000 "MinValue" d 0 curl -s -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan0_0", "Name": "fan0 0", "Reading": 100, "ReadingRangeMax": 100, "ReadingRangeMin": 0, "ReadingType": "Percent", "ReadingUnits": "%", "SpeedRPM": 18000.0, "Status": { "Health": "OK", "State": "Enabled" } } // D-Bus: "Value" d 18000 "MaxValue" d 36000 "MinValue" d 0 curl -s -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan1_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan1_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan1_0", "Name": "fan1 0", "Reading": 50, "ReadingRangeMax": 100, "ReadingRangeMin": 0, "ReadingType": "Percent", "ReadingUnits": "%", "SpeedRPM": 18000.0, "Status": { "Health": "OK", "State": "Enabled" } } // Minimum is non-zero // D-Bus: "Value" d 18000 "MaxValue" d 27000 "MinValue" d 9000 curl -s -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan2_0", "Name": "fan2 0", "Reading": 50, "ReadingRangeMax": 100, "ReadingRangeMin": 0, "ReadingType": "Percent", "ReadingUnits": "%", "SpeedRPM": 18000.0, "Status": { "Health": "OK", "State": "Enabled" } } // Minimum is not initialized - Reading is null // D-Bus: "Value" d 18000 "MaxValue" d 18000 "MinValue" d -inf curl -s -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan3_0", "Name": "fan3 0", "Reading": null, "ReadingRangeMax": 100, "ReadingRangeMin": 0, "ReadingType": "Percent", "ReadingUnits": "%", "SpeedRPM": 18000.0, "Status": { "Health": "OK", "State": "Enabled" } } // Minimum and Maximum are not initialized - so Reading is null // D-Bus: "Value" d 18000 "MaxValue" d inf "MinValue" d -inf curl -s -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan4_0", "Name": "fan4 0", "Reading": null, "ReadingRangeMax": 100, "ReadingRangeMin": 0, "ReadingType": "Percent", "ReadingUnits": "%", "SpeedRPM": 18000.0, "Status": { "Health": "OK", "State": "Enabled" } } ``` Example of unchanged response with compile option enabled: ``` curl -s -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan0_0", "Name": "fan0 0", "Reading": 18000.0, "ReadingRangeMax": 18000.0, "ReadingRangeMin": 0.0, "ReadingType": "Rotational", "ReadingUnits": "RPM", "SpeedRPM": 18000.0, "Status": { "Health": "OK", "State": "Enabled" } } ``` Change-Id: I8ec1e739bcd5ebce7453a2570569f2edc2284341 Signed-off-by: Janet Adkins <janeta@us.ibm.com>
2026-01-26Sensors: Add unit testsJanet Adkins1-0/+376
An earlier commit [1] refactored parts of objectPropertiesToJson() into sub-functions to make the code easier to follow. The review of that change requested unit tests for these new functions. [2] This commit adds them. [1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/85835 [2] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/85835/comments/408617a1_474b4062 Tested: Compiles and unit tests pass Change-Id: I65e06deccb4b7194603f2749a977986bcb673cd1 Signed-off-by: Janet Adkins <janeta@us.ibm.com>
2025-12-05sensor_utils: Add PeakReading propertyHarshit Aghera1-0/+69
Add support for PeakReading and PeakReadingTime for sensors. This enhancement allows sensor readings to include max observed value information in the Redfish API, along with timestamp. It uses PDI xyz.openbmc_project.Telemetry.Report. Property PeakReading is added if OperationType in PDI property ReadingParameters is set to Maximum. Current Limitation - The ResetMetrics action is currently not supported for sensor URIs. As a result, the ability to clear PeakReading values for GPU Power Sensors has not been implemented. Future Consideration - If ResetMetrics action support is added in the future, the corresponding functionality will also need to be implemented in the dbus-sensor application to ensure full compatibility. Schema: https://redfish.dmtf.org/schemas/v1/Sensor.v1_2_0.yaml (PeakReading) Backend implementation for reference: https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/82479 Tested: Build an image for nvl32-obmc machine with the following patches cherry picked. https://gerrit.openbmc.org/c/openbmc/openbmc/+/85490 https://gerrit.openbmc.org/c/openbmc/bmcweb/+/82449. The patch cherry-picks the following patches that are currently under review. ``` 1. device tree https://lore.kernel.org/all/aRbLqH8pLWCQryhu@molberding.nvidia.com/ 2. mctpd patches https://github.com/CodeConstruct/mctp/pull/85 3. u-boot changes https://lore.kernel.org/openbmc/20251121-msx4-v1-0-fc0118b666c1@nvidia.com/T/#t 4. kernel changes as specified in the openbmc patch (for espi) 5. entity-manager changes https://gerrit.openbmc.org/c/openbmc/entity-manager/+/85455 6. platform-init changes https://gerrit.openbmc.org/c/openbmc/platform-init/+/85456 7. spi changes https://lore.kernel.org/all/20251121-w25q01jv_fixup-v1-1-3d175050db73@nvidia.com/ ``` ``` > curl -s -k -u 'root:0penBmc' https://10.137.203.137/redfish/v1/Chassis/NVIDIA_GB200_1/Sensors/power_NVIDIA_GB200_GPU_0_Power_0 { "@odata.id": "/redfish/v1/Chassis/NVIDIA_GB200_1/Sensors/power_NVIDIA_GB200_GPU_0_Power_0", "@odata.type": "#Sensor.v1_2_0.Sensor", "Id": "power_NVIDIA_GB200_GPU_0_Power_0", "Name": "NVIDIA GB200 GPU 0 Power 0", "PeakReading": 52.671, "PeakReadingTime": 0, "Reading": 27.214, "ReadingRangeMax": 5000.0, "ReadingRangeMin": 0.0, "ReadingType": "Power", "ReadingUnits": "W", "Status": { "Health": "OK", "State": "Enabled" } }% ```` Change-Id: I8c1ab6ce85f31419db4a1d931bf99722d24afbd7 Signed-off-by: Harshit Aghera <haghera@nvidia.com>
2025-12-03Add remaining functions to systems_utils namespaceOliver Brewka1-20/+20
Initially, systems_utils.hpp has not defined its own namespace, all functions were under the redfish namespace. Patch 82078 [1] introduced systems_utils namespace to the header for new functionality. This patch adds all functions, that haven't been part of the new namespace to systems_utils namespace and updates all call sites accordingly. [1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/82078 Tested: Code compiles. Change-Id: Ia6ac3edd36aacc22cbf1a6adae4e2b264932b43c Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-17Use std::format for hex conversionsEd Tanous1-23/+1
Deprecate intoToHex handler now that we can do everything using std::format. Tested: RSV passes Redfish protocol validator passes Change-Id: I71000506573314d6c9326c4677f5fbca1ca02b46 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-10-21Add back include cleanerEd Tanous2-3/+3
Include cleaner helps the code review process. Add it back, by ignoring some of the more recent boost headers. Change-Id: I6eddd0e67cd9f469c93fbb344cc1ab46231e450f Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-10-14Add PowerWatts for EnvironmentMetricsGeorge Liu1-0/+7
The EnvironmentMetrics schema[1] provides for efficient retrieval of environmental metrics by separating them from performance metrics. EnvironmentMetrics is a property of the Chassis schema since v1_15_0[2]. EnvironmentMetrics was added to Redfish release 2021.2 [3] to be used instead of the deprecated Power schema.[4] This commit adds PowerWatts property of the EnvironmentMetrics schema. PowerWatts has been part of the EnvironmentMetrics schema since v1_1_0. PowerWatts is a SensorPowerExcerpt[5]. Implementation notes: The new D-Bus interface "xyz.openbmc_project.Sensor.Purpose" is used to find the sensor with the "TotalPower" purpose.[6][7] The new utility function sensor_utils::getSensorsByPurpose() returns a subset of an incoming list of sensors which implement a specified purpose. Multiple D-Bus calls are needed to find the sensor providing the totalPower: 1. Retrieve list of power sensors associated with specified chassis which implement the Sensor.Purpose interface using existing getAllSensorObjects() function. 2. For each of those power sensors retrieve the actual purpose of the sensor to find the sensor implementing totalPower purpose. Expect no more than one sensor to implement this purpose. New utility function getSensorsByPurpose() is used. 3. If a totalPower sensor is found then retrieve its properties to fill in PowerWatts in the response using existing sensor_utils::objectExcerptToJson() utility function. If no sensor has the "TotalPower" purpose then PowerWatts is not added to EnvironmentMetrics and no error is returned. [1] https://redfish.dmtf.org/schemas/v1/EnvironmentMetrics.v1_3_2.json [2] https://redfish.dmtf.org/schemas/v1/Chassis.v1_25_2.json [3] http://redfish.dmtf.org/schemas/Redfish_Release_History.pdf [4] https://redfish.dmtf.org/schemas/v1/Power.v1_7_3.json [5] http://redfish.dmtf.org/schemas/v1/Sensor.v1_9_1.json#/definitions/SensorPowerExcerpt [6] https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/75943 [7] https://gerrit.openbmc.org/c/openbmc/openpower-occ-control/+/77408 Tested: - Updated unit tests for new environmentMetricsNode enum - Redfish Service Validator passes (confirmed PowerWatts tested) ``` VERBOSE1 - ServiceRoot -> Chassis -> Members#4 -> EnvironmentMetrics, EnvironmentMetrics.v1_3_0, EnvironmentMetrics VERBOSE1 - @odata.id PASS VERBOSE1 - @odata.type PASS VERBOSE1 - Id PASS VERBOSE1 - Name PASS VERBOSE1 - PowerWatts PASS ``` - No "TotalPower" sensor exists (system never powered on). PowerWatts is not shown and no error is returned. ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics { "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics", "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics", "Id": "EnvironmentMetrics", "Name": "Chassis Environment Metrics" } ``` - "TotalPower" sensor exists (system powered on) ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system | grep PowerState "PowerState": "On", curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics { "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics", "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics", "Id": "EnvironmentMetrics", "Name": "Chassis Environment Metrics", "PowerWatts": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/power_total_power", "Reading": 191.0 } } ``` DataSourceUri is a valid sensor: ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/power_total_power { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/power_total_power", "@odata.type": "#Sensor.v1_2_0.Sensor", "Id": "power_total_power", "Name": "total power", "Reading": 191.0, "ReadingType": "Power", "ReadingUnits": "W", "Status": { "Health": "OK", "State": "Enabled" } } ``` - "TotalPower" sensor exists but null value (system powered off) ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system | grep PowerState "PowerState": "Off", curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics { "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics", "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics", "Id": "EnvironmentMetrics", "Name": "Chassis Environment Metrics", "PowerWatts": { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/power_total_power", "Reading": null } } ``` And again the DataSourceUri points to a valid sensor: ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/power_total_power { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/power_total_power", "@odata.type": "#Sensor.v1_2_0.Sensor", "Id": "power_total_power", "Name": "total power", "Reading": null, "ReadingType": "Power", "ReadingUnits": "W", "Status": { "Health": "OK", "State": "Enabled" } } ``` - Invalid chassis id ("TotalPower" sensor exists) ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassisBAD/EnvironmentMetrics { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Chassis named 'chassisBAD' was not found.", "MessageArgs": [ "Chassis", "chassisBAD" ], "MessageId": "Base.1.19.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.19.ResourceNotFound", "message": "The requested resource of type Chassis named 'chassisBAD' was not found." } } ``` Signed-off-by: George Liu <liuxiwei@inspur.com> Signed-off-by: Janet Adkins <janeta@us.ibm.com> Change-Id: Ibe84a5e7fe0d2b232f925e457a094c021ca85d36
2025-09-16Remove deprecated json decodesEd Tanous1-4/+7
These decodes haven't been standard practice for a while. While they will likely break some downstream builds, we need to clean things up. If you are seeing this commit message because your downstream build is broken, please migrate your code to using nlohmann::json::object_t instead of nlohmann::json when it does the unpack. Tested: Code compiles. Change-Id: Id892ee381b2d6b40a6366ee0622cde04d2cacd7b Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-09-15Add check to omit `DateTime` from etag calculationCorey Ethington1-0/+34
Ignores any json property named `DateTime` when calculating the etag value of an HTTP response as per the updated Redfish Spec (section 6.5: ETags) Tested: - Redfish Service Validator passes - Tested on romulus: 1. GET resource with a "DateTime" field ``` curl -k -H "X-Auth-Token: $XAUTH_TOKEN" "https://$BMC/redfish/v1/TaskService" \ --etag-save ./etag.txt -v ... < etag: "6A4CE897" ... { "@odata.id": "/redfish/v1/TaskService", "@odata.type": "#TaskService.v1_1_4.TaskService", "CompletedTaskOverWritePolicy": "Oldest", "DateTime": "2025-07-23T17:08:20+00:00", "Id": "TaskService", "LifeCycleEventOnTaskStateChange": true, "Name": "Task Service", "ServiceEnabled": true, "Status": { "State": "Enabled" }, "Tasks": { "@odata.id": "/redfish/v1/TaskService/Tasks" } ``` 2. GET same resource again later, etag is same as before ``` curl -k -H "X-Auth-Token: $XAUTH_TOKEN" "https://$BMC/redfish/v1/TaskService" \ --etag-save ./etag.txt -v ... < etag: "6A4CE897" ... { "@odata.id": "/redfish/v1/TaskService", "@odata.type": "#TaskService.v1_1_4.TaskService", "CompletedTaskOverWritePolicy": "Oldest", "DateTime": "2025-07-23T17:10:48+00:00", "Id": "TaskService", "LifeCycleEventOnTaskStateChange": true, "Name": "Task Service", "ServiceEnabled": true, "Status": { "State": "Enabled" }, "Tasks": { "@odata.id": "/redfish/v1/TaskService/Tasks" } ``` "DateTime" is the only value to have changed, but since it is ignored the etag did not change 3. GET with if-none-match returns 304 ``` curl -k -H "X-Auth-Token: $XAUTH_TOKEN" "https://$BMC/redfish/v1/TaskService" \ --etag-save ./etag.txt --etag-compare ./etag.txt -v ... > if-none-match: "6A4CE897" ... < HTTP/2 304 < allow: GET < odata-version: 4.0 < strict-transport-security: max-age=31536000; includeSubdomains < pragma: no-cache < cache-control: no-store, max-age=0 < x-content-type-options: nosniff < etag: "6A4CE897" < date: Wed, 23 Jul 2025 17:14:39 GMT < content-length: 0 < ... ``` Change-Id: I51f7668e75719c69c55535e4a1e48c8bae7c9488 Signed-off-by: Corey Ethington <cethington@coreweave.com>
2025-08-26Multi-host support for GET routes in systems.hppOliver Brewka1-0/+68
Add support for multi-host GET request-handling under the /redfish/v1/Systems/{computerSystemId}/ redfish resource. All multi-host supported redfish URIs can be found in this listing [1]. Multi-host meson options needed: -Dexperimental-redfish-multi-computer-system=enabled Tested: Validator passes on single-host machine and yv4 qemu emulation. [1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/76118 Change-Id: I67c17c3dd7a354fa9a2ebbc56d4def7a7e788909 Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-06-04Remove implicit conversionsEd Tanous2-10/+21
Since 2020, nlohmann has recognized that implicit conversions to and from json are an issue. Many bugs have been caused at both development time and runtime due to unexpected implicit conversions from json to std::string/int/bool. This commit disables implicit conversions using JSON_USE_IMPLICIT_CONVERSIONS [1]. This option will become the default in the future. That comment was written 3 years ago at this point, so we should prepare. Tested: Redfish service validator passes. [1] https://json.nlohmann.me/api/macros/json_use_implicit_conversions/ Change-Id: Id6cc47b9bbf8889e4777fd6d77ec992f3139962c Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-02-05Fix Message arg error in JSON Patchrohitpai1-0/+16
When array/vector object is expected in JSON patch the error info does not contain the actual wrong property instead shows "null". Fix is to correct the value in the error info. Tested - add new test case to verify this - unit tests are passing. Change-Id: Ica26ac9e501b5a34a5b118769cc1917eeab30524 Signed-off-by: rohitpai <rohitpai77@gmail.com>
2025-02-03Move error code utils into new filerohitpai2-141/+161
Error code utils can be used for aggregating error responses from multiples responses including use case for managing separate route handlers for OEM namespace Tests Units tests are passing. Change-Id: I2223d41fb318c0276de1ca64dd3e841bb988d902 Signed-off-by: rohitpai <rohitpai77@gmail.com>
2025-01-22Roll out error message utilsEd Tanous1-1/+0
This code should really be in a cpp/hpp file, not in a generated python script. The python script housed this temporarily to allow us to generate the registries. It's time to roll it out. Tested: Message registries generate successfully on GET. Redfish service validator passes. Change-Id: I7aca2d0a7fac6d530511421b667ff732617df61e Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-01-20Use SPDX identifiersEd Tanous8-0/+16
SPDX identifiers are simpler, and reduce the amount of cruft we have in code files. They are recommended by linux foundation, and therefore we should do as they allow. This patchset does not intend to modify any intent on any existing copyrights or licenses, only to standardize their inclusion. [1] https://www.linuxfoundation.org/blog/blog/copyright-notices-in-open-source-software-projects Change-Id: I935c7c0156caa78fc368c929cebd0f068031e830 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-12-12Fix clang-tidy for gcc-14Ed Tanous1-0/+1
We use these pragmas, that we must've been getting transitively through chrono in the past. Now we need to include them explicitly. Change-Id: Iee4c0a8866981b91adaa17bee0678b2c10e65ea9 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-12-10Make message registries use 2 digit versionsEd Tanous2-4/+4
Redfish specification, section 9.5.11.2 says: The MessageId property value shall be in the format: <MessageRegistryPrefix>.<MajorVersion>.<MinorVersion>.<MessageKey> bmcweb in certain places has incorrectly used the 3 digit version instead of the 2 digit version. This commit fixes that by modifying the parse_registries script to generate 3 separate struct entries to represent the registry version, and parse them where appropriate. MessageRegistryFileCollection uses the 3 digit version. No behavior changes. Message/event log entries use the 2 digit version. This will cause a MessageId change from: Base.1.19.0.InternalError to Base.1.19.InternalError This is a breaking change, so a new option to allow the old behavior is provided. Tested: Redfish Service validator passes. Heartbeat events on EventService show 2 digit versions. Change-Id: I4165e994f73e200f13bed8ea76cb58bee2b69faa Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-11-22json utility: fixed core dump during sensor loadJayanth Othayoth1-0/+8
bmcweb replaces underscores with spaces in sensor names for better readability. The existing objectKeyCmp function did not handle this case, leading to core dumps in the sensor load path. Error details are provided below. ``` bmcwebd[1368]: [DEBUG sensors.hpp:507] Added sensor P0_NS_VR_FAN_2 bmcwebd[1368]: terminate called after throwing an instance of 'boost::detail::with_throw_location<boost::system::system_error>' bmcwebd[1368]: what(): leftover [boost.url.grammar:4] ``` Implemented a new algorithm that alphabetically sorts non-URL keys and retains the existing logic for URL-type keys. Tested: Updated and verified the test cases. Change-Id: I39c3f7cc54dec5e7cf9658977e1078acb827afb2 Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com> Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-11-20Enable gcc-14 buildsEd Tanous1-0/+7
gcc-14 enables the std::chrono features we need for doing lots of time conversions. For whatever reason, std::chrono accepts a an hour of 60, whereas date.h didn't. This test case is really just a corner case, so accept either answer. Tested: Unit tests pass. Good coverage. Change-Id: I2fb7fcbebb2a4126b36f99d27b216b835d1e2994 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-10-17Handling of OutOfRange in ReadJsonMyung Bae1-0/+21
Currently readJsonPatch returns `PropertValueNotInList` in case when an input integer is out of range. This change is to return `PropertyValueOutOfRange` for the case out-of-range integer input. Tested: - Verify PATCH with an out-of-value integer. e.g. ``` $ curl -k -X PATCH https://${bmc}/redfish/v1/EventService/ -H "Content-Type: application/json" -d '{ "DeliveryRetryIntervalSeconds" : 4294967296}' ``` Before the change, its `MessageId` is `PropertyValueNotInList`. ``` "Message": "The value '4294967296' for the property DeliveryRetryIntervalSeconds is not in the list of acceptable values.", "MessageId": "Base.1.19.0.PropertyValueNotInList", "MessageSeverity": "Warning", "Resolution": "Choose a value from the enumeration list that the implementation can support and resubmit the request if the operation failed." ``` After the change, its `MessageId` will be `PropertyValueOutOfRange`. ``` "Message": "The value '4294967296' for the property DeliveryRetryIntervalSeconds is not in the supported range of acceptable values.", "MessageId": "Base.1.19.0.PropertyValueOutOfRange", "MessageSeverity": "Warning", "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed." ``` - Redfish Service Validator passes Change-Id: I0d0c5ecbc9f416b68fa7c0e81a0ea896ec2e50af Signed-off-by: Myung Bae <myungbae@us.ibm.com>
2024-10-14Implement TemperatureReadingsCelsius property for ThermalMetricsGeorge Liu1-0/+19
The ThermalMetrics schema[1] provides for efficient thermal metric gathering for thermal sensors. The schema allows retrieving just the thermal metrics with one Redfish URI. This prevents the additional work required when returning all the sensor data, or multiple Redfish URI calls to retrieve the properties for all of the thermal sensors. This commit implements the TemperatureReadingsCelsius property of ThermalMetrics[1]. ThermalMetrics is a property of ThermalSubsystem[2]. TemperatureReadingsCelsius is a SensorArrayExcerpt[3]. [1] https://redfish.dmtf.org/schemas/v1/ThermalMetrics.v1_0_1.json [2] https://redfish.dmtf.org/schemas/v1/ThermalSubsystem.v1_3_2.json [3] http://redfish.dmtf.org/schemas/v1/Sensor.v1_9_0.json#/definitions/SensorArrayExcerpt The temperature sensors are found by finding 'all_sensors' endpoints for specific chassis of D-Bus service /xyz/openbmc_project/sensors/temperature. An entry of SensorArrayExcerpt is built for each temperature sensor retrieved. Implementation Notes: - Common function sensor_utils::objectPropertiesToJson() is used to fill in sensor excerpt properties. Currently the only excerpt ChassisSubNode is ThermalMetrics. However there are others excerpts defined by Redfish. Right now mostly this is just skipping things, but I'm expecting when other sensor excerpts are implemented that some of the other properties may be added for excerpts as well. I'm expecting the combination of the chassisSubNode and the sensorType will be used to determine which properties are included for a particular call to build a sensor Json representation. - New sensor_utils::objectExcerptToJson() function created. This wraps sensor_utils::objectPropertiesToJson() and builds DataSourceUri for a sensor excerpt. - New sensor_utils::getAllSensorObjects() function created. This builds list of 'all_sensors' association endpoints for specified D-Bus path with specified D-Bus interfaces. Callback function is called with list for handling sensors. Tested: 1. Redfish Service Validator passed. 2. doGet method: ``` curl -k -H "X-Auth-Token: ${token}" -X GET https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/ThermalMetrics { "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/ThermalMetrics", "@odata.type": "#ThermalMetrics.v1_0_1.ThermalMetrics", "Id": "ThermalMetrics", "Name": "Thermal Metrics", "TemperatureReadingsCelsius": [ { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps0_temp0", "Reading": -131072000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps0_temp1", "Reading": -131072000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps0_temp2", "Reading": -131072000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps1_temp0", "Reading": -131072000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps1_temp1", "Reading": -131072000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps1_temp2", "Reading": -131072000.0 } ], "TemperatureReadingsCelsius@odata.count": 6 } ``` 3. Verification of DataSourceUri: ``` curl -k -H "X-Auth-Token: ${token}" -X GET https://${bmc}/redfish/v1/Chassis/chassis/Sensors/temperature_ps1_temp0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/temperature_ps1_temp0", "@odata.type": "#Sensor.v1_2_0.Sensor", "Id": "temperature_ps1_temp0", "Name": "ps1 temp0", "Reading": -131072000.0, "ReadingType": "Temperature", "ReadingUnits": "Cel", "Status": { "Health": "OK", "State": "Enabled" } } ``` 4. A bad chassis ID: ``` curl -k -H "X-Auth-Token: ${token}" -X GET https://${bmc}/redfish/v1/Chassis/chassisBAD/ThermalSubsystem/ThermalMetrics { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Chassis named 'chassisBAD' was not found.", "MessageArgs": [ "Chassis", "chassisBAD" ], "MessageId": "Base.1.18.1.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.18.1.ResourceNotFound", "message": "The requested resource of type Chassis named 'chassisBAD' was not found." } } ``` Signed-off-by: George Liu <liuxiwei@ieisystem.com> Change-Id: I6e4ed1f281fd5371c978983b6cc5666badd3752c Signed-off-by: Janet Adkins <janeta@us.ibm.com>
2024-10-09Support ProductionDate reportHieu Huynh1-0/+11
DSP0268 Redfish Data Model Specification provides ProductionDate property for various schema. phosphor-dbus-interface [1] also supports BuildDate property which we can map from FRU data, like `Board Manufacturer Date`. This adds code to support which gets the date from BuildDate property and report via Redfish. [1] https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Inventory/Decorator/Asset.interface.yaml#L16 Tested: Redfish Validator passes Signed-off-by: Hieu Huynh <hieuh@os.amperecomputing.com> Change-Id: Ie4ae564fa00218e7896f04ec61941fa92b23b912
2024-10-05dateStringToEpoch: add the additional formatHieu Huynh1-0/+13
This adds the additional format for ISO 8601, such as YYYYMMDD or YYYYMMDDThhmmssZ. Tested: Test case 1: The input ISO 8601 timestamp: 20230531T000000Z The output Epoch timestamp: 1685491200000000 Test case 2: The input ISO 8601 timestamp: 20230531 The output Epoch timestamp: 1685491200000000 Signed-off-by: Hieu Huynh <hieuh@os.amperecomputing.com> Change-Id: I23080a466b2edeecb5d8a4fb7ec0b00739454056
2024-10-03json utility: Update sort algorithmsEd Tanous1-2/+78
Modified sort utility to be able to sort on a specified key. New utility function sortJsonArrayByKey() added. Note: - Function odataObjectCmp() renamed to objectKeyCmp() - New function odataObjectCmp() created which calls objectKeyCmp() with @odata.id key specified. - Comments for odataObjectCmp() didn't match behavior for object without key. These objects are sorted as less than objects with the key. - sortJSONResponse() modified to use the new sortJsonArrayByKey(). Tested: - Added new unit tests. These tests are in addition to the existing tests. So they focus on testing comparing by different keys. The existing tests already cover the different permutations of the basic comparisons. - Redfish Service validator passes Change-Id: I949b7cb868c59a8eeda3798e6a82a1572bbc5792 Signed-off-by: Ed Tanous <etanous@nvidia.com> Signed-off-by: Janet Adkins <janeta@us.ibm.com>
2024-10-01Bump base registry to 1.19.0Jishnu CM1-3/+3
Adds GenerateSecretKeyRequired registry to the Base for MFA Change-Id: Ia690639b4bebbbd265b223bd626b0eb814103f99 Signed-off-by: Jishnu CM <jishnunambiarcm@duck.com>
2024-09-05Sensors: Add enum for chassis sub nodesJanet Adkins1-0/+37
Added ChassisSubNode enum for defining the different chassis subNode paths to retrieving sensor data. Modified path building sensor data to use the enum. Other paths were left still using the string. Specifically the paths using SensorsAsyncResp as these primarily use the strings for human readable output. Added utility functions to convert to/from enum to string value. Added unit tests for new utility functions. Tested: - Verified sensor paths before and after change had no change: - /redfish/v1/Chassis/chassis/Sensors - /redfish/v1/Chassis/chassis/Thermal - /redfish/v1/Chassis/chassis/Power - Selection of: /redfish/v1/Chassis/chassis/Sensors/<sensor> - /redfish/v1/Chassis/chassis/Sensors?\$expand=* - Redfish Validator passes Change-Id: I02bb5f3c0c49d85dbd1dff911d9f1a8467d6b1db Signed-off-by: Janet Adkins <janeta@us.ibm.com>
2024-09-04Remove IWYU pragmasEd Tanous6-42/+10
These were added as part of d5c80ad9c07b94465d8ea62d2b6f87c30cac765e: test treewide: iwyu Since then, Nan hasn't been very active on the project, and to my knowledge, since the initial run, we've never used IWYU again. clang-include-cleaner seems to work well without needing these pragmas, and is what we're using, even if it's less useful than IWYU. Remove all mention of IWYU. Tested: Code compiles. Change-Id: I06feedeeac9a114f5bdec81d59ca83223efd8aa7 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-09-04Fix includesEd Tanous1-1/+0
This commit is automatically generated by enabling clang-include-fixer. Tested: Code compiles. Change-Id: I475d7b9d43e95bbdeeaadf11905d3b2a60aa8ef3 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-08-24Make PATCH return 204 againEd Tanous1-0/+13
It was correctly pointed out that for PATCH, we cannot return 200 success without also returning the object, per Redfish. This commit partially reverts cdf25ff, to give PATCH the old (204) behavior again. Tested: Patch now returns 204 Change-Id: I8ede932a73ae064586d94c47393e4418350adb00 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-08-22Sensors: Create utility class for sensorsJanet Adkins1-0/+52
Create a separate utility class for sensors. The goal is to make these functions easily available for use outside of sensors for paths which need reference sensors. Moved splitSensorNameAndType() into new utility class. Created new utility function getSensorId(). The Id for a sensor is built from its name and type in a few different locations. These are modified to call the new function. The function has also been simplified to use std::format() to build the Id. Tested: - Checked before and after results for queries using this function: (Note: I was not able to confirm the setSensorsOverride() caller as it is only being used for redfish-allow-deprecated-power-thermal URI.) ''' - https://${bmc}/redfish/v1/Chassis/chassis/Sensors - https://${bmc}/redfish/v1/Chassis/chassis/Sensors/<str> where <str> was sensors of different types - https://${bmc}/redfish/v1/Chassis/chassis/Sensors?\$expand=* - https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans - https://${bmc}/redfish/v1/Chassis/chassis/PowerSubsystem/PowerSupplies ''' - Redfish Validator passed Change-Id: Ifa200b6e63f8e52d47f70c33d350999f5c527bbd Signed-off-by: Janet Adkins <janeta@us.ibm.com>
2024-08-17Make set properties return 200 Success not 204Ed Tanous1-2/+14
Both 200 and 204 are allowed by the Redfish specification. Table 11 states: 200 OK Success, and the action's schema definition does not contain an action response. 204 No Content: Success, and the action's schema definition does not contain an action response. While both of these are allowed, we accidentally changed behavior in the following commit: 87c4496 Move to Redfish setProperty call When we transitioned these over to the common dbus calling methods. This commit restores the old behavior of returning 200 success on actions, which some implementations are expecting. Tested: WIP. Change-Id: I02e47585acf85bd04dcb9d428ef3e39a21d9c75f Signed-off-by: Ed Tanous <ed@tanous.net>
2024-07-16Add tests for invalid datetimes in time_utilsFarah Rasheed1-0/+36
Add unit tests for dateStringToEpoch method for various invalid datetime strings and make sure that std::nullopt is returned as expected in each test case. Change-Id: I1eaa1beb471e02e7c11e575fa13bb175b48dc30d Signed-off-by: Farah Rasheed <Farah.Rasheed1@dell.com>
2024-06-18Bump base registry to 1.18.1Gunnar Mills1-2/+2
72169 points out a mistake in 1.16 which is fixed in 1.18. Let's pull 1.18.1 in. 1.18.1 is the latest. Changed 1 line in parse_registries.py and reran it. Tested: None. In the past bumping these hasn't caused problems. Change-Id: I79b135b8366d9b423f789c34802b1c0366d4e8a5 Signed-off-by: Gunnar Mills <gmills@us.ibm.com> Signed-off-by: Ed Tanous <ed@tanous.net>
2024-05-01Bring consistency to config optionsEd Tanous1-1/+1
The configuration options that exist in bmcweb are an amalgimation of CROW options, CMAKE options using #define, pre-bmcweb ifdef mechanisms and meson options using a config file. This history has led to a lot of different ways to configure code in the codebase itself, which has led to problems, and issues in consistency. ifdef options do no compile time checking of code not within the branch. This is good when you have optional dependencies, but not great when you're trying to ensure both options compile. This commit moves all internal configuration options to: 1. A namespace called bmcweb 2. A naming scheme matching the meson option. hyphens are replaced with underscores, and the option is uppercased. This consistent transform allows matching up option keys with their code counterparts, without naming changes. 3. All options are bool true = enabled, and any options with _ENABLED or _DISABLED postfixes have those postfixes removed. (note, there are still some options with disable in the name, those are left as-is) 4. All options are now constexpr booleans, without an explicit compare. To accomplish this, unfortunately an option list in config/meson.build is required, given that meson doesn't provide a way to dump all options, as is a manual entry in bmcweb_config.h.in, in addition to the meson_options. This obsoletes the map in the main meson.build, which helps some of the complexity. Now that we've done this, we have some rules that will be documented. 1. Runtime behavior changes should be added as a constexpr bool to bmcweb_config.h 2. Options that require optionally pulling in a dependency shall use an ifdef, defined in the primary meson.build. (note, there are no options that currently meet this class, but it's included for completeness.) Note, that this consolidation means that at configure time, all options are printed. This is a good thing and allows direct comparison of configs in log files. Tested: Code compiles Server boots, and shows options configured in the default build. (HTTPS, log level, etc) Change-Id: I94e79a56bcdc01755036e4e7278c7e69e25809ce Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-19Add missing headersEd Tanous1-6/+4
Most of these were found by breaking every redfish class handler into its own compile unit: When that's done, these missing headers become compile errors. We should just fix them. In addition, this allows us to enable automatic header checking in clang-tidy using misc-header-cleaner. Because the compiler can now "see" all the defines, it no longer tries to remove headers that it thinks are unused. [1] https://github.com/openbmc/bmcweb/commit/4fdee9e39e9f03122ee16a6fb251a380681f56ac Tested: Code compiles. Change-Id: Ifa27ac4a512362b7ded7cc3068648dc4aea6ad7b Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-04Allow parsing null or value classesEd Tanous1-0/+29
In Redfish schema, just about all values can be a type (string, EDM.Numeric, etc) or null. Most APIs don't allow explicitly setting null, but there are a few cases where it is useful, namely in lists, where an an empty object {} keeps the value the same, and null deletes the value from the list. Previously we handled this by unpacking as nlohmann::json, but this allowed things like [1.0, {}] to pass the check for an array of string values. We'd ideally like to reject the 1.0 at the first stage, as well as reduce the number of tiered readJson calls that we make. This commit introducess support for unpacking std::variant types, that allows unpacking a known type, or explicitly allowing null, by unpacking std::nullptr_t. Tested: Unit tests pass. Change-Id: Ic7451877c824ac743faf1951cc2b5d9f8df8019c Signed-off-by: Ed Tanous <edtanous@google.com>
2024-04-02Reduce multi-level calls of req.req membersMyung Bae1-4/+4
Several places access the members of `req` indirectly like `req.req.method()`. This can be simplified as `req.method()` . This would also make the code clearer. Tested: - Compiles - Redfish service validator passes Change-Id: Ie129564ff907cdea7ac224b1e3d80cc0dedfbd7b Signed-off-by: Myung Bae <myungbae@us.ibm.com>
2024-03-28Create Redfish specific setProperty callEd Tanous1-0/+74
There are currently 78 sdbusplus::asio::setProperty calls in redfish-core. The error handler for nearly all of them looks something like: ``` if (ec) { const sd_bus_error* dbusError = msg.get_error(); if ((dbusError != nullptr) && (dbusError->name == std::string_view( "xyz.openbmc_project.Common.Error.InvalidArgument"))) { BMCWEB_LOG_WARNING("DBUS response error: {}", ec); messages::propertyValueIncorrect(asyncResp->res, "<PropertyName>", <PropertyValue>); return; } messages::internalError(asyncResp->res); return; } messages::success(asyncResp->res); ``` In some cases there are more errors handled that translate to more error messages, but the vast majority only handle InvalidArgument. Many of these, like the ones in account_service.hpp, do the error handling in a lambda, which causes readability problems. This commit starts to make things more consistent, and easier for trivial property sets. This commit invents a setDbusProperty method in the redfish namespace that tries to handle all DBus errors in a consistent manner. Looking for input on whether this will work before changing over the other 73 calls. Overall this is less code, fewer inline lambdas, and defaults that should work for MOST use cases of calling an OpenBMC daemon, and fall back to more generic errors when calling a "normal" dbus daemon. As part of this, I've ported over several examples. Some things that might be up in the air: 1. Do we always return 204 no_content on property sets? Today there's a mix of 200, with a Base::Success message, and 204, with an empty body. 2. Do all DBus response codes map to the same error? A majority are covered by xyz.openbmc_project.Common.Error.InvalidArgument, but there are likely differences. If we allow any daemon to return any return code, does that cause compatibility problems later? Tested: ``` curl -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"HostName":"openbmc@#"}' https://192.168.7.2/redfish/v1/Managers/bmc/EthernetInterfaces/eth0 ``` Returns the appropriate error in the response Base.1.16.0.PropertyValueIncorrect Change-Id: If033a1112ba516792c9386c997d090c8f9094f3a Signed-off-by: Ed Tanous <ed@tanous.net>