Skip to content
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

vpd-tool: Refactoring more option in fixSystemVPD #591

Open
wants to merge 1 commit into
base: 1110
Choose a base branch
from

Conversation

branupama
Copy link

@branupama branupama commented Jan 15, 2025

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

}
catch (const std::exception& l_ex)
case types::UserOption::UseBackupDataForCurrent:
try
Copy link

@souvik1914581 souvik1914581 Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following block is being used in multiple places:

try{ utils::writeKeyword(); } catch() { }

This block can be put inside a method or a lambda to make the code more readable.

Copy link
Author

@branupama branupama Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was there in lambda function(line 1014), I removed that added in place.
Bcz, it will be useful only for UseBackupDataForCurrent & UseSystemBackplaneDataForCurrent case.
for case types::UserOption::NewValueOnBoth: need to add another try&catch block as it need to call utils::convertToBinary which can throw exception.

{
int l_slNum = 0;
bool l_exit = false;
l_rc = constants::SUCCESS;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is l_rc being set to SUCCESS by default?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case user skip, it should be considered as success

@@ -1072,7 +1050,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the static_cast<>() needed? l_slNum is an int?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes needed, along with std::setw(), passing normal number after that is not working.

"in HEX(prefixed with 0x) : ";
std::cin >> l_newValue;
std::cout << std::endl
<< std::string(191, '=') << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a constexpr variable for 191?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -1072,7 +1050,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intention of this code block is to print data in tabular format, I suggest using class Table in vpd_utils.hpp

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update that as another PR.

std::cout << "Exit successfully" << std::endl;
return constants::SUCCESS;
default:
l_runOnce = 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how long can we allow the user to provide invalid option?
can we have a count?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no count for how long user can give invalid option.
user can choose 0 to exit from the application

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants