Skip to content

Commit 3d87544

Browse files
committed
vpd-tool: User options for fixSystemVpd command
This commit implements user options for fixSystemVpd command, to fix any mismatch found between source and destination keyword’s value. User can select ‘use backup data’ as an option to update all system backplane keyword’s value with backup keyword’s value or can select ‘use system backplane data’ to update all backup keyword’s value. Output: ‘’’ User selecting Exit option: root@p10bmc:/tmp# ./vpd-tool --fixSystemVPD Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : 0 =============================================================================================================================================================================================== Exit successfully User selecting option1, but there is no mismatch of keywords found in the system: root@p10bmc:/tmp# ./vpd-tool --fixSystemVPD Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : 1 =============================================================================================================================================================================================== No mismatch found for any of the above mentioned record-keyword pair. Exit successfully. User selecting option2, but there is no mismatch of keywords found in the system: root@p10bmc:/tmp# ./vpd-tool --fixSystemVPD Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : 2 =============================================================================================================================================================================================== No mismatch found for any of the above mentioned record-keyword pair. Exit successfully. User selecting non existing option: root@p10bmc:/tmp# ./vpd-tool_option12 --fixSystemVPD Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : 4 =============================================================================================================================================================================================== Provide a valid option. Retry. Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : User selecting option2, where system has mismatch keyword's value for VSYS BR keyword: root@p10bmc:/tmp# vpd-tool -O /system/chassis/motherboard -R VSYS -K BR -r { "/system/chassis/motherboard": { "BR": "12" } } root@p10bmc:/tmp# vpd-tool -O /sys/bus/i2c/drivers/at24/8-0050/eeprom -R VSYS -K BR -r -H { "/sys/bus/i2c/drivers/at24/8-0050/eeprom": { "BR": "S0" } } root@p10bmc:/tmp# ./vpd-tool --fixSystemVPD Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : 2 =============================================================================================================================================================================================== Data updated successfully Data updated successfully for all mismatching record-keyword pairs by choosing their corresponding data from primary VPD. Exit successfully. root@p10bmc:/tmp# vpd-tool -O /system/chassis/motherboard -R VSYS -K BR -r { "/system/chassis/motherboard": { "BR": "S0" } } root@p10bmc:/tmp# vpd-tool -O /sys/bus/i2c/drivers/at24/8-0050/eeprom -R VSYS -K BR -r -H { "/sys/bus/i2c/drivers/at24/8-0050/eeprom": { "BR": "S0" } } User selecting option1, where system has mismatch keyword's value for VSYS BR keyword: root@p10bmc:/tmp# vpd-tool -O /system/chassis/motherboard -R VSYS -K BR -r { "/system/chassis/motherboard": { "BR": "S0" } } root@p10bmc:/tmp# vpd-tool -O /sys/bus/i2c/drivers/at24/8-0050/eeprom -R VSYS -K BR -r -H { "/sys/bus/i2c/drivers/at24/8-0050/eeprom": { "BR": "12" } } root@p10bmc:/tmp# ./vpd-tool --fixSystemVPD Enter 1 => If you choose the data on backup for all mismatching record-keyword pairs Enter 2 => If you choose the data on primary for all mismatching record-keyword pairs Enter 3 => If you wish to explore more options Enter 0 => To exit successfully : 1 =============================================================================================================================================================================================== Data updated successfully Data updated successfully for all mismatching record-keyword pairs by choosing their corresponding data from backup. Exit successfully. root@p10bmc:/tmp# vpd-tool -O /system/chassis/motherboard -R VSYS -K BR -r { "/system/chassis/motherboard": { "BR": "S0" } } root@p10bmc:/tmp# vpd-tool -O /sys/bus/i2c/drivers/at24/8-0050/eeprom -R VSYS -K BR -r -H { "/sys/bus/i2c/drivers/at24/8-0050/eeprom": { "BR": "S0" } } ‘’’ Signed-off-by: Anupama B R <[email protected]>
1 parent 720f4d0 commit 3d87544

File tree

2 files changed

+153
-6
lines changed

2 files changed

+153
-6
lines changed

vpd-tool/include/vpd_tool.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ class VpdTool
140140
*/
141141
void printSystemVpd(const nlohmann::json& i_parsedJsonObj) const noexcept;
142142

143+
/**
144+
* @brief API to update keyword's value.
145+
*
146+
* API iterates the given JSON object for all record-keyword pairs, if there
147+
* is any mismatch between source and destination keyword's value, API calls
148+
* the utils::writeKeyword API to update keyword's value.
149+
*
150+
* Note: writeKeyword API, internally updates primary, backup, redundant
151+
* EEPROM paths(if exists) with the given keyword's value.
152+
*
153+
* @param i_parsedJsonObj - Parsed JSON object.
154+
* @param i_useBackupData - Specifies whether to use source or destination
155+
* keyword's value to update the keyword's value.
156+
*
157+
* @return On success return 0, otherwise return -1.
158+
*/
159+
int updateAllKeywords(const nlohmann::json& i_parsedJsonObj,
160+
bool i_useBackupData) const noexcept;
161+
143162
public:
144163
/**
145164
* @brief Read keyword value.

vpd-tool/src/vpd_tool.cpp

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,45 @@ int VpdTool::fixSystemVpd() const noexcept
254254

255255
printSystemVpd(l_backupRestoreCfgJsonObj);
256256

257-
printFixSystemVpdOption(types::UserOption::UseBackupDataForAll);
258-
printFixSystemVpdOption(types::UserOption::UseSystemBackplaneDataForAll);
259-
printFixSystemVpdOption(types::UserOption::MoreOptions);
260-
printFixSystemVpdOption(types::UserOption::Exit);
257+
do
258+
{
259+
printFixSystemVpdOption(types::UserOption::UseBackupDataForAll);
260+
printFixSystemVpdOption(
261+
types::UserOption::UseSystemBackplaneDataForAll);
262+
printFixSystemVpdOption(types::UserOption::MoreOptions);
263+
printFixSystemVpdOption(types::UserOption::Exit);
264+
265+
int l_userSelectedOption = types::UserOption::Exit;
266+
std::cin >> l_userSelectedOption;
267+
268+
std::cout << std::endl << std::string(191, '=') << std::endl;
261269

262-
l_rc = constants::SUCCESS;
263-
// ToDo: Implementation needs to be added
270+
if (types::UserOption::UseBackupDataForAll == l_userSelectedOption)
271+
{
272+
l_rc = updateAllKeywords(l_backupRestoreCfgJsonObj, true);
273+
break;
274+
}
275+
else if (types::UserOption::UseSystemBackplaneDataForAll ==
276+
l_userSelectedOption)
277+
{
278+
l_rc = updateAllKeywords(l_backupRestoreCfgJsonObj, false);
279+
break;
280+
}
281+
else if (types::UserOption::MoreOptions == l_userSelectedOption)
282+
{
283+
// ToDo: Implementation needs to be added
284+
break;
285+
}
286+
else if (types::UserOption::Exit == l_userSelectedOption)
287+
{
288+
std::cout << "Exit successfully" << std::endl;
289+
break;
290+
}
291+
else
292+
{
293+
std::cout << "Provide a valid option. Retry." << std::endl;
294+
}
295+
} while (true);
264296

265297
return l_rc;
266298
}
@@ -797,4 +829,100 @@ void VpdTool::printSystemVpd(
797829
}
798830
}
799831
}
832+
833+
int VpdTool::updateAllKeywords(const nlohmann::json& i_parsedJsonObj,
834+
bool i_useBackupData) const noexcept
835+
{
836+
int l_rc = constants::FAILURE;
837+
838+
if (i_parsedJsonObj.empty() || !i_parsedJsonObj.contains("source") ||
839+
!i_parsedJsonObj.contains("backupMap"))
840+
{
841+
// TODO: Enable logging when verbose is enabled.
842+
std::cerr << "Invalid JSON" << std::endl;
843+
return l_rc;
844+
}
845+
846+
std::string l_srcVpdPath;
847+
if (auto l_vpdPath = i_parsedJsonObj["source"].value("hardwarePath", "");
848+
!l_vpdPath.empty())
849+
{
850+
l_srcVpdPath = l_vpdPath;
851+
}
852+
else if (auto l_vpdPath = i_parsedJsonObj["source"].value("inventoryPath",
853+
"");
854+
!l_vpdPath.empty())
855+
{
856+
l_srcVpdPath = l_vpdPath;
857+
}
858+
else
859+
{
860+
// TODO: Enable logging when verbose is enabled.
861+
std::cerr << "source path information is missing in JSON" << std::endl;
862+
return l_rc;
863+
}
864+
865+
bool l_anyMismatchFound = false;
866+
for (const auto& l_aRecordKwInfo : i_parsedJsonObj["backupMap"])
867+
{
868+
if (!l_aRecordKwInfo.contains("sourceRecord") ||
869+
!l_aRecordKwInfo.contains("sourceKeyword") ||
870+
!l_aRecordKwInfo.contains("destinationkeywordValue") ||
871+
!l_aRecordKwInfo.contains("sourcekeywordValue"))
872+
{
873+
// TODO: Enable logging when verbose is enabled.
874+
std::cerr << "Missing required information in the JSON"
875+
<< std::endl;
876+
continue;
877+
}
878+
879+
if (l_aRecordKwInfo["sourcekeywordValue"] !=
880+
l_aRecordKwInfo["destinationkeywordValue"])
881+
{
882+
l_anyMismatchFound = true;
883+
884+
auto l_keywordValue =
885+
i_useBackupData ? l_aRecordKwInfo["destinationkeywordValue"]
886+
: l_aRecordKwInfo["sourcekeywordValue"];
887+
888+
auto l_paramsToWrite = std::make_tuple(
889+
l_aRecordKwInfo["sourceRecord"],
890+
l_aRecordKwInfo["sourceKeyword"], l_keywordValue);
891+
892+
try
893+
{
894+
l_rc = utils::writeKeyword(l_srcVpdPath, l_paramsToWrite);
895+
if (l_rc > 0)
896+
{
897+
l_rc = constants::SUCCESS;
898+
}
899+
}
900+
catch (const std::exception& l_ex)
901+
{
902+
// TODO: Enable logging when verbose is enabled.
903+
std::cerr << "write keyword failed for record: "
904+
<< l_aRecordKwInfo["sourceRecord"]
905+
<< ", keyword: " << l_aRecordKwInfo["sourceKeyword"]
906+
<< ", error: " << l_ex.what() << std::ends;
907+
}
908+
}
909+
}
910+
911+
std::string l_dataUsed = (i_useBackupData ? "data from backup"
912+
: "data from primary VPD");
913+
if (l_anyMismatchFound)
914+
{
915+
std::cout << "Data updated successfully for all mismatching "
916+
"record-keyword pairs by choosing their corresponding "
917+
<< l_dataUsed << ". Exit successfully." << std::endl;
918+
}
919+
else
920+
{
921+
std::cout << "No mismatch found for any of the above mentioned "
922+
"record-keyword pair. Exit successfully."
923+
<< std::endl;
924+
}
925+
926+
return l_rc;
927+
}
800928
} // namespace vpd

0 commit comments

Comments
 (0)