Skip to content

Commit 546178e

Browse files
committed
vpd-tool: implement more option of fixSystemVPD
This commit implements more options for fixSystemVpd command, to update keyword’s value on primary and backup VPD, by iterating each keyword. User will be provided following keyword update option in case of any mismatch between primary and backup data: * Choose backup data as the right value. * Choose system backplane data as the right value. * Choose new value to update on both primary and backup. In case there is no mismatch: * Choose new value to update on both primary and backup. Output ''' ./vpd-tool --fixSystemVPD Restorable record-keyword pairs and their data on backup & primary. =============================================================================================================================================================================================== S.No Record Keyword Data On Backup Data On Primary Data Mismatch =============================================================================================================================================================================================== 1 VSYS BR S0 12 YES ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 VSYS TM NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 3 VSYS SE NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 4 VSYS SU NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5 VSYS RB NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 6 VSYS WN NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7 VSYS RG 0x36370000 0x36370000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 8 VSYS FV fw1010.00-01 fw1010.00-01 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 9 VCEN FC 78DA-001 78DA-001 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 10 VCEN SE 139EF60 139EF60 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 11 LXR0 LX 0x3100040100300071 0x3100040100300071 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12 UTIL D0 0x01 0x01 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 13 UTIL D1 0x00 0x00 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 14 UTIL F0 0x0000000000000000 0x0000000000000000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 15 UTIL F5 0x00000000000000000000000000000000 0x00000000000000000000000000000000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 16 UTIL F6 0x00000000000000000000000000000000 0x00000000000000000000000000000000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 : 3 =============================================================================================================================================================================================== S.No Record Keyword Backup Data Primary Data Data Mismatch 1 VSYS BR S0 12 YES =============================================================================================================================================================================================== Enter 4 => If you choose the data on backup as the right value Enter 5 => If you choose the data on primary as the right value Enter 6 => If you wish to enter a new value to update both on backup and primary Enter 7 => If you wish to skip the above record-keyword pair Enter 0 => To exit successfully : 4 Data updated successfully. S.No Record Keyword Backup Data Primary Data Data Mismatch 2 VSYS TM NO =============================================================================================================================================================================================== Enter 6 => If you wish to enter a new value to update both on backup and primary Enter 7 => If you wish to skip the above record-keyword pair Enter 0 => To exit successfully : 6 Enter the new value to update on both primary & backup. Value should be in ASCII or in HEX(prefixed with 0x) : 0x3132 =============================================================================================================================================================================================== Data updated successfully. S.No Record Keyword Backup Data Primary Data Data Mismatch 3 VSYS SE NO =============================================================================================================================================================================================== Enter 6 => If you wish to enter a new value to update both on backup and primary Enter 7 => If you wish to skip the above record-keyword pair Enter 0 => To exit successfully : 6 Enter the new value to update on both primary & backup. Value should be in ASCII or in HEX(prefixed with 0x) : "TEST" =============================================================================================================================================================================================== Data updated successfully. S.No Record Keyword Backup Data Primary Data Data Mismatch 4 VSYS SU NO =============================================================================================================================================================================================== Enter 6 => If you wish to enter a new value to update both on backup and primary Enter 7 => If you wish to skip the above record-keyword pair Enter 0 => To exit successfully : 0 Exit successfully Check updated values: root@p10bmc:/tmp# ./vpd-tool --fixSystemVPD Restorable record-keyword pairs and their data on backup & primary. =============================================================================================================================================================================================== S.No Record Keyword Data On Backup Data On Primary Data Mismatch =============================================================================================================================================================================================== 1 VSYS BR S0 S0 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 VSYS TM 12 12 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 3 VSYS SE "TEST" "TEST" NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 4 VSYS SU NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5 VSYS RB NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 6 VSYS WN NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7 VSYS RG 0x36370000 0x36370000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 8 VSYS FV fw1010.00-01 fw1010.00-01 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 9 VCEN FC 78DA-001 78DA-001 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 10 VCEN SE 139EF60 139EF60 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 11 LXR0 LX 0x3100040100300071 0x3100040100300071 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12 UTIL D0 0x01 0x01 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 13 UTIL D1 0x00 0x00 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 14 UTIL F0 0x0000000000000000 0x0000000000000000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 15 UTIL F5 0x00000000000000000000000000000000 0x00000000000000000000000000000000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 16 UTIL F6 0x00000000000000000000000000000000 0x00000000000000000000000000000000 NO ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 ''' Signed-off-by: Anupama B R <[email protected]>
1 parent c4c1359 commit 546178e

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

vpd-tool/src/vpd_tool.cpp

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,53 @@ int VpdTool::handleMoreOption(
991991
throw std::runtime_error("Invalid JSON");
992992
}
993993

994-
while (true)
994+
std::string l_srcVpdPath;
995+
996+
if (auto l_vpdPath = i_parsedJsonObj["source"].value("hardwarePath",
997+
"");
998+
!l_vpdPath.empty())
999+
{
1000+
l_srcVpdPath = l_vpdPath;
1001+
}
1002+
else if (auto l_vpdPath =
1003+
i_parsedJsonObj["source"].value("inventoryPath", "");
1004+
!l_vpdPath.empty())
1005+
{
1006+
l_srcVpdPath = l_vpdPath;
1007+
}
1008+
else
1009+
{
1010+
throw std::runtime_error(
1011+
"source path information is missing in JSON");
1012+
}
1013+
1014+
auto updateKeywordValue =
1015+
[](std::string io_vpdPath, const std::string& i_recordName,
1016+
const std::string& i_keywordName,
1017+
const types::BinaryVector& i_keywordValue) -> int {
1018+
int l_rc = constants::FAILURE;
1019+
1020+
try
1021+
{
1022+
auto l_paramsToWrite = std::make_tuple(
1023+
i_recordName, i_keywordName, i_keywordValue);
1024+
l_rc = utils::writeKeyword(io_vpdPath, l_paramsToWrite);
1025+
1026+
if (l_rc > 0)
1027+
{
1028+
std::cout << std::endl
1029+
<< "Data updated successfully." << std::endl;
1030+
}
1031+
}
1032+
catch (const std::exception& l_ex)
1033+
{
1034+
// TODO: Enable log when verbose is enabled.
1035+
std::cerr << l_ex.what() << std::endl;
1036+
}
1037+
return l_rc;
1038+
};
1039+
1040+
do
9951041
{
9961042
int l_slNum = 0;
9971043
bool l_exit = false;
@@ -1066,17 +1112,44 @@ int VpdTool::handleMoreOption(
10661112
if (types::UserOption::UseBackupDataForCurrent ==
10671113
l_userSelectedOption)
10681114
{
1069-
// ToDo: Implementation needs to be added
1115+
l_rc = updateKeywordValue(
1116+
l_srcVpdPath, l_aRecordKwInfo["sourceRecord"],
1117+
l_aRecordKwInfo["sourceKeyword"],
1118+
l_aRecordKwInfo["destinationkeywordValue"]);
10701119
}
10711120
else if (types::UserOption::UseSystemBackplaneDataForCurrent ==
10721121
l_userSelectedOption)
10731122
{
1074-
// ToDo: Implementation needs to be added
1123+
l_rc = updateKeywordValue(
1124+
l_srcVpdPath, l_aRecordKwInfo["sourceRecord"],
1125+
l_aRecordKwInfo["sourceKeyword"],
1126+
l_aRecordKwInfo["sourcekeywordValue"]);
10751127
}
10761128
else if (types::UserOption::NewValueOnBoth ==
10771129
l_userSelectedOption)
10781130
{
1079-
// ToDo: Implementation needs to be added
1131+
std::string l_newValue;
1132+
std::cout
1133+
<< std::endl
1134+
<< "Enter the new value to update on both "
1135+
"primary & backup. Value should be in ASCII or "
1136+
"in HEX(prefixed with 0x) : ";
1137+
std::cin >> l_newValue;
1138+
std::cout << std::endl
1139+
<< std::string(191, '=') << std::endl;
1140+
1141+
try
1142+
{
1143+
l_rc = updateKeywordValue(
1144+
l_srcVpdPath, l_aRecordKwInfo["sourceRecord"],
1145+
l_aRecordKwInfo["sourceKeyword"],
1146+
utils::convertToBinary(l_newValue));
1147+
}
1148+
catch (const std::exception& l_ex)
1149+
{
1150+
// TODO: Enable logging when verbose is enabled.
1151+
std::cerr << l_ex.what() << std::endl;
1152+
}
10801153
}
10811154
else if (types::UserOption::SkipCurrent == l_userSelectedOption)
10821155
{
@@ -1103,7 +1176,7 @@ int VpdTool::handleMoreOption(
11031176
l_rc = constants::SUCCESS;
11041177
break;
11051178
}
1106-
}
1179+
} while (true);
11071180
}
11081181
catch (const std::exception& l_ex)
11091182
{

0 commit comments

Comments
 (0)