Add inventory & chassis association to PSU sensors
For PSU sensor object paths, inventory and chassis
associations is missing due to double initialization
of association interface. Due to this PSU information
and PSU sensors are not show up in Redfish under
chassis. Corrected the code to register association
property and initialize it only after filling all
associations.
Tested:
- PowerSupplies information shows up in redfish /<chassisid>/Power
- PSU sensors shows up in redfish /<chassisid>/Thermal
and <chassisid>/sensors
Change-Id: If2a16e55681718d5b21f3d38c5465d36bda65460
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
diff --git a/include/sensor.hpp b/include/sensor.hpp
index 263cbfb..fa35ef5 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -61,6 +61,7 @@
setInitialProperties(std::shared_ptr<sdbusplus::asio::connection>& conn)
{
createAssociation(association, configurationPath);
+
sensorInterface->register_property("MaxValue", maxValue);
sensorInterface->register_property("MinValue", minValue);
sensorInterface->register_property(
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index d5f1b23..e94d1c4 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -81,10 +81,14 @@
thresholdInterfaceCritical = objectServer.add_interface(
dbusPath, "xyz.openbmc_project.Sensor.Threshold.Critical");
}
- association = objectServer.add_interface(dbusPath, association::interface);
+ // This should be called before initializing association.
+ // createInventoryAssoc() does add more associations before doing
+ // register and initialize "Associations" property.
setInitialProperties(conn);
+ association = objectServer.add_interface(dbusPath, association::interface);
+
createInventoryAssoc(conn, association, configurationPath);
setupRead();
}
@@ -96,6 +100,7 @@
objServer.remove_interface(sensorInterface);
objServer.remove_interface(thresholdInterfaceWarning);
objServer.remove_interface(thresholdInterfaceCritical);
+ objServer.remove_interface(association);
}
void PSUSensor::setupRead(void)
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 44a6bae..ca5a294 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -271,17 +271,24 @@
void setInventoryAssociation(
std::shared_ptr<sdbusplus::asio::dbus_interface> association,
- const std::string& path, const std::string& chassisPath)
+ const std::string& path,
+ const std::vector<std::string>& chassisPaths = std::vector<std::string>())
{
if (association)
{
std::filesystem::path p(path);
-
std::vector<Association> associations;
- associations.push_back(
- Association("inventory", "sensors", p.parent_path().string()));
- associations.push_back(
- Association("chassis", "all_sensors", chassisPath));
+ std::string objPath(p.parent_path().string());
+
+ associations.push_back(Association("inventory", "sensors", objPath));
+ associations.push_back(Association("chassis", "all_sensors", objPath));
+
+ for (const std::string& chassisPath : chassisPaths)
+ {
+ associations.push_back(
+ Association("chassis", "all_sensors", chassisPath));
+ }
+
association->register_property("Associations", associations);
association->initialize();
}
@@ -296,18 +303,18 @@
{
return;
}
+
conn->async_method_call(
[association, path](const boost::system::error_code ec,
- const std::vector<std::string>& ret) {
+ const std::vector<std::string>& invSysObjPaths) {
if (ec)
{
- std::cerr << "Error calling mapper\n";
+ // In case of error, set the default associations and
+ // initialize the association Interface.
+ setInventoryAssociation(association, path);
return;
}
- for (const auto& object : ret)
- {
- setInventoryAssociation(association, path, object);
- }
+ setInventoryAssociation(association, path, invSysObjPaths);
},
mapper::busName, mapper::path, mapper::interface, "GetSubTreePaths",
"/xyz/openbmc_project/inventory/system", 2,