Skip to content

Commit 115e43e

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 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) 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 fc1dcb8 commit 115e43e

File tree

7 files changed

+101
-7
lines changed

7 files changed

+101
-7
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 List of services 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 dbus::utility::MapperServiceMap& services,
32+
const nlohmann::json::json_pointer& namePath)
33+
{
34+
BMCWEB_LOG_DEBUG("Get PrettyName for: {}", path);
35+
36+
// Ensure we only got one service back
37+
if (services.size() != 1)
38+
{
39+
BMCWEB_LOG_ERROR("Invalid Service Size {}", services.size());
40+
for (const auto& service : services)
41+
{
42+
BMCWEB_LOG_ERROR("Invalid Service Name: {}", service.first);
43+
}
44+
if (asyncResp)
45+
{
46+
messages::internalError(asyncResp->res);
47+
}
48+
return;
49+
}
50+
51+
dbus::utility::getProperty<std::string>(
52+
services[0].first, path, "xyz.openbmc_project.Inventory.Item",
53+
"PrettyName",
54+
[asyncResp, path, namePath](const boost::system::error_code& ec,
55+
const std::string& prettyName) {
56+
if (ec)
57+
{
58+
BMCWEB_LOG_DEBUG("DBUS response error : {}", ec.value());
59+
return;
60+
}
61+
62+
if (prettyName.empty())
63+
{
64+
return;
65+
}
66+
67+
BMCWEB_LOG_DEBUG("Pretty Name: {}", prettyName);
68+
69+
asyncResp->res.jsonValue[namePath] = prettyName;
70+
});
71+
}
72+
73+
} // namespace name_util
74+
} // namespace redfish

redfish-core/lib/assembly.hpp

Lines changed: 6 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,11 @@ inline void getAssemblyProperties(
232233
return;
233234
}
234235

236+
nlohmann::json::json_pointer ptr(
237+
"/Assemblies/" + std::to_string(assemblyIndex) + "/Name");
238+
239+
name_util::getPrettyName(asyncResp, assembly, object, ptr);
240+
235241
for (const auto& [serviceName, interfaceList] : object)
236242
{
237243
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/fan.hpp

Lines changed: 4 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,9 @@ inline void afterGetValidFanPath(
387387
getFanAsset(asyncResp, fanPath, service);
388388
getFanLocation(asyncResp, fanPath, service);
389389
getLocationIndicatorActive(asyncResp, fanPath);
390+
const dbus::utility::MapperServiceMap& serviceMatch = {{service, {""}}};
391+
name_util::getPrettyName(asyncResp, fanPath, serviceMatch,
392+
"/Name"_json_pointer);
390393
}
391394

392395
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: 6 additions & 4 deletions
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

@@ -661,10 +663,10 @@ inline void afterGetSubtreeSystemsStorageDrive(
661663
const dbus::utility::MapperServiceMap& connectionNames = drive->second;
662664

663665
asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive";
664-
asyncResp->res.jsonValue["@odata.id"] =
665-
boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Drives/{}",
666-
BMCWEB_REDFISH_SYSTEM_URI_NAME, driveId);
667-
asyncResp->res.jsonValue["Name"] = driveId;
666+
asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
667+
"/redfish/v1/Systems/system/Storage/1/Drives/{}", driveId);
668+
name_util::getPrettyName(asyncResp, path, drive->second,
669+
"/Name"_json_pointer);
668670
asyncResp->res.jsonValue["Id"] = driveId;
669671

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

0 commit comments

Comments
 (0)