Skip to content

Commit

Permalink
PEL for Manager class
Browse files Browse the repository at this point in the history
This commit adds code to log a PEL in Manager class, in case of error
where PEL is required.

Also removed try catch block in manager constructor, as we are not doing
any error handling.

Signed-off-by: RekhaAparna01 <[email protected]>
  • Loading branch information
RekhaAparna01 committed Dec 19, 2024
1 parent 5c290ad commit 2fffca6
Showing 1 changed file with 111 additions and 108 deletions.
219 changes: 111 additions & 108 deletions vpd-manager/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "backup_restore.hpp"
#include "constants.hpp"
#include "event_logger.hpp"
#include "exceptions.hpp"
#include "logger.hpp"
#include "parser.hpp"
Expand All @@ -26,113 +27,102 @@ Manager::Manager(
const std::shared_ptr<sdbusplus::asio::connection>& asioConnection) :
m_ioContext(ioCon), m_interface(iFace), m_asioConnection(asioConnection)
{
try
{
#ifdef IBM_SYSTEM
m_worker = std::make_shared<Worker>(INVENTORY_JSON_DEFAULT);
m_worker = std::make_shared<Worker>(INVENTORY_JSON_DEFAULT);

// Set up minimal things that is needed before bus name is claimed.
m_worker->performInitialSetup();
// Set up minimal things that is needed before bus name is claimed.
m_worker->performInitialSetup();

// set callback to detect any asset tag change
registerAssetTagChangeCallback();
// set callback to detect any asset tag change
registerAssetTagChangeCallback();

// set async timer to detect if system VPD is published on D-Bus.
SetTimerToDetectSVPDOnDbus();
// set async timer to detect if system VPD is published on D-Bus.
SetTimerToDetectSVPDOnDbus();

// set async timer to detect if VPD collection is done.
SetTimerToDetectVpdCollectionStatus();
// set async timer to detect if VPD collection is done.
SetTimerToDetectVpdCollectionStatus();

// Instantiate GpioMonitor class
m_gpioMonitor = std::make_shared<GpioMonitor>(
m_worker->getSysCfgJsonObj(), m_worker, m_ioContext);
// Instantiate GpioMonitor class
m_gpioMonitor = std::make_shared<GpioMonitor>(m_worker->getSysCfgJsonObj(),
m_worker, m_ioContext);

#endif
// set callback to detect host state change.
registerHostStateChangeCallback();

// For backward compatibility. Should be depricated.
iFace->register_method(
"WriteKeyword",
[this](const sdbusplus::message::object_path i_path,
const std::string i_recordName, const std::string i_keyword,
const types::BinaryVector i_value) -> int {
return this->updateKeyword(
i_path, std::make_tuple(i_recordName, i_keyword, i_value));
});

// Register methods under com.ibm.VPD.Manager interface
iFace->register_method(
"UpdateKeyword",
[this](const types::Path i_vpdPath,
const types::WriteVpdParams i_paramsToWriteData) -> int {
return this->updateKeyword(i_vpdPath, i_paramsToWriteData);
});

iFace->register_method(
"ReadKeyword",
[this](const types::Path i_fruPath,
const types::ReadVpdParams i_paramsToReadData)
-> types::DbusVariantType {
return this->readKeyword(i_fruPath, i_paramsToReadData);
});

iFace->register_method(
"CollectFRUVPD",
[this](const sdbusplus::message::object_path& i_dbusObjPath) {
this->collectSingleFruVpd(i_dbusObjPath);
});

iFace->register_method(
"deleteFRUVPD",
[this](const sdbusplus::message::object_path& i_dbusObjPath) {
this->deleteSingleFruVpd(i_dbusObjPath);
});

iFace->register_method(
"GetExpandedLocationCode",
[this](const std::string& i_unexpandedLocationCode,
uint16_t& i_nodeNumber) -> std::string {
return this->getExpandedLocationCode(i_unexpandedLocationCode,
i_nodeNumber);
});

iFace->register_method("GetFRUsByExpandedLocationCode",
[this](const std::string& i_expandedLocationCode)
-> types::ListOfPaths {
return this->getFrusByExpandedLocationCode(i_expandedLocationCode);
});

iFace->register_method(
"GetFRUsByUnexpandedLocationCode",
[this](const std::string& i_unexpandedLocationCode,
uint16_t& i_nodeNumber) -> types::ListOfPaths {
return this->getFrusByUnexpandedLocationCode(
i_unexpandedLocationCode, i_nodeNumber);
});

iFace->register_method(
"GetHardwarePath",
[this](const sdbusplus::message::object_path& i_dbusObjPath)
-> std::string { return this->getHwPath(i_dbusObjPath); });

iFace->register_method("PerformVPDRecollection",
[this]() { this->performVpdRecollection(); });

// Indicates FRU VPD collection for the system has not started.
iFace->register_property_rw<std::string>(
"CollectionStatus", sdbusplus::vtable::property_::emits_change,
[this](const std::string l_currStatus, const auto&) {
m_vpdCollectionStatus = l_currStatus;
return 0;
}, [this](const auto&) { return m_vpdCollectionStatus; });
}
catch (const std::exception& e)
{
logging::logMessage("VPD-Manager service failed. " +
std::string(e.what()));
throw;
}
// set callback to detect host state change.
registerHostStateChangeCallback();

// For backward compatibility. Should be depricated.
iFace->register_method("WriteKeyword",
[this](const sdbusplus::message::object_path i_path,
const std::string i_recordName,
const std::string i_keyword,
const types::BinaryVector i_value) -> int {
return this->updateKeyword(
i_path, std::make_tuple(i_recordName, i_keyword, i_value));
});

// Register methods under com.ibm.VPD.Manager interface
iFace->register_method(
"UpdateKeyword",
[this](const types::Path i_vpdPath,
const types::WriteVpdParams i_paramsToWriteData) -> int {
return this->updateKeyword(i_vpdPath, i_paramsToWriteData);
});

iFace->register_method("ReadKeyword",
[this](const types::Path i_fruPath,
const types::ReadVpdParams i_paramsToReadData)
-> types::DbusVariantType {
return this->readKeyword(i_fruPath, i_paramsToReadData);
});

iFace->register_method(
"CollectFRUVPD",
[this](const sdbusplus::message::object_path& i_dbusObjPath) {
this->collectSingleFruVpd(i_dbusObjPath);
});

iFace->register_method(
"deleteFRUVPD",
[this](const sdbusplus::message::object_path& i_dbusObjPath) {
this->deleteSingleFruVpd(i_dbusObjPath);
});

iFace->register_method("GetExpandedLocationCode",
[this](const std::string& i_unexpandedLocationCode,
uint16_t& i_nodeNumber) -> std::string {
return this->getExpandedLocationCode(i_unexpandedLocationCode,
i_nodeNumber);
});

iFace->register_method("GetFRUsByExpandedLocationCode",
[this](const std::string& i_expandedLocationCode)
-> types::ListOfPaths {
return this->getFrusByExpandedLocationCode(i_expandedLocationCode);
});

iFace->register_method(
"GetFRUsByUnexpandedLocationCode",
[this](const std::string& i_unexpandedLocationCode,
uint16_t& i_nodeNumber) -> types::ListOfPaths {
return this->getFrusByUnexpandedLocationCode(i_unexpandedLocationCode,
i_nodeNumber);
});

iFace->register_method(
"GetHardwarePath",
[this](const sdbusplus::message::object_path& i_dbusObjPath)
-> std::string { return this->getHwPath(i_dbusObjPath); });

iFace->register_method("PerformVPDRecollection",
[this]() { this->performVpdRecollection(); });

// Indicates FRU VPD collection for the system has not started.
iFace->register_property_rw<std::string>(
"CollectionStatus", sdbusplus::vtable::property_::emits_change,
[this](const std::string l_currStatus, const auto&) {
m_vpdCollectionStatus = l_currStatus;
return 0;
}, [this](const auto&) { return m_vpdCollectionStatus; });
}

#ifdef IBM_SYSTEM
Expand Down Expand Up @@ -189,9 +179,12 @@ void Manager::processAssetTagChangeCallback(sdbusplus::message_t& i_msg)
}
catch (const std::exception& l_ex)
{
// TODO: Log PEL with below description.
logging::logMessage("Asset tag callback update failed with error: " +
std::string(l_ex.what()));
EventLogger::createAsyncPel(
types::ErrorType::InvalidVpdMessage,
types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
"Asset tag callback update failed with error: " +
std::string(l_ex.what()),
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
}
}

Expand Down Expand Up @@ -488,8 +481,11 @@ void Manager::collectSingleFruVpd(
}
catch (const std::exception& l_error)
{
// TODO: Log PEL
logging::logMessage(std::string(l_error.what()));
EventLogger::createAsyncPel(types::ErrorType::InvalidVpdMessage,
types::SeverityType::Informational,
__FILE__, __FUNCTION__, 0,
std::string(l_error.what()), std::nullopt,
std::nullopt, std::nullopt, std::nullopt);
}
}

Expand All @@ -515,8 +511,11 @@ void Manager::deleteSingleFruVpd(
}
catch (const std::exception& l_ex)
{
// TODO: Log PEL
logging::logMessage(l_ex.what());
EventLogger::createAsyncPel(types::ErrorType::InvalidVpdMessage,
types::SeverityType::Informational,
__FILE__, __FUNCTION__, 0, l_ex.what(),
std::nullopt, std::nullopt, std::nullopt,
std::nullopt);
}
}

Expand Down Expand Up @@ -824,8 +823,12 @@ void Manager::hostStateChangeCallBack(sdbusplus::message_t& i_msg)
}
catch (const std::exception& l_ex)
{
// TODO: Log PEL.
logging::logMessage(l_ex.what());
EventLogger::createAsyncPel(
types::ErrorType::InvalidVpdMessage,
types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
"Failed to get Host state change call back. Error: " +
std::string(l_ex.what()),
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
}
}

Expand Down

0 comments on commit 2fffca6

Please sign in to comment.