health: take json_ptr instead of reference when filling status
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
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index c86adab..ab59c33 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -248,10 +248,13 @@
// be resized, as json::array uses vector underneath and we
// need references to its members that won't change
size_t count = 0;
+ // Pointer based on |asyncResp->res.jsonValue|
+ nlohmann::json::json_pointer rootPtr =
+ "/StorageControllers"_json_pointer;
for (const auto& [path, interfaceDict] : subtree)
{
auto subHealth = std::make_shared<HealthPopulate>(
- asyncResp, root[count]["Status"]);
+ asyncResp, rootPtr / count / "Status");
subHealth->inventory.emplace_back(path);
health->inventory.emplace_back(path);
health->children.emplace_back(subHealth);