Skip to content

Commit 9d2cd2e

Browse files
authored
Merge pull request #570 from SunnySrivastava1984/updatePresentProperty
API to set present property
2 parents b1e5ac9 + a7432d2 commit 9d2cd2e

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

vpd-manager/include/worker.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ class Worker
499499
*/
500500
void setJsonSymbolicLink(const std::string& i_systemJson);
501501

502+
/**
503+
* @brief API to set present property.
504+
*
505+
* @param[in] i_vpdPath - EEPROM or inventory path.
506+
* @param[in] i_value - value to be set.
507+
*/
508+
void setPresentProperty(const std::string& i_fruPath, const bool& i_value);
509+
502510
// Parsed JSON file.
503511
nlohmann::json m_parsedJson{};
504512

vpd-manager/src/worker.cpp

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,15 @@ bool Worker::primeInventory(const std::string& i_vpdFilePath)
835835

836836
types::PropertyMap l_propertyValueMap;
837837
l_propertyValueMap.emplace("Present", false);
838-
if (std::filesystem::exists(i_vpdFilePath))
838+
839+
// TODO: Present based on file will be taken care in future.
840+
// By default present is set to false for FRU at the time of
841+
// priming. Once collection goes through, it will be set to true in that
842+
// flow.
843+
/*if (std::filesystem::exists(i_vpdFilePath))
839844
{
840845
l_propertyValueMap["Present"] = true;
841-
}
846+
}*/
842847

843848
vpdSpecificUtility::insertOrMerge(l_interfaces,
844849
"xyz.openbmc_project.Inventory.Item",
@@ -1464,13 +1469,11 @@ std::tuple<bool, std::string>
14641469

14651470
// TODO: Figure out a way to clear data in case of any failure at
14661471
// runtime.
1467-
// Prime the inventry for FRUs which
1468-
// are not present/processing had some error.
1469-
/* if (!primeInventory(i_vpdFilePath))
1470-
{
1471-
logging::logMessage("Priming of inventory failed for FRU " +
1472-
i_vpdFilePath);
1473-
}*/
1472+
1473+
// set present property to false for any error case. In future this will
1474+
// be replaced by presence logic.
1475+
setPresentProperty(i_vpdFilePath, false);
1476+
14741477
m_semaphore.release();
14751478
return std::make_tuple(false, i_vpdFilePath);
14761479
}
@@ -1674,4 +1677,72 @@ void Worker::deleteFruVpd(const std::string& i_dbusObjPath)
16741677
" error: " + std::string(l_ex.what()));
16751678
}
16761679
}
1680+
1681+
void Worker::setPresentProperty(const std::string& i_vpdPath,
1682+
const bool& i_value)
1683+
{
1684+
try
1685+
{
1686+
if (i_vpdPath.empty())
1687+
{
1688+
throw std::runtime_error(
1689+
"Path is empty. Can't set present property");
1690+
}
1691+
1692+
types::ObjectMap l_objectInterfaceMap;
1693+
1694+
// If the given path is EEPROM path.
1695+
if (m_parsedJson["frus"].contains(i_vpdPath))
1696+
{
1697+
for (const auto& l_Fru : m_parsedJson["frus"][i_vpdPath])
1698+
{
1699+
sdbusplus::message::object_path l_fruObjectPath(
1700+
l_Fru["inventoryPath"]);
1701+
1702+
types::PropertyMap l_propertyValueMap;
1703+
l_propertyValueMap.emplace("Present", i_value);
1704+
1705+
types::InterfaceMap l_interfaces;
1706+
vpdSpecificUtility::insertOrMerge(l_interfaces,
1707+
constants::inventoryItemInf,
1708+
move(l_propertyValueMap));
1709+
1710+
l_objectInterfaceMap.emplace(std::move(l_fruObjectPath),
1711+
std::move(l_interfaces));
1712+
}
1713+
}
1714+
else
1715+
{
1716+
// consider it as an inventory path.
1717+
if (i_vpdPath.find(constants::pimPath) != constants::VALUE_0)
1718+
{
1719+
throw std::runtime_error("Invalid inventory path: " +
1720+
i_vpdPath);
1721+
}
1722+
1723+
types::PropertyMap l_propertyValueMap;
1724+
l_propertyValueMap.emplace("Present", i_value);
1725+
1726+
types::InterfaceMap l_interfaces;
1727+
vpdSpecificUtility::insertOrMerge(l_interfaces,
1728+
constants::inventoryItemInf,
1729+
move(l_propertyValueMap));
1730+
1731+
l_objectInterfaceMap.emplace(i_vpdPath, std::move(l_interfaces));
1732+
}
1733+
1734+
// Notify PIM
1735+
if (!dbusUtility::callPIM(move(l_objectInterfaceMap)))
1736+
{
1737+
throw std::runtime_error(
1738+
"Call to PIM failed while setting present property for path " +
1739+
i_vpdPath);
1740+
}
1741+
}
1742+
catch (const std::exception& l_ex)
1743+
{
1744+
logging::logMessage(l_ex.what());
1745+
}
1746+
}
1747+
16771748
} // namespace vpd

0 commit comments

Comments
 (0)