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>
(cherry picked from commit 30edf418af83f47aad96c773709e53396cdd9d70)
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 9534f8f..ac0c4ba 100644
--- a/recipes-phosphor/interfaces/bmcweb/0018-Processor-Implement-Efficient-expand.patch
+++ b/recipes-phosphor/interfaces/bmcweb/0018-Processor-Implement-Efficient-expand.patch
@@ -1,4 +1,4 @@
-From 51590b81859230bbdbe35af896da20bad51ac73e Mon Sep 17 00:00:00 2001
+From dd7699f5f6c96ec094dc2e429d7087b16c3393ed Mon Sep 17 00:00:00 2001
From: Nikhil Namjoshi <nikhilnamjoshi@google.com>
Date: Mon, 22 Aug 2022 16:59:17 +0000
Subject: [PATCH] Processor : Implement Efficient expand
@@ -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 | 452 +++++++++++++++++++++++++++++++--
- 1 file changed, 436 insertions(+), 16 deletions(-)
+ redfish-core/lib/processor.hpp | 461 +++++++++++++++++++++++++++++++--
+ 1 file changed, 445 insertions(+), 16 deletions(-)
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
-index a5c7dcd1..b38031a8 100644
+index a5c7dcd1..b621586e 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -35,10 +35,29 @@
@@ -278,7 +280,7 @@
return;
}
// Object not found
-@@ -1458,6 +1503,366 @@ inline void
+@@ -1458,6 +1503,375 @@ inline void
cpuPath.c_str());
}
@@ -612,6 +614,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,7 @@
/**
* Request all the properties for the given D-Bus object and fill out the
* related entries in the Redfish OperatingConfig response.
-@@ -1919,7 +2324,12 @@ inline void requestRoutesProcessorCollection(App& app)
+@@ -1919,7 +2333,12 @@ inline void requestRoutesProcessorCollection(App& app)
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName) {
@@ -659,7 +670,7 @@
{
return;
}
-@@ -1941,11 +2351,21 @@ inline void requestRoutesProcessorCollection(App& app)
+@@ -1941,11 +2360,21 @@ inline void requestRoutesProcessorCollection(App& app)
asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Systems/system/Processors";
@@ -682,7 +693,7 @@
});
}
-@@ -1980,7 +2400,7 @@ inline void requestRoutesProcessor(App& app)
+@@ -1980,7 +2409,7 @@ inline void requestRoutesProcessor(App& app)
getProcessorObject(asyncResp, processorId,
std::bind_front(getProcessorData, asyncResp,
@@ -692,5 +703,5 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
--
-2.39.1.581.gbfd45094c4-goog
+2.40.0.577.gac1e443424-goog