PEL: Update filling VPD fields in PEL
Due to changes to the way Inventory manager adds Interfaces to
D-Bus the watches on Interfaces for VPD are not triggered anymore.
This change is to make a getProperty call to the Inventory
service every time the PEL is created.
Tested: Ran PEL Create command to inspect the PEL log to make
sure the MTMS and CCIN fields populate as needed
Change-Id: Icf918b23f36d9d69ad603b00daabdd8af9531783
Signed-off-by: Vijay Lobo <vijaylobo@gmail.com>
diff --git a/extensions/openpower-pels/data_interface.cpp b/extensions/openpower-pels/data_interface.cpp
index a228cbb..c3ca67c 100644
--- a/extensions/openpower-pels/data_interface.cpp
+++ b/extensions/openpower-pels/data_interface.cpp
@@ -19,7 +19,10 @@
#include "util.hpp"
+#include <fmt/format.h>
+
#include <fstream>
+#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
namespace openpower
@@ -39,6 +42,8 @@
constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper";
constexpr auto systemInv = "/xyz/openbmc_project/inventory/system";
constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis";
+constexpr auto motherBoardInv =
+ "/xyz/openbmc_project/inventory/system/chassis/motherboard";
constexpr auto baseInv = "/xyz/openbmc_project/inventory";
constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0";
constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0";
@@ -74,30 +79,13 @@
using namespace sdbusplus::xyz::openbmc_project::State::Boot::server;
using sdbusplus::exception::SdBusError;
+using namespace phosphor::logging;
DataInterface::DataInterface(sdbusplus::bus::bus& bus) : _bus(bus)
{
readBMCFWVersion();
readServerFWVersion();
readBMCFWVersionID();
- readMotherboardCCIN();
-
- // Watch both the Model and SN properties on the system's Asset iface
- _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>(
- bus, object_path::systemInv, interface::invAsset, *this,
- [this](const auto& properties) {
- auto model = properties.find("Model");
- if (model != properties.end())
- {
- this->_machineTypeModel = std::get<std::string>(model->second);
- }
-
- auto sn = properties.find("SerialNumber");
- if (sn != properties.end())
- {
- this->_machineSerialNumber = std::get<std::string>(sn->second);
- }
- }));
// Watch the BootProgress property
_properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
@@ -245,55 +233,89 @@
phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or("");
}
-void DataInterface::readMotherboardCCIN()
+std::string DataInterface::getMachineTypeModel() const
{
+ std::string model;
try
{
- // First, try to find the motherboard
- auto motherboards = getPaths({interface::invMotherboard});
- if (motherboards.empty())
- {
- throw std::runtime_error("No motherboards yet");
- }
- // Found it, so now get the CCIN
- _properties.emplace_back(
- std::make_unique<PropertyWatcher<DataInterface>>(
- _bus, motherboards.front(), interface::viniRecordVPD, "CC",
- *this,
- [this](const auto& ccin) { this->setMotherboardCCIN(ccin); }));
+ auto service = getService(object_path::systemInv, interface::invAsset);
+ if (!service.empty())
+ {
+ DBusValue value;
+ getProperty(service, object_path::systemInv, interface::invAsset,
+ "Model", value);
+
+ model = std::get<std::string>(value);
+ }
}
catch (const std::exception& e)
{
- // No motherboard in the inventory yet - watch for it
- _inventoryIfacesAddedMatch = std::make_unique<sdbusplus::bus::match_t>(
- _bus, match_rules::interfacesAdded(object_path::baseInv),
- std::bind(std::mem_fn(&DataInterface::motherboardIfaceAdded), this,
- std::placeholders::_1));
+ log<level::WARNING>(fmt::format("Failed reading Model property from "
+ "Interface: {} exception: {}",
+ interface::invAsset, e.what())
+ .c_str());
}
+
+ return model;
}
-void DataInterface::motherboardIfaceAdded(sdbusplus::message::message& msg)
+std::string DataInterface::getMachineSerialNumber() const
{
- sdbusplus::message::object_path path;
- DBusInterfaceMap interfaces;
-
- msg.read(path, interfaces);
-
- // This is watching the whole inventory, so check if it's what we want
- if (interfaces.find(interface::invMotherboard) == interfaces.end())
+ std::string sn;
+ try
{
- return;
+
+ auto service = getService(object_path::systemInv, interface::invAsset);
+ if (!service.empty())
+ {
+ DBusValue value;
+ getProperty(service, object_path::systemInv, interface::invAsset,
+ "SerialNumber", value);
+
+ sn = std::get<std::string>(value);
+ }
+ }
+ catch (const std::exception& e)
+ {
+ log<level::WARNING>(
+ fmt::format("Failed reading SerialNumber property from "
+ "Interface: {} exception: {}",
+ interface::invAsset, e.what())
+ .c_str());
}
- // Done watching for any new inventory interfaces
- _inventoryIfacesAddedMatch.reset();
+ return sn;
+}
- // Watch the motherboard CCIN, using the service from this signal
- // for the initial property read.
- _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
- _bus, path, interface::viniRecordVPD, "CC", msg.get_sender(), *this,
- [this](const auto& ccin) { this->setMotherboardCCIN(ccin); }));
+std::string DataInterface::getMotherboardCCIN() const
+{
+ std::string ccin;
+
+ try
+ {
+ auto service =
+ getService(object_path::motherBoardInv, interface::viniRecordVPD);
+ if (!service.empty())
+ {
+ DBusValue value;
+ getProperty(service, object_path::motherBoardInv,
+ interface::viniRecordVPD, "CC", value);
+
+ auto cc = std::get<std::vector<uint8_t>>(value);
+ ccin = std::string{cc.begin(), cc.end()};
+ }
+ }
+ catch (const std::exception& e)
+ {
+ log<level::WARNING>(
+ fmt::format("Failed reading Motherboard CCIN property from "
+ "Interface: {} exception: {}",
+ interface::viniRecordVPD, e.what())
+ .c_str());
+ }
+
+ return ccin;
}
void DataInterface::getHWCalloutFields(const std::string& inventoryPath,
diff --git a/extensions/openpower-pels/data_interface.hpp b/extensions/openpower-pels/data_interface.hpp
index 385b07a..9894684 100644
--- a/extensions/openpower-pels/data_interface.hpp
+++ b/extensions/openpower-pels/data_interface.hpp
@@ -34,20 +34,14 @@
*
* @return string - The machine Type/Model string
*/
- virtual std::string getMachineTypeModel() const
- {
- return _machineTypeModel;
- }
+ virtual std::string getMachineTypeModel() const = 0;
/**
* @brief Returns the machine serial number
*
* @return string - The machine serial number
*/
- virtual std::string getMachineSerialNumber() const
- {
- return _machineSerialNumber;
- }
+ virtual std::string getMachineSerialNumber() const = 0;
/**
* @brief Says if the system is managed by a hardware
@@ -205,10 +199,7 @@
*
* @return std::string The motherboard CCIN
*/
- virtual std::string getMotherboardCCIN() const
- {
- return _motherboardCCIN;
- }
+ virtual std::string getMotherboardCCIN() const = 0;
/**
* @brief Get the fields from the inventory necessary for doing
@@ -325,16 +316,6 @@
}
/**
- * @brief The machine type-model. Always kept up to date
- */
- std::string _machineTypeModel;
-
- /**
- * @brief The machine serial number. Always kept up to date
- */
- std::string _machineSerialNumber;
-
- /**
* @brief The hardware management console status. Always kept
* up to date.
*/
@@ -392,11 +373,6 @@
* @brief The host state property
*/
std::string _hostState;
-
- /**
- * @brief The motherboard CCIN
- */
- std::string _motherboardCCIN;
};
/**
@@ -455,6 +431,26 @@
void getProperty(const std::string& service, const std::string& objectPath,
const std::string& interface, const std::string& property,
DBusValue& value) const;
+ /**
+ * @brief Returns the machine Type/Model
+ *
+ * @return string - The machine Type/Model string
+ */
+ std::string getMachineTypeModel() const override;
+
+ /**
+ * @brief Returns the machine serial number
+ *
+ * @return string - The machine serial number
+ */
+ std::string getMachineSerialNumber() const override;
+
+ /**
+ * @brief Returns the motherboard CCIN
+ *
+ * @return std::string The motherboard CCIN
+ */
+ std::string getMotherboardCCIN() const override;
/**
* @brief Get the fields from the inventory necessary for doing
@@ -564,14 +560,6 @@
void readBMCFWVersionID();
/**
- * @brief Reads the motherboard CCIN and puts it into _motherboardCCIN.
- *
- * It finds the motherboard first, possibly having to wait for it to
- * show up.
- */
- void readMotherboardCCIN();
-
- /**
* @brief Finds all D-Bus paths that contain any of the interfaces
* passed in, by using GetSubTreePaths.
*
@@ -590,18 +578,6 @@
void motherboardIfaceAdded(sdbusplus::message::message& msg);
/**
- * @brief Set the motherboard CCIN from the DBus variant that
- * contains it.
- *
- * @param[in] ccin - The CCIN variant, a vector<uint8_t>.
- */
- void setMotherboardCCIN(const DBusValue& ccin)
- {
- const auto& c = std::get<std::vector<uint8_t>>(ccin);
- _motherboardCCIN = std::string{c.begin(), c.end()};
- }
-
- /**
* @brief Adds the Ufcs- prefix to the location code passed in
* if necessary.
*