Skip to content

Commit

Permalink
vpd-tool: Refactoring more option in fixSystemVPD
Browse files Browse the repository at this point in the history
This commit implements following changes in fixSystemVPD command’s more
option:
* Display ‘No mismatch found’ on the console, in case no mismatch
between primary and backup data for each keyword.
* Using switch case instead of if else condition.
* Updating while loop to end the iteration once all keywords are
traversed.

Output:
'''
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       9040-MRX                                                                   9040-MRX                                                                   NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3     VSYS    SE       AIMP10R                                                                    AIMP10R                                                                    NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4     VSYS    SU       0x0004ac1e442c                                                             0x0004ac1e442c                                                             NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5     VSYS    RB       0001                                                                       0001                                                                       NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6     VSYS    WN       C050760B964E                                                               C050760B964E                                                               NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7     VSYS    RG       0x00000000                                                                 0x00000000                                                                 NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8     VSYS    FV                                                                                                                                                             NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9     VCEN    FC       780C-001                                                                   780C-001                                                                   NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10    VCEN    SE       1234567                                                                    1234567                                                                    NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
11    LXR0    LX       0x3100080100300074                                                         0x3100080100300074                                                         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                                                                         S0                                                                         NO
===============================================================================================================================================================================================
No mismatch found.

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 : 7

Skipped the above record-keyword pair. Continue to the next available pair.

===============================================================================================================================================================================================
S.No  Record  Keyword  Backup Data                                                                Primary Data                                                               Data Mismatch
2     VSYS    TM       9040-MRX                                                                   9040-MRX                                                                   NO
===============================================================================================================================================================================================
No mismatch found.

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 : 7

Skipped the above record-keyword pair. Continue to the next available pair.

===============================================================================================================================================================================================
S.No  Record  Keyword  Backup Data                                                                Primary Data                                                               Data Mismatch
3     VSYS    SE       AIMP10R                                                                    AIMP10R                                                                    NO
===============================================================================================================================================================================================
No mismatch found.

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) : 0x3

Write option accepts 2 digit hex numbers. (Ex. 0x1 should be given as 0x01).

===============================================================================================================================================================================================
S.No  Record  Keyword  Backup Data                                                                Primary Data                                                               Data Mismatch
4     VSYS    SU       0x0004ac1e442c                                                             0x0004ac1e442c                                                             NO
===============================================================================================================================================================================================
No mismatch found.

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) : A

Data updated successfully.

===============================================================================================================================================================================================
S.No  Record  Keyword  Backup Data                                                                Primary Data                                                               Data Mismatch
5     VSYS    RB       0001                                                                       0001                                                                       NO
===============================================================================================================================================================================================
No mismatch found.

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
'''
Signed-off-by: Anupama B R <[email protected]>
  • Loading branch information
branupama committed Jan 16, 2025
1 parent 6a8e56f commit 6bb6eb8
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 104 deletions.
2 changes: 2 additions & 0 deletions vpd-tool/include/tool_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ constexpr auto assetInf = "xyz.openbmc_project.Inventory.Decorator.Asset";
constexpr auto objectMapperService = "xyz.openbmc_project.ObjectMapper";
constexpr auto objectMapperObjectPath = "/xyz/openbmc_project/object_mapper";
constexpr auto objectMapperInfName = "xyz.openbmc_project.ObjectMapper";

static constexpr auto OUTLINE_COUNT = 191;
} // namespace constants
} // namespace vpd
221 changes: 117 additions & 104 deletions vpd-tool/src/vpd_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int VpdTool::fixSystemVpd() const noexcept
int l_userSelectedOption = types::UserOption::Exit;
std::cin >> l_userSelectedOption;

std::cout << std::endl << std::string(191, '=') << std::endl;
std::cout << std::endl;

if (types::UserOption::UseBackupDataForAll == l_userSelectedOption)
{
Expand Down Expand Up @@ -827,7 +827,7 @@ void VpdTool::printSystemVpd(
std::cerr << "Invalid JSON to print system VPD" << std::endl;
}

std::string l_outline(191, '=');
std::string l_outline(constants::OUTLINE_COUNT, '=');
std::cout << "\nRestorable record-keyword pairs and their data on backup & "
"primary.\n\n"
<< l_outline << std::endl;
Expand All @@ -843,9 +843,9 @@ void VpdTool::printSystemVpd(

for (const auto& l_aRecordKwInfo : i_parsedJsonObj["backupMap"])
{
if (l_aRecordKwInfo.contains("sourceRecord") ||
l_aRecordKwInfo.contains("sourceKeyword") ||
l_aRecordKwInfo.contains("destinationkeywordValue") ||
if (l_aRecordKwInfo.contains("sourceRecord") &&
l_aRecordKwInfo.contains("sourceKeyword") &&
l_aRecordKwInfo.contains("destinationkeywordValue") &&
l_aRecordKwInfo.contains("sourcekeywordValue"))
{
std::string l_mismatchFound{
Expand All @@ -854,7 +854,7 @@ void VpdTool::printSystemVpd(
? "YES"
: "NO"};

std::string l_splitLine(191, '-');
std::string l_splitLine(constants::OUTLINE_COUNT, '-');

try
{
Expand Down Expand Up @@ -1011,38 +1011,15 @@ int VpdTool::handleMoreOption(
"source path information is missing in JSON");
}

auto updateKeywordValue =
[](std::string io_vpdPath, const std::string& i_recordName,
const std::string& i_keywordName,
const types::BinaryVector& i_keywordValue) -> int {
int l_rc = constants::FAILURE;
int l_slNum = 0;

try
{
auto l_paramsToWrite = std::make_tuple(
i_recordName, i_keywordName, i_keywordValue);
l_rc = utils::writeKeyword(io_vpdPath, l_paramsToWrite);

if (l_rc > 0)
{
std::cout << std::endl
<< "Data updated successfully." << std::endl;
}
}
catch (const std::exception& l_ex)
{
// TODO: Enable log when verbose is enabled.
std::cerr << l_ex.what() << std::endl;
}
return l_rc;
};

do
for (const auto& l_aRecordKwInfo : i_parsedJsonObj["backupMap"])
{
int l_slNum = 0;
bool l_exit = false;
l_rc = constants::SUCCESS;
++l_slNum;

for (const auto& l_aRecordKwInfo : i_parsedJsonObj["backupMap"])
int l_runOnce = 1;
while (l_runOnce--)
{
if (!l_aRecordKwInfo.contains("sourceRecord") ||
!l_aRecordKwInfo.contains("sourceKeyword") ||
Expand All @@ -1053,7 +1030,7 @@ int VpdTool::handleMoreOption(
std::cerr
<< "Source or destination information is missing in the JSON."
<< std::endl;
continue;
break;
}

const std::string l_mismatchFound{
Expand All @@ -1063,7 +1040,10 @@ int VpdTool::handleMoreOption(
: "NO"};

std::cout << std::endl
<< std::left << std::setw(6) << "S.No" << std::left
<< std::string(constants::OUTLINE_COUNT, '=')
<< std::endl;

std::cout << std::left << std::setw(6) << "S.No" << std::left
<< std::setw(8) << "Record" << std::left
<< std::setw(9) << "Keyword" << std::left
<< std::setw(75) << std::setfill(' ') << "Backup Data"
Expand All @@ -1072,7 +1052,7 @@ int VpdTool::handleMoreOption(
<< "Data Mismatch" << std::endl;

std::cout << std::left << std::setw(6)
<< static_cast<int>(++l_slNum) << std::left
<< static_cast<int>(l_slNum) << std::left
<< std::setw(8)
<< l_aRecordKwInfo.value("sourceRecord", "")
<< std::left << std::setw(9)
Expand All @@ -1086,7 +1066,8 @@ int VpdTool::handleMoreOption(
<< std::left << std::setw(14) << l_mismatchFound
<< std::endl;

std::cout << std::string(191, '=') << std::endl;
std::cout << std::string(constants::OUTLINE_COUNT, '=')
<< std::endl;

if (constants::STR_CMP_SUCCESS ==
l_mismatchFound.compare("YES"))
Expand All @@ -1101,6 +1082,7 @@ int VpdTool::handleMoreOption(
}
else
{
std::cout << "No mismatch found." << std::endl << std::endl;
printFixSystemVpdOption(types::UserOption::NewValueOnBoth);
printFixSystemVpdOption(types::UserOption::SkipCurrent);
printFixSystemVpdOption(types::UserOption::Exit);
Expand All @@ -1109,74 +1091,105 @@ int VpdTool::handleMoreOption(
int l_userSelectedOption = types::UserOption::Exit;
std::cin >> l_userSelectedOption;

if (types::UserOption::UseBackupDataForCurrent ==
l_userSelectedOption)
{
l_rc = updateKeywordValue(
l_srcVpdPath, l_aRecordKwInfo["sourceRecord"],
l_aRecordKwInfo["sourceKeyword"],
l_aRecordKwInfo["destinationkeywordValue"]);
}
else if (types::UserOption::UseSystemBackplaneDataForCurrent ==
l_userSelectedOption)
switch (l_userSelectedOption)
{
l_rc = updateKeywordValue(
l_srcVpdPath, l_aRecordKwInfo["sourceRecord"],
l_aRecordKwInfo["sourceKeyword"],
l_aRecordKwInfo["sourcekeywordValue"]);
}
else if (types::UserOption::NewValueOnBoth ==
l_userSelectedOption)
{
std::string l_newValue;
std::cout
<< std::endl
<< "Enter the new value to update on both "
"primary & backup. Value should be in ASCII or "
"in HEX(prefixed with 0x) : ";
std::cin >> l_newValue;
std::cout << std::endl
<< std::string(191, '=') << std::endl;

try
{
l_rc = updateKeywordValue(
l_srcVpdPath, l_aRecordKwInfo["sourceRecord"],
l_aRecordKwInfo["sourceKeyword"],
utils::convertToBinary(l_newValue));
}
catch (const std::exception& l_ex)
case types::UserOption::UseBackupDataForCurrent:
try
{
l_rc = utils::writeKeyword(
l_srcVpdPath,
std::make_tuple(
l_aRecordKwInfo["sourceRecord"],
l_aRecordKwInfo["sourceKeyword"],
l_aRecordKwInfo
["destinationkeywordValue"]));

if (l_rc > 0)
{
std::cout << std::endl
<< "Data updated successfully."
<< std::endl;
}
}
catch (const std::exception& l_ex)
{
// TODO: Enable log when verbose is enabled.
std::cerr << std::endl << l_ex.what() << std::endl;
}
break;
case types::UserOption::UseSystemBackplaneDataForCurrent:
try
{
l_rc = utils::writeKeyword(
l_srcVpdPath,
std::make_tuple(
l_aRecordKwInfo["sourceRecord"],
l_aRecordKwInfo["sourceKeyword"],
l_aRecordKwInfo["sourcekeywordValue"]));

if (l_rc > 0)
{
std::cout << std::endl
<< "Data updated successfully."
<< std::endl;
}
}
catch (const std::exception& l_ex)
{
// TODO: Enable log when verbose is enabled.
std::cerr << std::endl << l_ex.what() << std::endl;
}
break;
case types::UserOption::NewValueOnBoth:
{
// TODO: Enable logging when verbose is enabled.
std::cerr << l_ex.what() << std::endl;
std::string l_newValue;
std::cout
<< std::endl
<< "Enter the new value to update on both "
"primary & backup. Value should be in ASCII or "
"in HEX(prefixed with 0x) : ";
std::cin >> l_newValue;

try
{
l_rc = utils::writeKeyword(
l_srcVpdPath,
std::make_tuple(
l_aRecordKwInfo["sourceRecord"],
l_aRecordKwInfo["sourceKeyword"],
utils::convertToBinary(l_newValue)));

if (l_rc > 0)
{
std::cout << std::endl
<< "Data updated successfully."
<< std::endl;
}
}
catch (const std::exception& l_ex)
{
// TODO: Enable logging when verbose is enabled.
std::cerr << std::endl << l_ex.what() << std::endl;
}
break;
}
}
else if (types::UserOption::SkipCurrent == l_userSelectedOption)
{
std::cout << std::endl
<< "Skipped the above record-keyword pair. "
"Continue to the next available pair."
<< std::endl;
}
else if (types::UserOption::Exit == l_userSelectedOption)
{
std::cout << "Exit successfully" << std::endl;
l_exit = true;
break;
}
else
{
std::cout << "Provide a valid option. Retrying for the "
"current record-keyword pair"
<< std::endl;
}
}
if (l_exit)
{
l_rc = constants::SUCCESS;
break;
}
} while (true);
case types::UserOption::SkipCurrent:
std::cout << std::endl
<< "Skipped the above record-keyword pair. "
"Continue to the next available pair."
<< std::endl;
break;
case types::UserOption::Exit:
std::cout << "Exit successfully" << std::endl;
return constants::SUCCESS;
default:
l_runOnce = 1;
std::cout << "Provide a valid option. Retrying for the "
"current record-keyword pair"
<< std::endl;
} // end switch
} // end while
} // end for
}
catch (const std::exception& l_ex)
{
Expand Down

0 comments on commit 6bb6eb8

Please sign in to comment.