summaryrefslogtreecommitdiff
path: root/redfish-core
AgeCommit message (Collapse)AuthorFilesLines
2022-06-02Make code compile on clang againEd Tanous3-5/+5
The usual updates to make code compile on clang again. Extra semicolons that have snuck in, missing inline and static definitions. Tested: Code compiles on clang. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id7f889de98cafaa89471d75ed3e3bb97ab3855cd
2022-06-01Expand query: reimplement the way to do subqueriesNan Zhou2-79/+114
For any expand query, the current implementation does all queries in a single MultiAsyncResp, where the code sends a bunch of requests without Query parameters. This makes it impossible to invoke efficient expand handlers, since efficent handlers will only be invoked when a query has $expand in its parameters. (Delegation only happens when the query contains query parameters) To solve it, in this commit, we proposed to send a bunch of requests **WITH** Query parameters in MultiAsyncResp. This makes "/redfish/v1/Chassis/chassis?expand=.($levels=2)" be able to invoke efficient expand handlers that we developed for sensors, which existing implementation can't do. This decreases latency by nearly 100 times (the improvement that efficient sensor expand handler provides) on real hardware which contains 5+ chassis and totally 220+ sensors. This commit aligns with future $select support well, since the recursive queries can add $select as part of the query parameters. With this commit, though we create multiple MultiAsyncResp objects memory doesn't increase significantly; part of the reason is that we are not copying Query anymore in MultiAsyncResp. No out-of-memory issues are found when 4 threads are querying expand=levels=6 at the service root on a real large hardware which contains 2+ sockets, 5+ chassis, 220+ sensors, 30+ DIMMs, etc. Tested: 1. On real hardware, /redfish/v1/Chassis?$expand=.(level=3) is giving the correct result and invokes efficient sensor Expand handler 2. stress test ``` for i in {1..4}; do echo "thread $i" wget -qO- 'http://localhost:18080/redfish/v1?$expand=*($levels=6)' > "/tmp/$i.log" & done for i in {1..1000}; do top -b -n 1 | grep bmcweb >> /tmp/bmcweb_ori.log sleep 1 done ``` Results ``` 25878 2856 root R 194m 20% 1 38% /tmp/bmcweb_after 19005 2856 root R 215m 22% 1 36% /tmp/bmcweb_ori ``` Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I0e661db0263f56dd0cab66047a0a5d4fff31b69a
2022-06-01SensorCollection: use inline functions+bind_frontNan Zhou1-39/+42
This commit changes the `/redfish/v1/Chassis/<str>/Sensors/` route to take std::bind_front instead of lambdas. We can clearly see the indent levels decrease. It increases the readability. Tested: 1. trivial change; code compiles. 2. tested on my local mock environment; URL:/redfish/v1/Chassis/fake_chassis/Sensors/ Response: { "@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors", "@odata.type": "#SensorCollection.SensorCollection", "Description": "Collection of Sensors for this Chassis", "Members": [ { "@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor0" }, { "@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor1" }, { "@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor5" }, { "@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor6" } ], "Members@odata.count": 4, "Name": "Sensors" } 3. Service Validator Passes *** /redfish/v1/Chassis/fake_chassis/Sensors Type (SensorCollection.SensorCollection), GET SUCCESS (time: 0:00:00.002345) Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor0 Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor0: 0.006815780187025666 seconds. Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor1 Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor1: 0.004200570052489638 seconds. Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor5 Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor5: 0.004602659028023481 seconds. Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor6 Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor6: 0.00432420102879405 seconds. PASS Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ibdebd9b5427db5b42d5047367ae8548fa981ddea
2022-06-01sensors: use inline functions + bind_frontNan Zhou1-77/+80
This commit changes the `/redfish/v1/Chassis/<str>/Sensors/<str>/` route to take std::bind_front instead of lambdas. We can clearly see the indent levels decrease. It increases the readability. Tested: 1. trivial change; code compiles. 2. tested on my local mock environment; URL: /redfish/v1/Chassis/fake_chassis/Sensors/sensor0 Response: { "@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor0", "@odata.type": "#Sensor.v1_0_0.Sensor", "Id": "sensor0", "Name": "sensor0", "Reading": 0.0, "ReadingRangeMax": null, "ReadingRangeMin": null, "ReadingType": "Current", "ReadingUnits": "A", "Status": { "Health": "OK", "State": "Enabled" } } 3. Service Validator Pass *** /redfish/v1/Chassis/fake_chassis/Sensors/sensor0 Type (Sensor.v1_0_0.Sensor), GET SUCCESS (time: 0:00:00.007105) PASS Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ic60521a937a8b18d317390fc75d792c58f56e3e6
2022-06-01Move redfish/v1 instantiationEd Tanous2-1/+5
Make /redfish/v1 get instantiated in the same place as the other redfish routes, and not in main(). Tested: curl -vvvv --insecure --user root:0penBmc https://192.168.7.2/redfish returns the same value as previously. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Icb93954c00a4cf41708f1b323ddbd83e61146e5d
2022-06-01Try to fix the lambda formatting issueEd Tanous38-12632/+11949
clang-tidy has a setting, LambdaBodyIndentation, which it says: "For callback-heavy code, it may improve readability to have the signature indented two levels and to use OuterScope." bmcweb is very callback heavy code. Try to enable it and see if that improves things. There are many cases where the length of a lambda call will change, and reindent the entire lambda function. This is really bad for code reviews, as it's difficult to see the lines changed. This commit should resolve it. This does have the downside of reindenting a lot of functions, which is unfortunate, but probably worth it in the long run. All changes except for the .clang-format file were made by the robot. Tested: Code compiles, whitespace changes only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
2022-05-31meson option: make the insecure-disable-auth macro more accurateNan Zhou1-6/+6
The "auth" term is overloaded in meson option and macros. This commit changes the macro from BMCWEB_INSECURE_DISABLE_AUTHENTICATION to BMCWEB_INSECURE_DISABLE_AUTHX, given that if "insecure-disable-auth" is enabled, both authentication and authorization are disabled. Tested: 1. set 'insecure-disable-auth=enabled', no authz nor authn is performed, no crash on AccountService as well. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Iddca1f866d16346bcc2017338fa6f077cb89cef9
2022-05-27memory: set @odata attributes only if the object is foundNan Zhou1-5/+5
The existing code returns a JSON payload with @odata attributes even if it is a 404 not found. This commit corrects that by moving @odata after the object is found. Tested: 1. before ``` { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm5", "@odata.type": "#Memory.v1_11_0.Memory", "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Memory named 'dimm5' was not found.", "MessageArgs": [ "Memory", "dimm5" ], "MessageId": "Base.1.11.0.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.11.0.ResourceNotFound", "message": "The requested resource of type Memory named 'dimm5' was not found." } } ``` after ``` { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Memory named 'dimm5' was not found.", "MessageArgs": [ "Memory", "dimm5" ], "MessageId": "Base.1.11.0.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.11.0.ResourceNotFound", "message": "The requested resource of type Memory named 'dimm5' was not found." } } ``` 2. Service Validator on MemoryResource passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Id0f912015b0ecf25cacb22e919ebe88708187677
2022-05-26health: take json_ptr instead of reference when filling statusNan Zhou3-7/+18
The existing codes populates the health status on the |AsyncResponse| or a given JSON reference. This doesn't work if we want to populates status on an array of objects, since the array can be resized which changes the address of each object. This commit changed the contructor to take a JSON pointer instead. |HealthPopulate| will populates status on |AsyncResponse->res.jsonValue|[json_ptr]. If the point can't be resolved in the |jsonValue|, |HealthPopulate| populates nothing. Fixed all places where the old reference based constructor is used. This commit is extremely useful when implementing efficient level-1 expand handler on ResourceCollections. It also prevents issues on reference lifecycles. Tested: 1. It builds 2. Tested DIMM/System/Storage health on real hardware, works as expected 3. Tested on Redfish Service Validator, no new failures on health properties. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I305515522af50b48be92a3f4689d8166f3bc0cc0
2022-05-26memory: move Partition codes from callbacks into separate functionsNan Zhou1-61/+65
Another change to move codes from callbacks to functions in the memory resource. It is a bit cleaner to have separate functions rather than keep codes in the callback, as callback normally have deeper indent. The main reason is that this helps code review of later changes that make Expand at MemoryCollection efficient. Tested: 1. on my mockup environment; added partition data into the fake dimm; URL /redfish/v1/Systems/system/Memory/dimm0 ``` { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm0", "@odata.type": "#Memory.v1_11_0.Memory", "AllowedSpeedsMHz": [], "BaseModuleType": "RDIMM", "BusWidthBits": 0, "CapacityMiB": 1024, "DataWidthBits": 0, "ErrorCorrection": "NoECC", "FirmwareRevision": "0", "Id": "dimm0", "Name": "DIMM Slot", "OperatingSpeedMhz": 0, "RankCount": 0, "Regions": [ { "MemoryClassification": "", "OffsetMiB": 0, "PassphraseEnabled": false, "RegionId": "", "SizeMiB": 1024 } ], "Status": { "Health": "OK", "HealthRollup": "OK", "State": "Enabled" } } ``` 2. No new Redfish Validator failures on MemoryCollection on real hardware. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I27b251ff32bab026d6fa919abf7b6dcf2905e4a3
2022-05-25Remove messages::operationFailed from processorEd Tanous1-7/+0
A file write error being returned from dbus is by definition, an internal error that the user can do nothing about, so it should be returning internal error (ie 500) to the user, rather than OperationFailed. OperationFailed refers to aggregation proxy use cases, so its use here, while an understandable mistake, because dbus is arguably a "proxy", is incorrect, and should be fixed. Tested: Code compiles, no good way to test error cases. Inspection only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I01aae6bcf377d019ff6e868309f87959281a2156
2022-05-25Change operationFailed to return 502Ed Tanous1-1/+1
Redfish base registry for operation failed says: "Indicates that one of the internal operations necessary to complete the request failed. Examples of this are when an internal service provider is unable to complete the request, such as in aggregation or RDE." In terms of return codes, this translates to 502, Bad Gateway, given that we're talking about proxy behavior here. There is currently one usage of messages::operationFailed, which arguably should've used internalErrror, and will be fixed in the next patchset. Tested: Code compiles. No (correct) users. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iff20e04d4f297b9f6595039f76321d0927f86c4d
2022-05-25ethernet: Remove PATCH VLANId supportJiaqing Zhao1-14/+11
phosphor-networkd does not support changing VLAN ID of an existing VLAN interface. Though the DBus property can be updated, the change never takes effect. This patch disallows PATCH VLANId requests. Tested: PATCH {"VLANId": 3} /redfish/v1/Managers/bmc/EthernetInterfaces/eth0 /VLANs/eth0_1 returns PropertyNotWritable error. Change-Id: Ice43064de761d63aa3cfde8019e5d4db138fcf02 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
2022-05-24ethernet: Use std::optional<uint32> for VLAN IDJiaqing Zhao1-7/+7
According to Redfish EthernetInterface and VLanNetworkInterface schema, VLANId is "The ID for this VLAN", meaning that each interface can only have at most one VLAN ID. (Though EthernetInterface schema says "If this interface supports more than one VLAN, the VLAN collection link shall be present", the collection link is depracated in 1.7.0 and the spec suggests "using individual EthernetInterface resources to show VLAN information".) OpenBMC network stack implementation uses linux's virtual interface to represent a VLAN (named as <interface-name>.<vlan-id>, e.g. eth0.100). In both design and implementation, an interface can have either zero or one VLAN ID. This patch replaces the std::vector for VLAN ID with std::optional to match the design. It has no impact on the Redfish response. Tested: Verified GET /redfish/v1/Managers/bmc/EthernetInterfaces/eth0 can list all VLANs on eth0, and GET, PATCH and DELETE /redfish/v1/Managers/bmc /EthernetInterfaces/eth0/VLANs/eth0_1 works. Change-Id: Iab05e859d76639b2e60546cd5549efd34effafb7 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
2022-05-24Fix segmentation fault when deleting the sessionswukaihua-fii-na1-1/+2
Fix the segmentation fault caused by deleting the sessions via Redfish. Do not compare the username when deleting the sessions with no-auth. Tested: Delete the session via Redfish and bmcweb not crashed Signed-off-by: wukaihua-fii-na <eason.kh.wu@fii-na.com> Change-Id: I7f5268e7243a22ba5010ba5b8b4c82f19b8b4f20
2022-05-23bmcweb: Remove hardcoded HTTP verbs and headersCarson Labrado1-2/+3
Modifies HttpClient so that the HTTP verb and headers can be set for each individual message sent. Right now those fields are set when a connection is first created and then reused by each message sent using that connection. Tested: Launched two Event Listener servers that created 6 and 2 subscriptions. Sending a test event resulted in the servers receiving 6 requests and 2 requests, respectively. Change-Id: I8d7e2d54385bc2c403498293820adb584bff8b57 Signed-off-by: Carson Labrado <clabrado@google.com> Signed-off-by: Ed Tanous <edtanous@google.com>
2022-05-23bmcweb: Fetch Satellite Config from D-BusCarson Labrado1-0/+228
Adds a RedfishAggregator class which is able to pull configuration information from D-Bus for Satellite BMCs. These BMCs will be aggregated by Redfish Aggregation. Also added is a new compiler option which will be used to enable Redfish Aggregation. This patch only allows configurations with unencrypted and unauthenticated satellite BMC communication. Support for encryption and authentication willneed to be added in future patches. Note that this patch does not actually use the config information after it has been fetched. That functionality will be added in future patches. Tested: I made this example config information available on D-Bus busctl introspect xyz.openbmc_project.EntityManager \ /xyz/openbmc_project/inventory/system/board/SatelliteBMC/aggregated0 \ xyz.openbmc_project.Configuration.SatelliteController NAME TYPE SIGNATURE RESULT/VALUE FLAGS .AuthType property s "None" emits-change .Hostname property s "127.0.0.1" emits-change .Name property s "aggregated0" emits-change .Port property t 443 emits-change .Type property s "SatelliteController" emits-change That information was picked up by the changes in this CL: [DEBUG "redfish_aggregator.hpp":80] Found Satellite Controller at /xyz/openbmc_project/inventory/system/board/SatelliteBMC/aggregated0 [DEBUG "redfish_aggregator.hpp":209] Added satellite config aggregated0 at http://127.0.0.1:443 [DEBUG "redfish_aggregator.hpp":52] Redfish Aggregation enabled with 1 satellite BMCs [DEBUG "redfish_aggregator.hpp":21] There were 1 satellite configs found at startup Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: Ib5eee2c93aeb209157191055975c127759d73627
2022-05-20Add RootOfTrustCollection and RootOfTrust under Google service root.Vidya Satyamsetti2-3/+100
These are Google only resources powered by Hoth DBus interface. The ComponentsProtected links is hardcoded for now. But it will be queried from DBus and interpreted accordingly in the future. TEST: $curl -u root:0penBmc -X GET http://[::1]:$PORT/google/v1/RootOfTrustCollection { "@odata.id": "/google/v1/RootOfTrustCollection", "@odata.type": "#RootOfTrustCollection.RootOfTrustCollection", "Members": [ { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth" } ], "Members@odata.count": 1 } $ curl -u root:0penBmc -X GET http://[::1]:$PORT/google/v1/RootOfTrustCollection/Hoth { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth", "@odata.type": "#RootOfTrust.v1_0_0.RootOfTrust", "Actions": { "#RootOfTrust.SendCommand": { "target": "/google/v1/RootOfTrustCollection/Hoth/Actions/RootOfTrust.SendCommand" } }, "Id": "Hoth", "Location": { "PartLocation": { "ServiceLabel": "Hoth", "Locationtype": "Embedded" } }, "Name": "RootOfTrust-Hoth", "Status": { "State": "Enabled" } $ curl -u root:0penBmc -X POST -d @req.json -H "Content-Type: application/json" http://[::1]:$PORT/google/v1/RootOfTrustCollection/Hoth/Actions/RootOfTrust.SendCommand { "CommandResponse": "033B0000" } Signed-off-by: Vidya Satyamsetti <satyamsetti@google.com> Change-Id: If64612468bb89e6d9251d848697608b7daf37339
2022-05-19memory: move long code blocks in callbacks into separate functionsNan Zhou1-267/+257
It is a bit cleaner to have separate functions rather than keep codes in the callback, as callback normally have deeper indent. The main reason is that this helps code review of later changes that make Expand at MemoryCollection efficient. Tested: 1. Tested on my mock environment, ``` URI: /redfish/v1/Systems/system/Memory/dimm0 { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm0", "@odata.type": "#Memory.v1_11_0.Memory", "AllowedSpeedsMHz": [], "BaseModuleType": "RDIMM", "BusWidthBits": 0, "CapacityMiB": 1024, "DataWidthBits": 0, "ErrorCorrection": "NoECC", "FirmwareRevision": "0", "Id": "dimm0", "Name": "DIMM Slot", "OperatingSpeedMhz": 0, "RankCount": 0, "Status": { "Health": "OK", "HealthRollup": "OK", "State": "Enabled" } } ``` 2. No new Redfish Validator failures on MemoryCollection on real hardware. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I7693388049aeffa6ebd285b958e5ca6622e5d3b6
2022-05-19Change query param errors to be 400 instead of 403Ed Tanous1-2/+2
Any query param errors from the base registry being sent imply that the user-provided parameters were bad, which should return bad request, not forbidden. This is in line with the spec. Luckily, the only usage of these parameters as of now is from within the query params support model, so changing it shouldn't cause any backward compatibility issues, and because these are meant for "bad request" type messages, it's unlikely it would even be able to effect clients. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I13a4601d1236d9eaac6bbf5fb25e0f1b28c04a21
2022-05-17Fake out allow header in UpdateServiceEd Tanous1-0/+9
In an attempt to smooth out the transition on changing the URI for /redfish/v1/UpdateService:HttpPushUri, this patch modifies the allow header on the /redfish/v1/UpdateService to return the "wrong" value, and remove POST from the list of allowed verbs. While this is technically incorrect, this field is new, so there can't be any users relying on it, and if they were to use it, they would ideally code to HttpPushUri as the spec would suggest. Tested: Redfish-service-validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ida3bdb772646253af5376bc8e0e13db285048b93
2022-05-17Change UpdateService POST URIEd Tanous1-1/+26
As d01e32c3786f2fbbb70c9724a87cf979b4a06232 found, the Redfish specification doesn't allow a direct POST handler on UpdateService. Ideally clients would be following the specification, and relying on the HttpPushUri as the spec requires, so we could simply make this change. Unfortunately, a quick polling of the community shows that a significant number of instances, including the Redfish cheat sheet, and the robot tests, have hardcoded the non-spec behavior. This commit is present to give a trap door to allow easier porting of this behavior to the specification. The old uri is left, and now returns a WARNING http field, indicating that the uri is deprecated, in case clients have ignored the Redfish specification. Tested: Ran firmware update instructions from https://gerrit.openbmc-project.xyz/c/openbmc/docs/+/53664 Test gave the same result as previously. /redfish/v1/UpdateService returns an HttpPushUri that matches the above. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7427f461d151c9460160b0b9b366dca5aefc49d5
2022-05-17Move update service post to free methodEd Tanous1-23/+26
Refactor the update service post method in a similar way to how we've done elsewhere. This is done to enable a refactor later. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iaa16b5f07fbdbbd1ffc244d5f3e94aa5efa39ad0
2022-05-16Fix regression in ComputerSystemEd Tanous1-2/+5
Despite the pseudo non-plural name "Links.Chassis", the Redfish schema states that Chassis is an array of chassis, not a singular chassis. While odd, we should obey the specification. This resolves the regression introduced by 1476687de Tested: Code compiles, code inspection looks correct. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I4d6d0554865e412137c44562d173a6efe3f88f4a
2022-05-16log_services: fix wrong AdditionalDataURIPotin Lai1-2/+2
fix wrong AdditionalDataURI of EventLog entries Tested: [Before] $ curl -s -u root:0penBmc -k https://10.10.11.203/redfish/v1/Systems/system/LogServices/EventLog/Entries/60 |\ > python -c 'import sys, json; print(json.load(sys.stdin)["AdditionalDataURI"])' /redfish/v1/Systems/system/LogServices/EventLog/attachment/60 $ curl -s -u root:0penBmc -k https://10.10.11.203/redfish/v1/Systems/system/LogServices/EventLog/attachment/60 Not Found [After] $ curl -s -u root:0penBmc -k https://10.10.11.203/redfish/v1/Systems/system/LogServices/EventLog/Entries/60 |\ > python -c 'import sys, json; print(json.load(sys.stdin)["AdditionalDataURI"])' /redfish/v1/Systems/system/LogServices/EventLog/Entries/60/attachment $ curl -s -u root:0penBmc -k https://10.10.11.203/redfish/v1/Systems/system/LogServices/EventLog/Entries/60/attachment BQAAADwAAAAGAAAAEeFXk4ABAAAtAAAAAAAAAHh5ei5vcGVuYm1jX3Byb2plY3QuTG9nZ2luZy5TRUwuRXJyb3IuQ3JlYXRlZAYAAAAAAAAACwAAAAAAAABFVkVOVF9ESVI9MQ8AAAAAAAAAR0VORVJBVE9SX0lEPTMyDQAAAAAAAABSRUNPUkRfVFlQRT0yEgAAAAAAAABTRU5TT1JfREFUQT01MjAyQzE6AAAAAAAAAFNFTlNPUl9QQVRIPS94eXovb3BlbmJtY19wcm9qZWN0L3NlbnNvcnMvdm9sdGFnZS9QMTJWX0ZBTjEIAAAAAAAAAF9QSUQ9MzAxAAAAAAAAAAAAIAAAAAAAAAAyLjEyLjAtZGV2LTEwOTQtZ2MzNDk4NzlmNi1kaXJ0eRHhV5OAAQAAAAAAAAAAAAAAAAAAAAAAAA== Signed-off-by: Potin Lai <potin.lai@quantatw.com> Change-Id: I859638a942a0afcb57f68d6a6613d5c3498ab3be
2022-05-16Fix regression in brace initializationEd Tanous1-1/+1
1476687de introduced a regression because of a simple copy/paste transcription error. Unfortunately, dump logs aren't enabled on a majority of systems, so this typo wasn't caught in the tested statement for that commit, but was only caught in later CI. Tested: Code compiles, code inspection (regression resolution) Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I98297546be3ed624e21461edbe8c5781287787db
2022-05-16Return OData.Version with responsesEd Tanous1-0/+2
The Redfish specification section 8.1 lists header values that should be returned from responses. It lists OData.Version: 4.0 as required in this same section. Implement this to the specification. Tested: Redfish protocol validator RESP_HEADERS_ODATA_VERSION test now passes. curl --vvv https://$bmc/redfish/v1 shows Odata.Version header set in response. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id02ec218299524905fbd91cb161bfe727a51fc65
2022-05-13Move /redfish to free methodsEd Tanous1-8/+11
Similar to the refactors done elsewhere, move the /redfish route to a free method. Tested: curl /redfish/v1 returns the same payload as previously. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Icd7668e8e3779926508aa901959b2ca6d079c8f0
2022-05-13Add setUpRedfishRoute to /redfish/ routeEd Tanous1-2/+6
Because this file originally wasn't in redfish-core when we handled this site-wide change, it didn't get the additional redfish decorators added to it. This commit adds it. Tested: curl /redfish returns as before. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I89a01a8fd75ab081d031de34ced6c9ae9c0ca75a
2022-05-13LogService: Sort dump entries collection by IdClaire Weinan1-0/+6
Ordering by ID (represented internally as the last part of the D-Bus object path, after the rightmost slash) is done for human readability, but please note that Redfish clients should not be written in a way that assumes a particular ordering of entries in a collection. Without this change, entries are presented in the collection in whatever order entries are returned by the D-Bus method GetManagedObjects(), called in getDumpEntryCollection(). The effect of this change is that entries are presented in chronological order (by ID) with the earliest entry appearing first. Testing: 1. Prerequisite: Fixed createDump() locally, similar to https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/38954 2. Created 12 BMC dump entries by repeatedly calling CollectDiagnosticData: curl -k -H "X-Auth-Token: $token" -X POST http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData -d '{"DiagnosticDataType":"Manager", "OEMDiagnosticDataType":"BMC"}' 3. Retrieved BMC dump entries collection and verified that entries were sorted by ID (1,2,3,4,5,6,7,8,9,10,11,12): curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries Signed-off-by: Claire Weinan <cweinan@google.com> Change-Id: I99f96dd6679163cea443353ad0e4c8c750cd4330
2022-05-13Remove brace initialization of json objectsEd Tanous26-872/+999
Brace initialization of json objects, while quite interesting from an academic sense, are very difficult for people to grok, and lead to inconsistencies. This patchset aims to remove a majority of them in lieu of operator[]. Interestingly, this saves about 1% of the binary size of bmcweb. This also has an added benefit that as a design pattern, we're never constructing a new object, then moving it into place, we're always adding to the existing object, which in the future _could_ make things like OEM schemas or properties easier, as there's no case where we're completely replacing the response object. Tested: Ran redfish service validator. No new failures. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iae409b0a40ddd3ae6112cb2d52c6f6ab388595fe
2022-05-12Move redfish v1 into redfish-coreEd Tanous1-0/+21
This file has existed for a long time, and predates redfish-core, so it was put in an inopportune place. Move the code to where it should be, in lib. Tested: Code compiles. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I422c27563a5e0f2a5debb2b1d4713aa8db0fe331
2022-05-11Refactor HttpClient ClassCarson Labrado1-29/+26
Refactors HttpClient with the following changes: - Convert class to singleton - Replace circular buffers with devectors - Sending queued requests and closing connections handled within their own callback - Add connection pooling (max size 4) - HttpClient supports multiple connections to multiple clients - Retry policies can be set for specific use cases Also modifies its use in the Subscription class to be compatible with the refactored code. It is assumed that a BMC will be able to handle 4 parallel connections and thus the max pool size is set as 4. The max number of queued messages was left unchanged at 50. Eventually we may want to allow tuning of these limits to boost performance. That would come in a future patch. Tested: Launched two Event Listener servers that created 6 and 2 subscriptions. Sending a test event created a connection pool for each server. 4 and 2 connections were added to each pool, respectively and were used to send the test request. For the first pool the 2 extra requests were placed into a queue until connections became available. After a request completed, its associated connection was used to send the next request in the queue. Resending the test event caused those prior connections to be reused instead of new connections being added to the pools. Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: Iba72b3e342cdc05d1fb972e2e9856763a0a1b3c5
2022-05-10Implement $top and $skipEd Tanous2-1/+114
$top and $skip are parameters for controlling the responses of collections, to limit their size, per the Redfish specification section 7.4. $skip=integer "Applies to resource collections. Returns a subset of the members in a resource collection, or an empty set of members if the $skip value is greater than or equal to the member count. This paging query parameter defines the number of members in the resource collection to skip." $top=<integer> "Applies to resource collections. Defines the number of members to show in the response. Minimum value is 0 , though a value of 0 returns an empty set of members." This commit implements them within the resource query. Tested: curl --insecure --user root:0penBmc https://localhost:18080/redfish/v1/Registries\?\$top\=1 Returns 1 value. Walking through values of 1-5 (there are 4 registries currently) returns the appropriate sizes of collection (with 5 returning 4 entries). curl --insecure --user root:0penBmc https://localhost:18080/redfish/v1/Registries\?\$skip\=0 Returns the collection. $skip values of 0-5 return descending number of results. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ied8a8f8338f119173509fb4b7ba2bd4a6c49cae8
2022-05-06system: Handle PATCH request with multi-depth readJsonJiaqing Zhao1-67/+48
This reduces readJson calls and makes the code more readable, and saves ~164 bytes of compressed image size. Tested: Verified PATCH /redfish/v1/Systems/system is handled as expected. Change-Id: I90dd5e0d4b0b055ee370288ad159d26e5bb40281 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
2022-05-06query: expand: fix a bug in inLinksNan Zhou2-5/+14
Old codes handle links incorrectly; when links appear before some keys, old codes don't expand these keys. Tested: 1. On real hardware, Expand with links are working correctly. 2. Unit tests. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I028b55579d833f23120987a24cef4442fdd5800d
2022-05-06memory: correct type of MemorySizeInKBNan Zhou1-2/+2
This is needed for this code to work on both 32 and 64 bits system. According to the interface, https://github.com/openbmc/phosphor-dbus-interfaces/blob/388b58f9a878f45b8ec243152cac5eb44ec90ced/yaml/xyz/openbmc_project/Inventory/Item/Dimm.interface.yaml#L9, MemorySizeInKB is of type size_t. Tested: On real hardware, the memory resource is working as expected. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ie81d2610c245a08a22c3ea891495f34cc0bdc075
2022-05-04Fix bmcweb crash problem when no-authJunLin Chen1-1/+38
This change is similiar as https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/49465 After insecure-disable-auth=enabled. it is not needed to do login and establish session before request. GET/PATCH /redfish/v1/AccountService/Accounts/<accountname>. (no matter account exist or not) It won't get any status code and cause the bmcweb service crashed. Solutions: Add #ifndef BMCWEB_INSECURE_DISABLE_AUTHENTICATION and [[maybe_unused]] const crow::Request& req Test: GET / PATCH with authless https://<bmcip>/redfish/v1/AccountService/Accounts/TestAccount Return 200 { "@odata.id": "/redfish/v1/AccountService/Accounts/TestAccount", "@odata.type": "#ManagerAccount.v1_4_0.ManagerAccount", "AccountTypes": [ "Redfish" ], "Description": "User Account", "Enabled": true, "Id": "TestAccount", "Links": { "Role": { "@odata.id": "/redfish/v1/AccountService/Roles/Administrator" } }, "Locked": false, "Locked@Redfish.AllowableValues": [ "false" ], "Name": "User Account", "Password": null, "PasswordChangeRequired": false, "RoleId": "Administrator", "UserName": "TestAccount" } GET nonexistent account https://<bmcip>/redfish/v1/AccountService/Accounts/TestAccountsss { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type ManagerAccount named TestAccountsss was not found.", "MessageArgs": [ "ManagerAccount", "TestAccountsss" ], "MessageId": "Base.1.8.1.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.8.1.ResourceNotFound", "message": "The requested resource of type ManagerAccount named TestAccountsss was not found." } } Signed-off-by: JunLin Chen <Jun-Lin.Chen@quantatw.com> Change-Id: Ic00020ac07950347973b54d49dacd44c4d4571b7 Signed-off-by: Tony Lee <tony.lee@quantatw.com> Signed-off-by: Ed Tanous <edtanous@google.com>
2022-05-02Add OpenBMC.1.0.ServiceStarted to registrySui Chen1-2/+11
This change adds OpenBMC.1.0.ServiceStarted to the registry, and adds a test case for getMessage and getMessageFromRegistry. The getMessageFromRegistry function is moved to a .cpp file so it can be called from the test. Unit test passes. When tested in QEMU: With https://gerrit.openbmc-project.xyz/c/openbmc/openbmc/+/52591 applied, restarting a service generates a corresponding log entry. bmc# systemctl restart rsyslogd host$ wget -q -O - \ http://localhost:10080/redfish/v1/Systems/system/LogServices/EventLog/Entries/ ... { "@odata.id": /redfish/v1/Systems/system/LogServices/EventLog/Entries/47441_1", "@odata.type": "#LogEntry.v1_8_0.LogEntry", "Created": "1970-01-01T13:10:41+00:00", "EntryType": "Event", "Id": "47441_1", "Message": "Service rsyslog.service has started successfully.", "MessageArgs": [ "rsyslog.service" ], "MessageId": "OpenBMC.1.0.ServiceStarted", "Name": "System Event Log Entry", "Severity": "OK" }, Signed-off-by: Sui Chen <suichen@google.com> Change-Id: Iea6fa6e3ea8591853169043c1c04f5a7cf00b2f6
2022-05-02storage: Call function only if interfaces existWilly Tu1-4/+24
Avoid making the dbus call if the interface does not exist and is expected to error out to reduce the number of dbus calls. Tested: Redfish Validator passed for Drives ``` $ wget -qO- \ http://localhost:80/redfish/v1/Systems/system/Storage/1/Drives/drive { "@odata.id": "/redfish/v1/Systems/system/Storage/1/Drives/drive", "@odata.type": "#Drive.v1_7_0.Drive", "Id": "warthog", "Links": { "Chassis": { "@odata.id": "/redfish/v1/Chassis/chassis" } }, "Manufacturer": "XXX", "MediaType": "SSD", "Model": "XXX", "Name": "drive", "PartNumber": "xxxxxxxxxxxxx", "Protocol": "SATA", "SerialNumber": "123456", "Status": { "Health": "OK", "HealthRollup": "OK", "State": "Enabled" } } ``` Change-Id: Ic83c8ee5a49f75b71d443781faf8b65d8fab31b6 Signed-off-by: Willy Tu <wltu@google.com>
2022-04-28Make log services use parameter delegationEd Tanous3-104/+195
The commit prior to this one added support for delegation of $expand and $only query param types; This commit adds support for delegation of top and skip (which we already have a few handlers for) and moves them to the new style. Note, this makes top and skip query params NOT below the insecure-enable-redfish-query. top and skip have existed for a while, and are unlikely to have security issues, as they're relatively simple transforms. Tested: curl --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/Managers/bmc/LogServices/Journal/Entries\?\$top\=3\&\$skip\=0 With varying $top between 1-5 and $skip between 0-5 gave the expected number of log results. Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ia213a5e929c40579825eaf251e4b9159bc84c802
2022-04-28Make insecure-enable-redfish-query more specificEd Tanous3-8/+11
insecure-enable-redfish-query is really only intended to protect the user from things that might run the system out of resources, like expand, or complex filter queries (ie queries that might pop the stack). This commit message moves the location where the parameters are enabled/disabled into the parser itself, such that some parameters (like top and skip in the next commit) can be executed outside of this option flag. Because of moving the expand support deeper in the call stack, some unit tests now need to be aware of whether or not expand is supported in the configuration. Tested: Enabled query option through local.conf with EXTRA_OEMESON:pn-bmcweb:append = "-Dinsecure-enable-redfish-query='enabled'" Then did: curl --insecure --user root:0penBmc https://192.168.7.2/redfish/v1\?\$expand\=\* Query expanded as expected; set insecure-enable-redfish-query='disabled' and observed that the same curl query returned QueryParameterValueFormatError, which is expected. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I24fbc2c9f64628d6457dd117b61ff22b276b0682
2022-04-27Fix Ethernet privilegesAbhishek Patel1-9/+3
Post method: 1) /redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/ ConfigureComponents -> ConfigureManager Patch method: 1) /redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/ ConfigureComponents -> ConfigureManager 2) /redfish/v1/Managers/bmc/EthernetInterfaces/<str>/ ConfigureComponents -> ConfigureManager (SubordinateOverrides) Delete method: 1) /redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/ ConfigureComponents -> ConfigureManager This change allows only Admin user to post, patch, and delete on VLAN Network Interface Collection and restrict Operator user. Same for the EthernetInterfaces patch method. Tested: Ran curl test with admin and operator privileged user for all methods (post, patch, and delete). one test failing. Error: curl -k -H "X-Auth-Token: $bmc_token" -X PATCH -d '{"VLANId" :30 , "VLANEnable" : true}' https://${BMC_IP}/redfish/v1/Managers/bmc/EthernetInterfaces/ eth0/VLANs/eth0_50 This command is unable to update the VLANId value. instead, it deletes VLAN Email sent to openbmc list: https://lists.ozlabs.org/pipermail/openbmc/2021-August/027232.html Signed-off-by: Abhishek Patel <Abhishek.Patel@ibm.com> Change-Id: I4101c429db6fa788909982b66445b191ccacaec7
2022-04-27Fix certificate_service privilegesAbhishek Patel1-3/+1
Post method: 1) /redfish/v1/CertificateService/Actions/ CertificateService.GenerateCSR/ ConfigureComponents-> ConfigureManager This change allows only Admin users to Generate CSR Certificate and restrict Operator user. Tested: Ran curl Post requests with Admin and Operator privileged users Get output as expected. Email sent to openbmc list: https://lists.ozlabs.org/pipermail/openbmc/2021-August/027232.html Signed-off-by: Abhishek Patel <Abhishek.Patel@ibm.com> Change-Id: I46d505357cfc55a31911e75e8bd9948a0db90555
2022-04-27Simplify sensor path lookupsEd Tanous3-59/+52
This commit drops 8k from the binary size. Tested: SensorCollection returns sensor values as expected, same as previously Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ife1dc40ff6745585ac6bc3f99cd5e6c4811baa56
2022-04-26system: Fix incorrect WatchdogTimer PATCH handlerJiaqing Zhao1-1/+1
Changes the incorrect WatchdogTimer property name to HostWatchdogTimer in PATCH /redfish/v1/Systems/system handler to match the Redfish spec. Tested: Updating HostWatchdogTimer with PATCH request is handled properly. Change-Id: Ic7c9c72e3fd43fb738f4fc21eb39e335aa8d1bcd Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
2022-04-25Sensors: Add humidity hierarchyGunnar Mills1-1/+7
As stated in PDI humidity is a valid hierarchy. https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Sensor/Value.interface.yaml From https://redfish.dmtf.org/schemas/v1/Sensor.v1_5_0.json: Humidity is a valid ReadingType and Humidity ReadingUnits shall be %. This follows the following Redfish mockup: https://redfish.dmtf.org/redfish/mockups/v1/1156 This is not under BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM due to not being part of the old thermal or power resources. Tested: Validator passes. See a Humidity sensor in the Sensor colleciton: { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/Relative_Humidity", "@odata.type": "#Sensor.v1_0_0.Sensor", "Id": "Relative_Humidity", "Name": "Relative Humidity", "Reading": 61.935424802658005, "ReadingRangeMax": 100.0, "ReadingRangeMin": 0.0, "ReadingType": "Humidity", "ReadingUnits": "%", ... Signed-off-by: Gunnar Mills <gmills@us.ibm.com> Change-Id: Ib1f52b0b0e3d8c4bfec8c4389c811fdb8b9d887a
2022-04-19Remove regex uses in event service and consolidateEd Tanous2-41/+15
As the patch at https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/50994 can attest, parsing urls with a regex is error prone. We should avoid it where possible, and we have boost::urls that implements a full, correct, and unit tested parser. Ideally, eventually this helper function would devolve into just the parse_uri, and setting defaults portion, and we could rely on the boost::urls::url class to pass into things like http_client. As a side note, because boost url implements port as a proper type-safe uint16, some interfaces that previously accepted port by std::string& needed to be modified, and is included in this patch. Also, once moved, the branch on the ifdef for HTTP push support was failing a clang-tidy validation. This is a known limitation of using ifdefs for our code, and something we've solved with the header file, so move the http push enabler to the header file. Also note that given this reorganization, two EXPECT statements are added to the unit tests for user input behaviors that the old code previously did not handle properly. Tested: Unit tests passing Ran Redfish-Event-Listener, saw subscription create properly: Subcription is successful for https://192.168.7.2, /redfish/v1/EventService/Subscriptions/2197426973 Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ia4127c6cbcde6002fe8a50348792024d1d615e8f
2022-04-19Implement odata annotations ignoringEd Tanous2-2/+44
From the quoted section of the spec in the patchset, we should be ignoring odata annotations on PATCH requests. This commit implements a preliminary loop through the json object, and removes the odata items before processing begins. Tested: curl -vvvv --insecure --user root:0penBmc -X PATCH -d '{"@odata.etag": "my_etag"}' https://192.168.7.2/redfish/v1/AccountService/Accounts/root returns: Base.1.11.0.NoOperation Redfish protocol validator now passes the REQ_PATCH_ODATA_PROPS test. Included unit tests passing. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I62be75342681d147b8536fd122bbc793eeaa3788
2022-04-15ethernet: Fix naming conventionsJiaqing Zhao2-88/+87
Some variable names in ethernet.hpp does not match naming conventions, fix'em all. Tested: Only variable name changes, build pass. Change-Id: If275a77364e5ed827a5088342f44548274b059e1 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>