Skip to content

Commit c3f0607

Browse files
deepakala-kwltu
andcommitted
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 other commit to use pretty name for dimm and fan into this commit for easier maintanence Squashed another commit: "Logging invalid service name for debug" 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. Signed-off-by: Willy Tu <[email protected]> Co-authored-by: Willy Tu <[email protected]>
1 parent 93df608 commit c3f0607

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-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", [asyncResp, path, namePath]
54+
(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/chassis.hpp

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

2526
#include <asm-generic/errno.h>
2627

@@ -583,7 +584,9 @@ inline void handleChassisGetSubTree(
583584
asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis";
584585
asyncResp->res.jsonValue["@odata.id"] =
585586
boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
586-
asyncResp->res.jsonValue["Name"] = "Chassis Collection";
587+
name_util::getPrettyName(asyncResp, path, connectionNames,
588+
"/Name"_json_pointer);
589+
asyncResp->res.jsonValue["ChassisType"] = "RackMount";
587590
asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
588591
boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset",
589592
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

@@ -765,6 +767,8 @@ inline void handleProcessorSubtree(
765767
// process must be on the same object path.
766768

767769
callback(objectPath, serviceMap);
770+
name_util::getPrettyName(asyncResp, objectPath, serviceMap,
771+
"/Name"_json_pointer);
768772
return;
769773
}
770774
}

redfish-core/lib/storage.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#include "registries/privilege_registry.hpp"
2121
#include "utils/collection.hpp"
2222
#include "utils/dbus_utils.hpp"
23+
#include "utils/name_utils.hpp"
2324

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

@@ -660,10 +662,10 @@ inline void afterGetSubtreeSystemsStorageDrive(
660662
const dbus::utility::MapperServiceMap& connectionNames = drive->second;
661663

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

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

0 commit comments

Comments
 (0)