bmcweb: Fix the missing Members section when cpu count is 0
There is a corner case in Processor efficient expand response,
which causes the Members field to be missing when the system has
0 cpus.
Tested:
Verfied that the response has members section when system has no cpus
```
wget -qO- 'http://localhost:80/redfish/v1/Systems/system/Processors?$expand=.($levels=1)'
{
"@odata.id": "/redfish/v1/Systems/system/Processors",
"@odata.type": "#ProcessorCollection.ProcessorCollection",
"Members": [],
"Members@odata.count": 0,
"Name": "Processor Collection"
}
Also verified that the normal case (where cpus are present) is not
affected.
```
Google-Bug-Id: 245990552
Google-Bug-Id: 276975902
Change-Id: Id4169bff9b526bad79230ce3907e46c3c9bc3074
Signed-off-by: Nikhil Namjoshi <nikhilnamjoshi@google.com>
diff --git a/recipes-phosphor/interfaces/bmcweb/0018-Processor-Implement-Efficient-expand.patch b/recipes-phosphor/interfaces/bmcweb/0018-Processor-Implement-Efficient-expand.patch
index 0b8943b..ecfa2fb 100644
--- a/recipes-phosphor/interfaces/bmcweb/0018-Processor-Implement-Efficient-expand.patch
+++ b/recipes-phosphor/interfaces/bmcweb/0018-Processor-Implement-Efficient-expand.patch
@@ -1,7 +1,7 @@
-From f76254bfe368f149d320614c2356f406ea039617 Mon Sep 17 00:00:00 2001
+From 1d3c4f5a27c40d8a25d2a813721113fe0ea42360 Mon Sep 17 00:00:00 2001
From: Nikhil Namjoshi <nikhilnamjoshi@google.com>
Date: Mon, 22 Aug 2022 16:59:17 +0000
-Subject: [PATCH 01/21] Processor : Implement Efficient expand
+Subject: [PATCH] Processor : Implement Efficient expand
With the addition of thread resources under Processor
(/redfish/v1/Systems/system/Processor), the
@@ -149,12 +149,14 @@
Change-Id: Id6f5a63a96e5edf88dcfd35a03d2d11ffd107f9a
Signed-off-by: Nikhil Namjoshi <nikhilnamjoshi@google.com>
+
+%% original patch: 0018-Processor-Implement-Efficient-expand.patch
---
- redfish-core/lib/processor.hpp | 474 +++++++++++++++++++++++++++++++--
- 1 file changed, 457 insertions(+), 17 deletions(-)
+ redfish-core/lib/processor.hpp | 482 +++++++++++++++++++++++++++++++--
+ 1 file changed, 465 insertions(+), 17 deletions(-)
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
-index 35cec3f7..9c7aac93 100644
+index 35cec3f7..5e3338e2 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -37,10 +37,29 @@
@@ -278,7 +280,7 @@
return;
}
// Object not found
-@@ -1463,6 +1508,386 @@ inline void
+@@ -1463,6 +1508,394 @@ inline void
cpuPath.c_str());
}
@@ -632,6 +634,15 @@
+ cpus.push_back(cpuId);
+ }
+
++ // If no cpus found, return
++ if (cpus.size() == 0)
++ {
++ BMCWEB_LOG_WARNING << "D-Bus CPU count was somehow empty";
++ aResp->res.jsonValue["Members@odata.count"] = 0;
++ aResp->res.jsonValue["Members"] = nlohmann::json::array();
++ return;
++ }
++
+ // Get numerically sorted list of cpu IDs
+ std::sort(cpus.begin(), cpus.end(), AlphanumLess<std::string>());
+
@@ -645,7 +656,6 @@
+ (cpuNameToSubtreeRespMap[cpu]).second;
+ getProcessorData(aResp, cpuMemberPtr, expandLevel - 1, cpu,
+ objectPath, serviceMap);
-+
+ cpuMemberCount++;
+ }
+
@@ -665,7 +675,7 @@
/**
* Request all the properties for the given D-Bus object and fill out the
* related entries in the Redfish OperatingConfig response.
-@@ -1923,7 +2348,12 @@ inline void requestRoutesProcessorCollection(App& app)
+@@ -1923,7 +2356,12 @@ inline void requestRoutesProcessorCollection(App& app)
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName) {
@@ -679,7 +689,7 @@
{
return;
}
-@@ -1945,11 +2375,21 @@ inline void requestRoutesProcessorCollection(App& app)
+@@ -1945,11 +2383,21 @@ inline void requestRoutesProcessorCollection(App& app)
asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Systems/system/Processors";
@@ -703,7 +713,7 @@
}
inline void requestRoutesProcessor(App& app)
-@@ -1983,7 +2423,7 @@ inline void requestRoutesProcessor(App& app)
+@@ -1983,7 +2431,7 @@ inline void requestRoutesProcessor(App& app)
getProcessorObject(asyncResp, processorId,
std::bind_front(getProcessorData, asyncResp,
@@ -713,5 +723,5 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
--
-2.39.2.722.g9855ee24e9-goog
+2.40.0.577.gac1e443424-goog