1 #include "inventory_backup_handler.hpp"
2
3 #include "error_codes.hpp"
4 #include "utility/common_utility.hpp"
5
checkInventoryBackupPath(uint16_t & o_errCode) const6 bool InventoryBackupHandler::checkInventoryBackupPath(
7 uint16_t& o_errCode) const noexcept
8 {
9 bool l_rc{false};
10 o_errCode = 0;
11 try
12 {
13 /* TODO:
14 Check inventory backup path to see if it
15 has sub directories with inventory backup data and return true if so.
16 */
17 }
18 catch (const std::exception& l_ex)
19 {
20 o_errCode = vpd::error_code::STANDARD_EXCEPTION;
21
22 m_logger->logMessage("Failed to check inventory path. Error: " +
23 std::string(l_ex.what()));
24 }
25 return l_rc;
26 }
27
restoreInventoryBackupData(uint16_t & o_errCode) const28 bool InventoryBackupHandler::restoreInventoryBackupData(
29 uint16_t& o_errCode) const noexcept
30 {
31 bool l_rc{false};
32 o_errCode = 0;
33 try
34 {
35 if (!checkInventoryBackupPath(o_errCode))
36 {
37 if (o_errCode)
38 {
39 throw std::runtime_error(
40 "Failed to check if inventory backup path exists. Error: " +
41 vpd::commonUtility::getErrCodeMsg(o_errCode));
42 }
43 return l_rc;
44 }
45
46 /* TODO:
47 1. Iterate through directories under
48 /var/lib/phosphor-data-sync/bmc_data_bkp/
49 2. Extract the object path and interface information
50 3. Restore the data to inventory manager persisted path.
51 */
52 }
53 catch (const std::exception& l_ex)
54 {
55 const vpd::types::PelInfoTuple l_pelInfo{
56 vpd::types::ErrorType::FirmwareError,
57 vpd::types::SeverityType::Warning,
58 0,
59 std::nullopt,
60 std::nullopt,
61 std::nullopt,
62 std::nullopt};
63
64 m_logger->logMessage("Failed to restore inventory backup data from [" +
65 m_inventoryBackupPath.string() + "] to [" +
66 m_inventoryPrimaryPath.string() +
67 "] Error: " + std::string(l_ex.what()),
68 vpd::PlaceHolder::PEL, &l_pelInfo);
69
70 o_errCode = vpd::error_code::STANDARD_EXCEPTION;
71 }
72 return l_rc;
73 }
74
clearInventoryBackupData(uint16_t & o_errCode) const75 bool InventoryBackupHandler::clearInventoryBackupData(
76 uint16_t& o_errCode) const noexcept
77 {
78 bool l_rc{false};
79 o_errCode = 0;
80 try
81 {
82 /* TODO:
83 Clear all directories under inventory backup path
84 */
85 }
86 catch (const std::exception& l_ex)
87 {
88 const vpd::types::PelInfoTuple l_pelInfo{
89 vpd::types::ErrorType::FirmwareError,
90 vpd::types::SeverityType::Warning,
91 0,
92 std::nullopt,
93 std::nullopt,
94 std::nullopt,
95 std::nullopt};
96
97 m_logger->logMessage(
98 "Failed to clear inventory backup data from path [" +
99 m_inventoryBackupPath.string() +
100 "]. Error: " + std::string(l_ex.what()),
101 vpd::PlaceHolder::PEL, &l_pelInfo);
102
103 o_errCode = vpd::error_code::STANDARD_EXCEPTION;
104 }
105 return l_rc;
106 }
107
restartInventoryManagerService(uint16_t & o_errCode) const108 bool InventoryBackupHandler::restartInventoryManagerService(
109 uint16_t& o_errCode) const noexcept
110 {
111 bool l_rc{false};
112 o_errCode = 0;
113 try
114 {
115 /* TODO:
116 1. Restart inventory manager service, with a re-try limit of 3
117 attempts
118 2. If above step fails, check inventory manager service state
119 3. If service is in running state, then log critical PEL and go for
120 re-collection. If not running then along with critical PEL, fail this
121 service as well.
122 */
123 }
124 catch (const std::exception& l_ex)
125 {
126 m_logger->logMessage("Failed to restart inventory manager service " +
127 m_inventoryManagerServiceName +
128 ". Error: " + std::string(l_ex.what()));
129 o_errCode = vpd::error_code::STANDARD_EXCEPTION;
130 }
131 return l_rc;
132 }
133