-
Notifications
You must be signed in to change notification settings - Fork 20
vpd-tool: Add module VPD sanity check #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1120
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,17 @@ class ParserInterface | |
return -1; | ||
} | ||
|
||
/** | ||
* @brief Virtual API to perform sanity check on EEPROM passed via | ||
* constructor of parser class. | ||
* | ||
* @return 0 on Success, -1 on Failure. | ||
*/ | ||
virtual int sanityChecker() | ||
{ | ||
return -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use constants SUCCESS or FAILURE. Currently ipz parser class is implementing its own sanityChecker, |
||
} | ||
|
||
/** | ||
* @brief Virtual destructor. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -996,4 +996,38 @@ bool IpzVpdParser::processInvalidRecords( | |
} | ||
return l_rc; | ||
} | ||
|
||
int IpzVpdParser::sanityChecker() | ||
{ | ||
try | ||
{ | ||
logging::logMessage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep necessary logs only. This log is not required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are not sure, it ran for 1 or more eeproms( redundant), in that case this log will be a proof. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
"Performing sanity check for file path: " + m_vpdFilePath); | ||
auto l_itrToVPD = m_vpdVector.cbegin(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l_itrToVpd |
||
|
||
// Check vaidity of VHDR record | ||
checkHeader(l_itrToVPD); | ||
|
||
// Read the table of contents | ||
const auto l_ptLen = readTOC(l_itrToVPD); | ||
|
||
// Read the table of contents record, to get offsets to other records. | ||
auto l_result = readPT(l_itrToVPD, l_ptLen); | ||
|
||
if (!processInvalidRecords(l_result.second)) | ||
{ | ||
logging::logMessage("Failed to process invalid records for [" + | ||
m_vpdFilePath + "]"); | ||
} | ||
return constants::SUCCESS; | ||
} | ||
catch (const std::exception& l_ex) | ||
{ | ||
logging::logMessage("Sanity Check failed for EEPROM [" + m_vpdFilePath + | ||
"], reason: " + std::string(l_ex.what())); | ||
|
||
Alpana07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return constants::FAILURE; | ||
} | ||
} | ||
|
||
} // namespace vpd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,11 @@ Manager::Manager( | |
this->performVpdRecollection(); | ||
}); | ||
|
||
iFace->register_method( | ||
"performVpdSanityCheck", [this](const types::Path& i_fruPath) { | ||
return this->performVpdSanityCheck(i_fruPath); | ||
}); | ||
|
||
// Indicates FRU VPD collection for the system has not started. | ||
iFace->register_property_rw<std::string>( | ||
"CollectionStatus", sdbusplus::vtable::property_::emits_change, | ||
|
@@ -640,4 +645,37 @@ void Manager::performVpdRecollection() | |
m_worker->performVpdRecollection(); | ||
} | ||
} | ||
|
||
int Manager::performVpdSanityCheck(const types::Path& i_fruPath) noexcept | ||
{ | ||
try | ||
{ | ||
if (i_fruPath.empty()) | ||
{ | ||
throw std::runtime_error("Given FRU path is empty"); | ||
} | ||
|
||
nlohmann::json l_sysCfgJsonObj{}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can move this after if condition, as there is no use in case if condition gets executed. |
||
|
||
if (m_worker.get() == nullptr) | ||
{ | ||
throw std::runtime_error( | ||
"Worker object not found. Can't perform VPD Sanity check."); | ||
} | ||
l_sysCfgJsonObj = m_worker->getSysCfgJsonObj(); | ||
|
||
std::shared_ptr<Parser> l_parserObj = | ||
std::make_shared<Parser>(i_fruPath, l_sysCfgJsonObj); | ||
|
||
return l_parserObj->vpdSanityCheck(); | ||
} | ||
catch (const std::exception& l_exception) | ||
{ | ||
logging::logMessage("Sanity check failed for file[" + i_fruPath + | ||
"], reason: " + std::string(l_exception.what())); | ||
|
||
return constants::FAILURE; | ||
} | ||
} | ||
|
||
} // namespace vpd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,4 +346,64 @@ int Parser::updateVpdKeywordOnHardware( | |
return l_bytesUpdatedOnHardware; | ||
} | ||
|
||
int Parser::vpdSanityCheck() noexcept | ||
{ | ||
int l_rc = constants::SUCCESS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable can be moved inside try, as there is no use outside of the try-catch block. |
||
uint16_t l_errCode = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move the scope of this variable, just before where it gets consumed. |
||
try | ||
{ | ||
std::shared_ptr<vpd::ParserInterface> l_parser = getVpdParserInstance(); | ||
|
||
if (l_parser->sanityChecker() == constants::FAILURE) | ||
{ | ||
logging::logMessage("Sanity checker failed for " + m_vpdFilePath); | ||
l_rc = constants::FAILURE; | ||
} | ||
logging::logMessage("Sanity checker Passed for " + m_vpdFilePath); | ||
|
||
// Collect redundant FRU path | ||
const auto l_redundantPath = | ||
jsonUtility::getRedundantEepromPathFromJson( | ||
m_parsedJson, m_vpdFilePath, l_errCode); | ||
if (l_errCode) | ||
{ | ||
logging::logMessage( | ||
"Failed to get redundant EEPROM path for FRU [" + | ||
m_vpdFilePath + | ||
"], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode)); | ||
return l_rc; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we returning success, in case get redundant eeprom path call fails ? |
||
} | ||
|
||
if (l_redundantPath.empty()) | ||
{ | ||
logging::logMessage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of this log, as most of the FRUs' don't have redundant EEPROM path, returning from this API is enough. |
||
"No redundant path found for FRU [" + m_vpdFilePath + "]"); | ||
return l_rc; | ||
} | ||
// Read the VPD data into a vector. | ||
vpdSpecificUtility::getVpdDataInVector(l_redundantPath, m_vpdVector, | ||
m_vpdStartOffset); | ||
|
||
// This will detect the type of parser required. | ||
std::shared_ptr<vpd::ParserInterface> l_parser1 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why l_parser1 as we dont have multiple parser objects here. |
||
ParserFactory::getParser(m_vpdVector, l_redundantPath, | ||
m_vpdStartOffset); | ||
|
||
if (l_parser1->sanityChecker() == constants::FAILURE) | ||
{ | ||
logging::logMessage("Sanity checker failed for " + l_redundantPath); | ||
l_rc = constants::FAILURE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as there is no return from inside if condition, both fail and success log will be printed, in case sanity check failed for the FRU. |
||
} | ||
logging::logMessage("Sanity checker Passed for " + l_redundantPath); | ||
|
||
return l_rc; | ||
} | ||
catch (const std::exception& l_exception) | ||
{ | ||
logging::logMessage("Sanity Check failed for EEPROM [" + m_vpdFilePath + | ||
"], reason: " + std::string(l_exception.what())); | ||
return constants::FAILURE; | ||
} | ||
} | ||
|
||
} // namespace vpd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1558,4 +1558,49 @@ void VpdTool::clearVpdDumpDir() const noexcept | |
} | ||
} | ||
|
||
int VpdTool::performSanityCheck(const std::string& i_fruPath) noexcept | ||
{ | ||
try | ||
{ | ||
nlohmann::json l_parsedJson; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where this variable used ? |
||
if (i_fruPath.empty()) | ||
{ | ||
std::cerr << "Provided empty path,please provide valid EEPROM path" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API should just say input is empty. |
||
<< std::endl; | ||
return vpd::constants::FAILURE; | ||
} | ||
|
||
int l_returnValue; | ||
auto l_bus = sdbusplus::bus::new_default(); | ||
|
||
auto l_method = l_bus.new_method_call( | ||
constants::vpdManagerService, constants::vpdManagerObjectPath, | ||
constants::vpdManagerInfName, "performVpdSanityCheck"); | ||
|
||
l_method.append(i_fruPath); | ||
auto l_result = l_bus.call(l_method); | ||
l_result.read(l_returnValue); | ||
|
||
if (l_returnValue == vpd::constants::FAILURE) | ||
{ | ||
std::cerr | ||
<< "EEPROM sanity check has failed. Check PELs for details" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we logging any PEL for this command. ? |
||
<< std::endl; | ||
return vpd::constants::FAILURE; | ||
} | ||
|
||
std::cout << "EEPROM sanity checking is Successful." << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Sanity checking is Successful" is enough. |
||
return vpd::constants::SUCCESS; | ||
} | ||
catch (const std::exception& l_ex) | ||
{ | ||
std::cerr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be |
||
<< "EEPROM sanity check failed. Exception caught for the reason - " | ||
<< std::endl | ||
<< l_ex.what() << std::endl; | ||
|
||
return vpd::constants::FAILURE; | ||
} | ||
} | ||
|
||
} // namespace vpd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,7 +279,9 @@ void updateFooter(CLI::App& i_app) | |
" From DBus to console in Table format: " | ||
"vpd-tool -i -t\n" | ||
"Force Reset:\n" | ||
" vpd-tool --forceReset\n"); | ||
" vpd-tool --forceReset\n" | ||
"Vpd sanity check:\n" | ||
" vpd-tool --sanityCheck -P <EEPROM Path> \n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It showed as new option -P, I see Souvik comment for the same. So it should be |
||
} | ||
|
||
int main(int argc, char** argv) | ||
|
@@ -359,6 +361,13 @@ int main(int argc, char** argv) | |
"--forceReset, -f, -F", | ||
"Force collect for hardware. CAUTION: Developer only option."); | ||
|
||
auto l_sanityCheckFlag = | ||
l_app | ||
.add_flag( | ||
"--sanityCheck", | ||
"Performs sanity check for given EEPROM path. If any redundant EEPROM is found for that FRU in system config json, it will validate that as well.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log will be printed under Options: in help section, we should just say what this command do precisely. Please take a look how other commands are printed when vpd-tool is executed. Can it be |
||
->needs(l_objectOption); | ||
|
||
CLI11_PARSE(l_app, argc, argv); | ||
|
||
if (checkOptionValuePair(l_objectOption, l_vpdPath, l_recordOption, | ||
|
@@ -432,6 +441,19 @@ int main(int argc, char** argv) | |
return forceReset(); | ||
} | ||
|
||
if (!l_sanityCheckFlag->empty()) | ||
{ | ||
if (l_objectOption->empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checkOptionValuePair() is already taking care of input validation. |
||
{ | ||
std::cerr << "Please provide EEPROM path.\nUse --object/-O " | ||
"to give EEPROM path. Refer --help." | ||
<< std::endl; | ||
return vpd::constants::FAILURE; | ||
} | ||
|
||
vpd::VpdTool l_vpdToolObj; | ||
return l_vpdToolObj.performSanityCheck(l_vpdPath); | ||
} | ||
std::cout << l_app.help() << std::endl; | ||
return vpd::constants::FAILURE; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.