Skip to content

Commit 948e4c7

Browse files
deepakala-kwltuSunnySrivastava1984gtmills
committed
util: Add pretty name for resources (#918)
Created a helper function to fetch pretty name and added for some resources. - Chassis - FirmwareInventory - Storage - StorageController - System - Processor - Fan - Fabric Adaptor - Memory - Assembly Implementation Details: The helper function makes a call to ObjectMapper to get the services that support the object path with the interfaces we want. It expects only one service is exporting the object path. Then it will try to get the `PrettyName` property. If it is found and is valid, it will set the `Name` to the value. If not, it will use the default value that is set before the function call. This will affect all systems and replace the Name with the PrettyName if it exist within the resource's object path. Tested: Passed Redfish Validator The output names release the existing `Name` property only if the PrettyName property exists. If not, it will use the default value. Output with PrettyName ``` $ curl -u root:0penBmc -X GET http://${bmc}/redfish/v1/Chassis/chassis0 { "@odata.id": "/redfish/v1/Chassis/chassis0", "@odata.type": "#Chassis.v1_14_0.Chassis", "ChassisType": "RackMount", "Id": "chassis0", "Links": { "ComputerSystems": [ { "@odata.id": "/redfish/v1/Systems/system" } ], "ManagedBy": [ { "@odata.id": "/redfish/v1/Managers/bmc" } ] }, "Name": "Test Chassis", ... } ``` Without PrettyName ``` $ curl -u root:0penBmc -X GET http://${bmc}/redfish/v1/Chassis/chassis0 { "@odata.id": "/redfish/v1/Chassis/chassis0", "@odata.type": "#Chassis.v1_14_0.Chassis", "ChassisType": "RackMount", "Id": "chassis0", "Links": { "ComputerSystems": [ { "@odata.id": "/redfish/v1/Systems/system" } ], "ManagedBy": [ { "@odata.id": "/redfish/v1/Managers/bmc" } ] }, "Name": "chassis0", ... } ``` Squashed following commits: Logging invalid service name for debug Util api to fetch pretty name for assemblies Dimm: Look at Pretty Name (#973) (#1111) Add pretty name for fabric adapters (#869) The method getPrettyName() may be called more than one time. This will generate journal logging messages for the required Service name if there are unexpected service names. In case prettyName is blank for that FRU, then last part of the object path will be used to populate assembly name. Signed-off-by: Willy Tu <[email protected]> Co-authored-by: Willy Tu <[email protected]> Co-authored-by: Sunny Srivastava <[email protected]> Co-authored-by: Gunnar Mills <[email protected]>
1 parent 708bf03 commit 948e4c7

File tree

9 files changed

+126
-6
lines changed

9 files changed

+126
-6
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
#pragma once
3+
#include "dbus_utility.hpp"
4+
#include "error_messages.hpp"
5+
#include "logging.hpp"
6+
7+
#include <async_resp.hpp>
8+
#include <boost/system/error_code.hpp>
9+
10+
#include <memory>
11+
#include <string>
12+
13+
namespace redfish
14+
{
15+
namespace name_util
16+
{
17+
18+
/**
19+
* @brief Populate the collection "Members" from a GetSubTreePaths search of
20+
* inventory
21+
*
22+
* @param[i,o] asyncResp Async response object
23+
* @param[i] path D-bus object path to find the pretty name
24+
* @param[i] services Service to exporting the D-bus object path
25+
* @param[i] namePath Json pointer to the name field to update.
26+
*
27+
* @return void
28+
*/
29+
inline void getPrettyName(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
30+
const std::string& path,
31+
const std::string& serviceName,
32+
const nlohmann::json::json_pointer& namePath)
33+
{
34+
BMCWEB_LOG_DEBUG("Get PrettyName for: {}", path);
35+
36+
dbus::utility::getProperty<std::string>(
37+
serviceName, path, "xyz.openbmc_project.Inventory.Item", "PrettyName",
38+
[asyncResp, path, namePath](const boost::system::error_code& ec,
39+
const std::string& prettyName) {
40+
if (ec)
41+
{
42+
BMCWEB_LOG_DEBUG("DBUS response error : {}", ec.value());
43+
return;
44+
}
45+
46+
if (prettyName.empty())
47+
{
48+
return;
49+
}
50+
51+
BMCWEB_LOG_DEBUG("Pretty Name: {}", prettyName);
52+
53+
asyncResp->res.jsonValue[namePath] = prettyName;
54+
});
55+
}
56+
57+
/**
58+
* @brief Populate the collection "Members" from a GetSubTreePaths search of
59+
* inventory
60+
*
61+
* @param[i,o] asyncResp Async response object
62+
* @param[i] path D-bus object path to find the pretty name
63+
* @param[i] services List of services to exporting the D-bus object path
64+
* @param[i] namePath Json pointer to the name field to update.
65+
*
66+
* @return void
67+
*/
68+
inline void getPrettyName(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
69+
const std::string& path,
70+
const dbus::utility::MapperServiceMap& services,
71+
const nlohmann::json::json_pointer& namePath)
72+
{
73+
BMCWEB_LOG_DEBUG("Get PrettyName with MapperServiceMap for: {}", path);
74+
75+
// Ensure we only got one service back
76+
if (services.size() != 1)
77+
{
78+
BMCWEB_LOG_ERROR("Invalid Service Size {}", services.size());
79+
for (const auto& service : services)
80+
{
81+
BMCWEB_LOG_ERROR("Invalid Service Name: {}", service.first);
82+
}
83+
if (asyncResp)
84+
{
85+
messages::internalError(asyncResp->res);
86+
}
87+
return;
88+
}
89+
90+
getPrettyName(asyncResp, path, services[0].first, namePath);
91+
}
92+
93+
} // namespace name_util
94+
} // namespace redfish

redfish-core/lib/assembly.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <nlohmann/json.hpp>
2222
#include <sdbusplus/asio/property.hpp>
2323
#include <sdbusplus/unpack_properties.hpp>
24+
#include <utils/name_utils.hpp>
2425

2526
#include <algorithm>
2627
#include <array>
@@ -232,6 +233,10 @@ inline void getAssemblyProperties(
232233
return;
233234
}
234235

236+
nlohmann::json::json_pointer ptr(
237+
"/Assemblies/" + std::to_string(assemblyIndex) + "/Name");
238+
name_util::getPrettyName(asyncResp, assembly, object, ptr);
239+
235240
for (const auto& [serviceName, interfaceList] : object)
236241
{
237242
for (const auto& interface : interfaceList)

redfish-core/lib/chassis.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "utils/collection.hpp"
2323
#include "utils/dbus_utils.hpp"
2424
#include "utils/json_utils.hpp"
25+
#include "utils/name_utils.hpp"
2526

2627
#include <boost/beast/http/field.hpp>
2728
#include <boost/beast/http/verb.hpp>
@@ -478,7 +479,9 @@ inline void handleChassisGetSubTree(
478479
asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis";
479480
asyncResp->res.jsonValue["@odata.id"] =
480481
boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
481-
asyncResp->res.jsonValue["Name"] = "Chassis Collection";
482+
name_util::getPrettyName(asyncResp, path, connectionNames,
483+
"/Name"_json_pointer);
484+
asyncResp->res.jsonValue["ChassisType"] = "RackMount";
482485
asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
483486
boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset",
484487
chassisId);

redfish-core/lib/fabric_adapters.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <boost/url/format.hpp>
2828
#include <sdbusplus/message/native_types.hpp>
2929
#include <sdbusplus/unpack_properties.hpp>
30+
#include <utils/name_utils.hpp>
3031

3132
#include <algorithm>
3233
#include <array>
@@ -309,7 +310,10 @@ inline void doAdapterGet(
309310
"</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
310311
asyncResp->res.jsonValue["@odata.type"] =
311312
"#FabricAdapter.v1_4_0.FabricAdapter";
312-
asyncResp->res.jsonValue["Name"] = "Fabric Adapter";
313+
314+
nlohmann::json::json_pointer ptr("/Name");
315+
name_util::getPrettyName(asyncResp, fabricAdapterPath, serviceName, ptr);
316+
313317
asyncResp->res.jsonValue["Id"] = adapterId;
314318
asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
315319
"/redfish/v1/Systems/{}/FabricAdapters/{}", systemName, adapterId);

redfish-core/lib/fabric_ports.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <boost/system/error_code.hpp>
2626
#include <boost/url/format.hpp>
2727
#include <sdbusplus/asio/property.hpp>
28+
#include <utils/name_utils.hpp>
2829

2930
#include <algorithm>
3031
#include <array>
@@ -156,7 +157,10 @@ inline void getFabricPortProperties(
156157
boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters/{}/Ports/{}",
157158
systemName, adapterId, portId);
158159
asyncResp->res.jsonValue["Id"] = portId;
159-
asyncResp->res.jsonValue["Name"] = "Fabric Port";
160+
161+
nlohmann::json::json_pointer ptr("/Name");
162+
name_util::getPrettyName(asyncResp, portPath, serviceName, ptr);
163+
160164
asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
161165
asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
162166

redfish-core/lib/fan.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "registries/privilege_registry.hpp"
1515
#include "utils/chassis_utils.hpp"
1616
#include "utils/json_utils.hpp"
17+
#include "utils/name_utils.hpp"
1718

1819
#include <asm-generic/errno.h>
1920

@@ -235,7 +236,6 @@ inline void addFanCommonProperties(crow::Response& resp,
235236
resp.addHeader(boost::beast::http::field::link,
236237
"</redfish/v1/JsonSchemas/Fan/Fan.json>; rel=describedby");
237238
resp.jsonValue["@odata.type"] = "#Fan.v1_3_0.Fan";
238-
resp.jsonValue["Name"] = "Fan";
239239
resp.jsonValue["Id"] = fanId;
240240
resp.jsonValue["@odata.id"] = boost::urls::format(
241241
"/redfish/v1/Chassis/{}/ThermalSubsystem/Fans/{}", chassisId, fanId);
@@ -387,6 +387,7 @@ inline void afterGetValidFanPath(
387387
getFanAsset(asyncResp, fanPath, service);
388388
getFanLocation(asyncResp, fanPath, service);
389389
getLocationIndicatorActive(asyncResp, fanPath);
390+
name_util::getPrettyName(asyncResp, fanPath, service, "/Name"_json_pointer);
390391
}
391392

392393
inline void doFanGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,

redfish-core/lib/memory.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <nlohmann/json.hpp>
3030
#include <sdbusplus/message/native_types.hpp>
3131
#include <sdbusplus/unpack_properties.hpp>
32+
#include <utils/name_utils.hpp>
3233

3334
#include <array>
3435
#include <cstddef>
@@ -408,7 +409,6 @@ inline void assembleDimmProperties(
408409
const nlohmann::json::json_pointer& jsonPtr)
409410
{
410411
asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
411-
asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
412412
asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
413413
resource::State::Enabled;
414414
asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] =
@@ -754,6 +754,8 @@ inline void afterGetDimmData(
754754
objectPath);
755755
dimmInterface = true;
756756
found = true;
757+
name_util::getPrettyName(asyncResp, objectPath, serviceMap,
758+
"/Name"_json_pointer);
757759
}
758760
else if (interface ==
759761
"xyz.openbmc_project.Association.Definitions")

redfish-core/lib/processor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include "utils/dbus_utils.hpp"
2121
#include "utils/hex_utils.hpp"
2222
#include "utils/json_utils.hpp"
23+
#include "utils/name_utils.hpp"
2324

2425
#include <boost/beast/http/field.hpp>
2526
#include <boost/beast/http/verb.hpp>
2627
#include <boost/system/error_code.hpp>
2728
#include <boost/url/format.hpp>
29+
#include <nlohmann/json.hpp>
2830
#include <sdbusplus/message/native_types.hpp>
2931
#include <sdbusplus/unpack_properties.hpp>
3032

@@ -813,6 +815,8 @@ inline void handleProcessorSubtree(
813815
// process must be on the same object path.
814816

815817
callback(objectPath, serviceMap);
818+
name_util::getPrettyName(asyncResp, objectPath, serviceMap,
819+
"/Name"_json_pointer);
816820
return;
817821
}
818822
}

redfish-core/lib/storage.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
#include "utils/chassis_utils.hpp"
2222
#include "utils/collection.hpp"
2323
#include "utils/dbus_utils.hpp"
24+
#include "utils/name_utils.hpp"
2425

2526
#include <boost/beast/http/verb.hpp>
2627
#include <boost/system/error_code.hpp>
2728
#include <boost/url/format.hpp>
29+
#include <nlohmann/json.hpp>
2830
#include <sdbusplus/message/native_types.hpp>
2931
#include <sdbusplus/unpack_properties.hpp>
3032

@@ -664,7 +666,8 @@ inline void afterGetSubtreeSystemsStorageDrive(
664666
asyncResp->res.jsonValue["@odata.id"] =
665667
boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Drives/{}",
666668
BMCWEB_REDFISH_SYSTEM_URI_NAME, driveId);
667-
asyncResp->res.jsonValue["Name"] = driveId;
669+
name_util::getPrettyName(asyncResp, path, drive->second,
670+
"/Name"_json_pointer);
668671
asyncResp->res.jsonValue["Id"] = driveId;
669672

670673
if (connectionNames.size() != 1)

0 commit comments

Comments
 (0)