summaryrefslogtreecommitdiff
path: root/redfish-core/lib/managers.hpp
AgeCommit message (Collapse)AuthorFilesLines
2023-05-11clang-format: copy latest and re-formatPatrick Williams1-14/+4
clang-format-16 has some backwards incompatible changes that require additional settings for best compatibility and re-running the formatter. Copy the latest .clang-format from the docs repository and reformat the repository. Change-Id: I75f89d2959b0f1338c20d72ad669fbdc1d720835 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-05-10managers: fix bug of searching dbus object pathPotin Lai1-2/+4
Notice a bug of patching existed object if the object name contains space or underscore. Normally dbus replace space with underscore for object path. Replacing all spaces in input name with underscore to find the correct dbus object path. Tested results: - Add new object Input JSON ``` { "Oem": { "OpenBmc": { "Fan": { "StepwiseControllers": { "Test_1": { "Direction": "Floor", "Inputs": [ "MB_U402_THERM_LOCAL" ], "NegativeHysteresis": 0.0, "PositiveHysteresis": 0.0, "Steps": [ { "Output": 0.0, "Target": 48.0 }, { "Output": 40.0, "Target": 52.0 } ], "Zones": [ { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone0" } ] } } } } } } ``` Check result from /redfish/v1/Managers/bmc ``` "Test_1": { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers/Test_1", "@odata.type": "#OemManager.StepwiseController", "Direction": "Floor", "Inputs": [ "MB U402 THERM LOCAL" ], "NegativeHysteresis": 0.0, "PositiveHysteresis": 0.0, "Steps": [ { "Output": 0.0, "Target": 48.0 }, { "Output": 40.0, "Target": 52.0 } ], "Zones": [ { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone0" } ] } ``` - Patching existed object successful Input JSON ``` { "Oem": { "OpenBmc": { "Fan": { "StepwiseControllers": { "Test_1": { "NegativeHysteresis": 0.0, "PositiveHysteresis": 5.0, } } } } } } ``` Check result from /redfish/v1/Managers/bmc ``` "Test_1": { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers/Test_1", "@odata.type": "#OemManager.StepwiseController", "Direction": "Floor", "Inputs": [ "MB U402 THERM LOCAL" ], "NegativeHysteresis": 0.0, "PositiveHysteresis": 5.0, "Steps": [ { "Output": 0.0, "Target": 48.0 }, { "Output": 40.0, "Target": 52.0 } ], "Zones": [ { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone0" } ] } ``` Signed-off-by: Potin Lai <potin.lai@quantatw.com> Change-Id: I12c78e52801bd0814ba2d928cf020e0a04214c39
2023-03-15Replace space with underscore for Dbus Object PathYaswanth Reddy M1-1/+1
Currently code search for underscore and replace space in the dbus object path , which construct invalid object path.This Patch construct proper dbus object path by replacing space with underscore. Tested: Verified that object path is created in proper format. Change-Id: Ibdf18c13ce30aa007f165e1ccfe7f68e86d50c32 Signed-off-by: Yaswanth Reddy M <yaswanthx.reddy.munukuru@intel.com>
2023-03-02Remove excessive logging in managersEd Tanous1-35/+0
nlohmann::json::dump() calls are very wordy, have a lot of code to them, and have some odd usages in exception safety (that are documented in COMMON_ERRORS.md). Therefore, we should minimize how many places we call it. This file dumped the json values to the console for logging, which no other handler does, and if we want, we have generic ways to do it. readJson these days has quite a bit of built-in logging that should cover all of these cases for debug. Remove the logging, and make managers take on the style of the other code around it. Tested: Debug logging deletes only. Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I019dd0549d65e4698e2cee863d9815ca7ddae5a2
2023-02-24Take boost error_code by referenceEd Tanous1-18/+18
By convention, we should be following boost here, and passing error_code by reference, not by value. This makes our code consistent, and removes the need for a copy in some cases. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id42ea4a90b6685a84818b87d1506c11256b3b9ae
2023-02-23Update most resources to use urlFromPiecesWilly Tu1-20/+35
Only id in event_service and account_service have not been updated due to the risk of it breaking the username/id. It will require further testing to verify. Use urlFromPieces wherever that is needed to insert a variable in the URI. Don't use urlFromPieces when it is hardcoded values. This allow us to control all resource URIs that is dynamically added and to sync with the current recommanded method for `@odata.id`. The goal is to have a common place to manage the url created from dbus-paths in order to manage/update it easily when needed. Tested: RedfishValidtor Passed for all resource including the sensors with the fragments. Change-Id: I95cdfaaee58fc7f21c95f5944e1e5c813b3215f2 Signed-off-by: Willy Tu <wltu@google.com> Signed-off-by: Ed Tanous <edtanous@google.com>
2023-02-16Revert "Implement Manager/ServiceRootUptime"Ed Tanous1-44/+0
This reverts commit ee61a619da7f180a3148317d569d2dabd1cd9832. This feature was tested against an old version of schemas, and upstream DMTF seems to have changed the definition in the meantime. This wasn't caught because of the same test failure as yesterday. Mea Culpa Change-Id: I0be095f5dea0f036927202f367542275abc0ebe3 Signed-off-by: Ed Tanous <edtanous@google.com>
2023-02-15Implement Manager/ServiceRootUptimeEd Tanous1-0/+44
This property was added in Redfish 2022.2 to denote how long this service has been up and available. This implementation opts to go to systemd to get the bmcweb service uptime rather than track it through internal process state, given that systemd already has an API that tracks the bmcweb uptime, and bmcweb attempts to keep as little state as possible. Given that we already have helper functions that give durations in milliseconds precision, this patchset opts to keep the millisecond granularity, rather than dropping to microsecond precision of the systemd API. There are no use cases that would require microsecond precision, so this patchset opts for lower complexity. Tested: Redfish service validator passes. GET /redfish/v1/Managers/bmc Returns a ServiceRootUptime property. Value matches systemctl status bmcweb. systemctl restart bmcweb, causes counter to reset. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iae7e805f3f7f5f26745476eaeaecb63bda16a957
2023-01-24Refactor GetSubTree methodGeorge Liu1-32/+28
Since the GetSubTree method has been implemented in dbus_utility and this commit is to integrate all the places where the GetSubTree method is called, and use the method in dbus_utility uniformly. Tested: Redfish Validator Passed Signed-off-by: George Liu <liuxiwei@inspur.com> Change-Id: If3852b487d74e7cd8f123e0efffbd4affe92743c
2023-01-23Break out set time function and unit test itEd Tanous1-37/+20
This function is something that's easily unit tested. Do it. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8d664c77ec4b3a9886128597449c5f9c041b86b3
2023-01-18Fix a boatload of #includesEd Tanous1-0/+1
Most of these missing includes were found by running clang-tidy on all files, including headers. The existing scripts just run clang-tidy on source files, which doesn't catch most of these. Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ic741fbb2cc9e5e92955fd5a1b778a482830e80e8
2022-12-22Fix cppcheck errorEd Tanous1-29/+15
cppcheck comments that this can be const. Unfortunately, this looks like a false positive, where cppcheck cannot see through the std::replace template. Tested: This is in the set pid loop handler that doesn't have any good tests with it. Code compiles, and only inspection is possible at this time. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I21eaadcc37b2f3993e63b39d471cbf118d88119a
2022-11-29managers: fix interface patch and delete of pid objectPotin Lai1-3/+13
Only set createNewObject to true when corresponding interface not found in the object. Tested on Bletchley: - Add new StepwiseController called SWTest Body in JSON format ``` { "Oem": { "OpenBmc": { "Fan": { "StepwiseControllers": { "SWTest": { "Direction": "Floor", "Inputs": [ "MB_U402_THERM_LOCAL" ], "NegativeHysteresis": 1.0, "PositiveHysteresis": 2.0, "Steps": [ { "Output": 0.0, "Target": 48.0 }, { "Output": 15.0, "Target": 49.0 } ], "Zones": [ { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone0" } ] } } } } } } ``` Checking object from dbus ``` root@bletchley:~# busctl introspect xyz.openbmc_project.EntityManager \ > /xyz/openbmc_project/inventory/system/chassis/Bletchley_Chassis/SWTest \ > xyz.openbmc_project.Configuration.Stepwise NAME TYPE SIGNATURE RESULT/VALUE FLAGS .Delete method - - - .Class property s "Floor" emits-change writable .Inputs property as 1 "MB U402 THERM LOCAL" emits-change writable .Name property s "SWTest" emits-change writable .NegativeHysteresis property d 1 emits-change writable .Output property ad 2 0 15 emits-change writable .PositiveHysteresis property d 2 emits-change writable .Reading property ad 2 48 49 emits-change writable .Type property s "Stepwise" emits-change writable .Zones property as 1 "Zone0" emits-change writable ``` - Patch SWTest properties Body in JSON format ``` { "Oem": { "OpenBmc": { "Fan": { "StepwiseControllers": { "SWTest": { "NegativeHysteresis": 3.0, "PositiveHysteresis": 4.0 } } } } } } ``` Checking object from dbus ``` root@bletchley:~# busctl introspect xyz.openbmc_project.EntityManager \ > /xyz/openbmc_project/inventory/system/chassis/Bletchley_Chassis/SWTest \ > xyz.openbmc_project.Configuration.Stepwise NAME TYPE SIGNATURE RESULT/VALUE FLAGS .Delete method - - - .Class property s "Floor" emits-change writable .Inputs property as 1 "MB U402 THERM LOCAL" emits-change writable .Name property s "SWTest" emits-change writable .NegativeHysteresis property d 3 emits-change writable .Output property ad 2 0 15 emits-change writable .PositiveHysteresis property d 4 emits-change writable .Reading property ad 2 48 49 emits-change writable .Type property s "Stepwise" emits-change writable .Zones property as 1 "Zone0" emits-change writable ``` - Delete SWTest object Body in JSON format ``` { "Oem": { "OpenBmc": { "Fan": { "StepwiseControllers": { "SWTest": null } } } } } ``` Object deleted from dbus ``` root@bletchley:~# busctl introspect xyz.openbmc_project.EntityManager \ > /xyz/openbmc_project/inventory/system/chassis/Bletchley_Chassis/SWTest \ > xyz.openbmc_project.Configuration.Stepwise Failed to introspect object /xyz/openbmc_project/inventory/system/chassis/Bletchley_Chassis/SWTest of service xyz.openbmc_project.EntityManager: Unknown object '/xyz/openbmc_project/inventory/system/chassis/Bletchley_Chassis/SWTest'. ``` Signed-off-by: Potin Lai <potin.lai@quantatw.com> Change-Id: I482e942ee3c76dca17af522765d8b3aa9dc8678b
2022-09-28treewide: change EM's ObjectManager pathNan Zhou1-1/+2
EntityManager moves its ObjectManager in commit [1], this patch is to change accordingly. Please see [1] for why we made that change. [1] https://gerrit.openbmc.org/c/openbmc/entity-manager/+/57279 Tested: code compiles. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Idf5657463d54022f53d12e860483d06b5c5c7ccd
2022-09-12Remove nlohmann brace initializationEd Tanous1-7/+8
There's a few last places (outside of tests) where we still use nlohmann brace initialization. Per the transforms we've been doing, move these to constructing the objects explicitly, using operator[], nlohmann::object_t and nlohmann::array_t. Theses were found by manual inspection grepping for all uses of nlohmann::json. This is done to reduce binary size and reduce the number of intermediate objects being constructed. This commit saves a trivial amount of size (~4KB, Half a percent of total) and in addition but makes our construction consistent. Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7478479a9fdc41b254eef325002d413c1fb411a0
2022-09-09Fix thrown exceptionEd Tanous1-11/+30
The newest version of clang detects this as an exception thrown in a destructor. To solve this, this commit moves the returned data to a struct, and loads it backs into io::service::post(). Tested: Not sure I know how to test this, and this code was checked in prior to tested statements being required. Change-Id: Ieef32e43d89043fe99fbbf46cceb794b08db8b13 Signed-off-by: Ed Tanous <edtanous@google.com>
2022-09-02Fix regression in pid settingEd Tanous1-28/+27
It looks like one of the patchset merge conflicts got rebased poorly (ie commented out). In the meantime, a number of these structures have gone from map->vector, so modify the algorithm to account for that. Tested: 1. Redfish validator - passed with this change. 2. Verified from Redfish by patching "StepwiseControllers" sensors. Signed-off-by: Ed Tanous <edtanous@google.com> Signed-off-by: Jayaprakash Mutyala <mutyalax.jayaprakash@intel.com> Change-Id: I89d36f1b0b3699b6bf07a17af029e5a2504c85de
2022-08-15Move time utils to be in one placeEd Tanous1-2/+3
We've accumulated several time utility functions in the http classes. Time isn't a core HTTP primitive, so http is not where those functions below. This commit moves all the time functions from the crow::utility namespace into the redfish::time_utils namespace, as well as moves the unit tests. No code changes where made to the individual functions, with the exception of changing the namespace on the unit tests. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8493375f60aea31899c84ae703e0f71a17dbdb73
2022-08-13used sdbusplus::unpackPropertiesNoThrow part 2Krzysztof Grobelny1-85/+78
used sdbusplus::unpackPropertiesNoThrow in managers.hpp, also replaced all usages of "GetAll" with sdbusplus::asio::getAllProperties bmcweb size: 2677080 -> 2672984 (-4096) compressed size: 1128633 -> 1128611 (-22) Tested: Performed get on: - /redfish/v1/Managers - /redfish/v1/Managers/bmc Get result before and after the change was the same Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com> Change-Id: If1a0227eda106361ed9dda74a5f13ada3ef07d69
2022-08-10Add redfish-oem-manager-fan-data optionGunnar Mills1-0/+7
IBM doesn't use the Redfish OEM fan data in OemManager. IBM does not use phosphor-pid-control instead using phosphor-fan-presence and such. This is data such as PidControllers, StepwiseControllers, FanZones, FanControllers, and Profile. This has been in bmcweb since Oct 2018 so defaulting this flag to enabled to not break anyone. Why we want a flag: 1) Have observed 500 errors with getting the thermalMode. "Jan 24 16:34:57 rain534 bmcweb[435]: (2022-01-24 16:34:57) [ERROR "managers.hpp":1196] GetPIDValues: Can't get thermalModeIface /xyz/openbmc_project/control/thermal/0" 2) This Redfish OEM fan data includes PATCHing. Commit turning this off in meta-ibm: https://gerrit.openbmc.org/c/openbmc/openbmc/+/56327 Tested: With this flag enabled and disabled. Manager resource looks as expected. Before on a dummy PATCH to this: curl -k -X PATCH https://$bmc/redfish/v1/Managers/bmc -d \ '{"Oem":{"OpenBmc":{"Fan":{"Profile":"Acoustic"}}}}' { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The request failed due to an internal service... With this change and the meta-ibm change (instead see a PropertyUnknown) curl -k -X PATCH https://$bmc/redfish/v1/Managers/bmc -d \ '{"Oem":{"OpenBmc":{"Fan":{"Profile" : "Acoustic"} }}}' { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The property %1 is not in the list of valid... "MessageArgs": [ "Oem" ], "MessageId": "Base.1.13.0.PropertyUnknown", PATCHed the DateTime with this enabled. Change-Id: I374292ca2798e096b18d49df5bbc7a93c7f1c400 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
2022-07-19Replace boost with std replaceEd Tanous1-7/+10
Per our coding standard, we should be using std namespace methods for these things when both a boost one and a std one exist. Update the code. Tested: Code compiles. I don't think we have great examples of the usages of these APIs. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I35cfa25c4f8038ba8d9e3dbe337b5b3d72c64144
2022-07-15Manager: add ManagerDiagnosticData handlerSui Chen1-7/+13
This change adds a link in the Manager for all BMCs to an empty ManagerDiagnosticData resource and a minimum ManagerDiagnosticData handler. This service is backed by phosphor-health-monitor (PHM), which is enabled by default through the "obmc-apps" package group. If PHM is disabled, the resource will be empty. $ curl http://${bmc}:10080/redfish/v1/Managers/bmc/ManagerDiagnosticData { "@odata.id": "/redfish/v1/Managers/bmc/ManagerDiagnosticData", "@odata.type": "#ManagerDiagnosticData.v1_0_0.ManagerDiagnosticData", "Id": "ManagerDiagnosticData", "Name": "Manager Diagnostic Data" } Also ran the Redfish Service Validator to make sure no new errors are introduced with the introduction of ManagerDiagnosticData. Signed-off-by: Sui Chen <suichen@google.com> Change-Id: Iba242bc3b6ebec851dbd26e149d5c92c19a7992e
2022-07-12Fix const correctness issuesEd Tanous1-8/+8
cppcheck correctly notes that a lot of variables in the new code can be const. Make most of them const. Tested: WIP Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8f37b6353fd707923f533e1d61c5b5419282bf23
2022-06-30Require explicit decorator on one arg constructorsEd Tanous1-1/+2
We essentially follow this rule already, not relying on implicit operators, although there are a number of cases where in theory we could've implicitly constructed an object. This commit enables the clang-tidy check. Tested: Code compiles, passes clang-tidy. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ia428463313b075c69614fdb326e8c5c094e7adde
2022-06-28Fix shadowed variable issuesEd Tanous1-7/+7
This patchset is the conclusion of a multi-year effort to try to fix shadowed variable names. Variables seem to be shadowed all over, and in most places they exist, there's a "code smell" of things that aren't doing what the author intended. This commit attempts to clean up these in several ways by: 1. Renaming variables where appropriate. 2. Preferring to refer to member variables directly when operating within a class 3. Rearranging code so that pass through variables are handled in the calling scope, rather than passing them through. These patterns are applied throughout the codebase, to the point where -Wshadow can be enabled in meson.build. Tested: Code compiles, unit tests pass. Still need to run redfish service validator. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: If703398c2282f9e096ca2694fd94515de36a098b
2022-06-19sw_util: Rename all Firmware to Software wherever possibleWilly Tu1-2/+2
Rename to Software so we can reuse it for software inventory. This make is more consistent to the SoftwareVersion dbus interface that is used. Change-Id: I97fb10fccf744a6d6d4cba57f970759431bf4744 Signed-off-by: Willy Tu <wltu@google.com>
2022-06-15Expose AsyncResp shared_ptr when handling responseCarson Labrado1-6/+6
For Redfish Aggregation, we need a common point to check the D-Bus for satellite configs. If they are available then we perform the aggregation operations. The functions in query.hpp are used by all endpoints making them the logical location. The aggregation code requires a shared_ptr to the AsyncResp so these functions need to be able to supply that. This patch is broken out of a future patch for routing Redfish Aggregation requests https://gerrit.openbmc.org/c/openbmc/bmcweb/+/53310 The follow commands can be used to perform most of the replacements: find . -type f | xargs sed -i 's/setUpRedfishRoute(app, req, asyncResp->res/setUpRedfishRoute(app, req, asyncResp/g' find . -type f | xargs sed -i 's/setUpRedfishRouteWithDelegation(app, req, asyncResp->res/setUpRedfishRouteWithDelegation(app, req, asyncResp/g' Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: I4f4f9f22cdcfb14a3bd94b9a8f3d64aae34e57bc
2022-06-01Try to fix the lambda formatting issueEd Tanous1-1031/+976
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-13Remove brace initialization of json objectsEd Tanous1-48/+72
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-04-06Add setUpRedfishRoute to all nodes in redfishEd Tanous1-67/+94
For better or worse, the series ahead of this is making use of setUpRedfishRoute to do the common "redfish specified" things that need to be done for a connection, like header checking, filtering, and other things. In the current model, where BMCWEB_ROUTE is a common function for all HTTP routes, this means we need to propagate this injection call into the whole tree ahead of the requests being handled. In a perfect world, we would invent something like a REDFISH_ROUTE macro, but because macros are discouraged, the routes take a variadic template of parameters, and each call to the route has a .privileges() call in the middle, there's no good way to effect this change in a less costly manner. This was messaged both in the prior reviews, and on discord sourcing improvements on this pattern, to which none arose. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id29cc799e214edad41e48fc7ce6eed0521f90ecb
2022-03-22Consitently use dbus::utility typesEd Tanous1-53/+42
This saves about 4k on the binary size Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I9546227a19c691b1aecb80e80307889548c0293f
2022-03-07Don't rely on operator << for object loggingEd Tanous1-2/+2
In the upcoming fmt patch, we remove the use of streams, and a number of our logging statements are relying on them. This commit changes them to no longer rely on operator>> or operator+ to build their strings. This alone isn't very useful, but in the context of the next patch makes the automation able to do a complete conversion of all log statements automatically. Tested: enabled logging on local and saw log statements print to console Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I0e5dc2cf015c6924037e38d547535eda8175a6a1
2022-02-28Move error messages to string_viewEd Tanous1-4/+3
using std::string_view on these lets us call them in more contexts, and allows us to inline some previously more complex code. In general, for APIs like this, std::string_view should be preferred as it gives more flexibility in calling conventions. Tested: curl --insecure "https://localhost:18080/redfish/v1/AccountService/Roles/foobar" ✔ { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Role named 'foobar' was not found.", "MessageArgs": [ "Role", "foobar" ], "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 Role named 'foobar' was not found." } } This is the same response as previously. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8ee17120c42d2a13677648c3395aa4f9ec2bd51a
2022-02-28Add url type safety to message registryEd Tanous1-8/+20
There are a number of places where we use message registry messages incorrectly. This patchset attempts to fix them, and invoke some type safety when they're used such that they're more obvious to use. Namely, it changes a number of the message registry methods to accept a boost::urls::url_view for its argument instead of a const std::string&. This forces the calling code to correctly encode a URL to use the method, which should make it obvious that it's not for an ID, a property name, or anything else. In the course of doing this, several places were found to be using the first argument incorrectly. Tested: curl --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/Chassis/foobar Returns: { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type #Chassis.v1_16_0.Chassis named foobar was not found.", "MessageArgs": [ "#Chassis.v1_16_0.Chassis", "foobar" ], "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 #Chassis.v1_16_0.Chassis named foobar was not found." } Identically to previously. Also tested with IDs that contained % encoded characters, like foobar%10, which gave the same result. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Icbb3bce5d190a260610087c9ef35e7becc5a50c7
2022-02-25json_utils: Add support jsonRead Patch/ActionWilly Tu1-6/+6
Added support for readJson for Patch and Action. The only difference is that Patch does not allow empty json input while Action does. Action with empty input will use the default value based on the implementation and return 200 OK response code. readJsonPatch will replace the existing readJson and be used for path requests. It will not allow empty json input and all requested keys are required in the json input. readJsonAction will be used for Action requests where it is possible for all of the properties to be optional and allow empty request. The optional properties are determined by the requested values type. All current Action readJson are replaced with readJsonAction. It does not change the existing behavior since it needs `std::optional`. This will have to be updated later as we define the default behavior. Tested: Added unit tests and readJsonAction allows empty empty json object. No Change to Redfish Tree. Change-Id: Ia5e1f81695c528a20f1dc985aee19c920d8adaea Signed-off-by: Willy Tu <wltu@google.com>
2022-02-23managers: populate the name correctly for PIDWilly Tu1-1/+1
The name was never set properly and is empty. All of the information are saved to the same location. Tested: Redfish Service Validator has issue from before ``` 6 exceptionPropCheck errors in /redfish/v1/Managers/bmc 2 exceptionPropCheck errors in /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone_2 *** /redfish/v1/Managers/bmc ERROR - This complex object FanMode should be a dictionary or None, but it's of type <class 'str'>... ERROR - This complex object ZoneIndex should be a dictionary or None, but it's of type <class 'float'>... ERROR - This complex object FanMode should be a dictionary or None, but it's of type <class 'str'>... ERROR - This complex object ZoneIndex should be a dictionary or None, but it's of type <class 'float'>... ERROR - This complex object FanMode should be a dictionary or None, but it's of type <class 'str'>... ERROR - This complex object ZoneIndex should be a dictionary or None, but it's of type <class 'float'>... INFO - Type (Manager.v1_11_0.Manager), GET SUCCESS (time: 0:00:00.226048) INFO - Attempt 1 of /redfish/v1/UpdateService/FirmwareInventory/3199f4dc INFO - Response Time for GET to /redfish/v1/UpdateService/FirmwareInventory/3199f4dc: 0.01309930405113846 seconds. INFO - Attempt 1 of /redfish/v1/Chassis/AgoraV2 INFO - Response Time for GET to /redfish/v1/Chassis/AgoraV2: 0.0709426780231297 seconds. INFO - Attempt 1 of /redfish/v1/Managers/bmc/EthernetInterfaces INFO - Response Time for GET to /redfish/v1/Managers/bmc/EthernetInterfaces: 0.02456553210504353 seconds. INFO - Attempt 1 of /redfish/v1/Managers/bmc/NetworkProtocol INFO - Response Time for GET to /redfish/v1/Managers/bmc/NetworkProtocol: 0.12236760894302279 seconds. INFO - Attempt 1 of /redfish/v1/Managers/bmc/LogServices INFO - Response Time for GET to /redfish/v1/Managers/bmc/LogServices: 0.0062645250000059605 seconds. WARNING - SerialConsole: The given property is deprecated by revision: This property has been deprecated in favor of the SerialConsole property in the ComputerSystem resource. ERROR - FanMode: Could not finish check on this property ('str' object has no attribute 'get') ERROR - ZoneIndex: Could not finish check on this property ('float' object is not iterable) ERROR - FanMode: Could not finish check on this property ('str' object has no attribute 'get') ERROR - ZoneIndex: Could not finish check on this property ('float' object is not iterable) ERROR - FanMode: Could not finish check on this property ('str' object has no attribute 'get') ERROR - ZoneIndex: Could not finish check on this property ('float' object is not iterable) INFO - FAIL... INFO - ``` Before, ``` "FanControllers": { "": { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers/", "@odata.type": "#OemManager.FanController", "FFGainCoefficient": 0.006, "FFOffCoefficient": 0.0, "ICoefficient": 0.0, "ILimitMax": 0.0, "ILimitMin": 0.0, "Inputs": [ "fan0_tach", "fan1_tach" ], "OutLimitMax": 100.0, "OutLimitMin": 25.0, "Outputs": [ "fan0_pwm", "fan1_pwm" ], "PCoefficient": 0.0, "SlewNeg": 0.0, "SlewPos": 0.0, "Zones": [ { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone_0" } ] }, "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers", "@odata.type": "#OemManager.FanControllers" }, ``` After, ``` "FanControllers": { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers", "@odata.type": "#OemManager.FanControllers", "pwm_1": { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers/pwm_1", "@odata.type": "#OemManager.FanController", "FFGainCoefficient": 0.006, "FFOffCoefficient": 0.0, "ICoefficient": 0.0, "ILimitMax": 0.0, "ILimitMin": 0.0, "Inputs": [ "fan0_tach", "fan1_tach" ], "OutLimitMax": 100.0, "OutLimitMin": 25.0, "Outputs": [ "fan0_pwm", "fan1_pwm" ], "PCoefficient": 0.0, "SlewNeg": 0.0, "SlewPos": 0.0, "Zones": [ { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Zone_0" } ] }, ... ``` Change-Id: Ia487feaaca060d53a173d1fe83a80472fe0f331d Signed-off-by: Willy Tu <wltu@google.com>
2022-02-15Enable readability-implicit-bool-conversion checksEd Tanous1-3/+3
These checks ensure that we're not implicitly converting ints or pointers into bools, which makes the code easier to read. Tested: Ran series through redfish service validator. No changes observed. UUID failing in Qemu both before and after. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I1ca0be980d136bd4e5474341f4fd62f2f6bbdbae
2022-02-09Enable readability-avoid-const-params-in-declsEd Tanous1-2/+2
This check involves explicitly declaring variables const when they're declared auto, which helps in readability, and makes it more clear that the variables are const. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I71198ea03850384a389a56ad26f2c4a48c75b148
2022-01-28Enable readability-container-size-empty testsEd Tanous1-3/+3
This one is a little trivial, but it does help in readability. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I5366d4eec8af2f781b3bad804131ae2eb806e3aa
2022-01-20managers: Fix incorrect property name for "Class"Lei YU1-1/+1
The commit 711ac7a9 introduces a bug in redfish-core/lib/managers.hpp that it uses the incorrect property name when getting "Class"'s value. This results in HW CI error that is related to /redfish/v1/Managers/bmc, and manually access this URI results in 500 InternalError. Tested: Verify the /redfish/v1/Managers/bmc URI is OK and the HW CI passes. Signed-off-by: Lei YU <yulei.sh@bytedance.com> Change-Id: Ieb8f98b6cfee6aa22a0320d2410a9b96c536c080
2022-01-12Enable cppcoreguidelines-special-member-functions checksEd Tanous1-0/+11
Part of enforcing cpp core guidelines involves explicitly including all constructors required on a non-trivial class. We were missing quite a few. In all cases, the copy/move/and operator= methods are simply deleted. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie8d6e8bf2bc311fa21a9ae48b0d61ee5c1940999
2022-01-12Enable init checkerEd Tanous1-2/+2
clang-tidy added cppcoreguidelines-init-variables as a check, which is something we already enforce to some extent, but getting CI to enforce it will help reviews move faster. Tested: Code compiles. Noop changes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7e10950de617b1d3262265572b1703f2e60b69d0
2022-01-12enable bugprone exception escape checkEd Tanous1-1/+14
clang-13 includes new checks, and finds some issues. The first is that the boost::vector constructor can possibly throw, so replace the underlying flat_map container with std::vector instead. The others are places where we could possibly throw in destructors, which would be bad. Ideally we wouldn't use the destructor pattern, but that would be non-trivial to clean up at this point, so just catch the exception, and log it. At the same time, catch exceptions thrown to main and log them. Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I77b86eaa2fc79e43d1ca044c78ca3b0ce0a7c38c
2022-01-10Enforce const correctnessEd Tanous1-2/+2
For all async calls, we should be consistently capturing non trivial objects by const reference. This corrects bmcweb to be consistent and capture errors by const value, and objects by const reference. Tested: Code compiles. Trivial changes. This saves about 300 bytes on our compressed binary size. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib3e0b6edef9803a1c480701556949488406305d4
2022-01-10Consistently use ManagedObjectTypeEd Tanous1-62/+85
Some subsystems seem to have invented their own typedefs for this stuff, move to using the one typedef in dbus::utility so we're consistent, and we reduce our templates. Tested: code compiles This saves a negligible amount (104 bytes compressed) on our binary size. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I952ea1f960aa703808d0ac80f35dc24cdd8d5027
2021-12-28Using sdbusplus::asio::getPropertyJonathan Doman1-45/+20
It simplifies a lot of code and after changing sdbusplus implementation slightly reduces binary size if used together with: https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49467 * Uncompressed size: 3033148 -> 3012164, -20984 B * gzip compressed size: 1220586 -> 1214625, -5961 B Tested: - Redfish validator output is the same before and after the change Change-Id: Ibe3227d3f4230de2363ba3d9396e51130c8240a5 Signed-off-by: Jonathan Doman <jonathan.doman@intel.com> Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
2021-12-28Move to common variantEd Tanous1-19/+18
This saves approximately 34kB in the compressed binary size of bmcweb due to reduced template instantiations. This amounts to a 2.5% reduction in the overall size. Note, there were a few places where we broke const-correctness in the form of pulling a non-const reference out of a const variant. This new variant now requires const correctness, so some consts are added where required. Tested: Code compiles. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I6a60c8881c1268627eedb4ffddf16689dc5f6ed2
2021-12-11fix the year 2038 problem in getDateTimeNan Zhou1-3/+2
The existing codes cast uint64_t into time_t which is int32_t in most 32-bit systems. It results overflow if the timestamp is larger than INT_MAX. time_t will be 64 bits in future releases of glibc. See https://sourceware.org/bugzilla/show_bug.cgi?id=28182. This change workarounds the year 2038 problem via boost's ptime. std::chrono doesn't help since it is still 32 bits. Tested on QEMU. Example output for certificate: { "Name": "HTTPS Certificate", "Subject": null, "ValidNotAfter": "2106-01-28T20:40:31Z", "ValidNotBefore": "2106-02-06T18:28:16Z" } Previously, the format is like "1969-12-31T12:00:00+00:00". Note that the ending "+00:00" is the time zone, not ms. Tested the schema on QEMU. No new Redfish Service Validator errors. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8ef0bee3d724184d96253c23f3919447828d3f82
2021-11-19Update clang-formatGeorge Liu1-46/+34
refer: https://github.com/openbmc/docs/blob/master/style/cpp/.clang-format `Don't break long string literals` Tested: built bmcweb successfully and RedfishValidator Passed. Signed-off-by: George Liu <liuxiwei@inspur.com> Change-Id: Ib58f7c942fd3838592e043c57e0b6ffcdc3d963b
2021-07-08Automate PrivilegeRegistry to codeEd Tanous1-6/+7
This commit attempts to automate the creation of our privileges structures from the redfish privilege registry. It accomplishes this by updating parse_registries.py to also pull down the privilege registry from DMTF. The script then generates privilege_registry.hpp, which include const defines for all the privilege registry entries in the same format that the Privileges struct accepts. This allows new clients to simply reference the variable to these privilege structures, instead of having to manually (ie error pronely) put the privileges in themselves. This commit updates all the routes. For the moment, override and OEM schemas are not considered. Today we don't have any OEM-specific Redfish routes, so the existing ones inherit their parents schema. Overrides have other issues, and are already incorrect as Redfish defines them. Binary size remains unchanged after this patchset. Tested: Ran redfish service validator Ran test case from f9a6708c4c6490257e2eb6a8c04458f500902476 to ensure that the new privileges constructor didn't cause us to regress the brace construction initializer. Checked binary size with: gzip -c $BBPATH/tmp/work/s7106-openbmc-linux-gnueabi/obmc-phosphor-image/1.0-r0/rootfs/usr/bin/bmcweb | wc -c 1244048 (tested on previous patchset) Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ideede3d5b39d50bffe7fe78a0848bdbc22ac387f