Update keyword’s value on primary or backup path
This commit adds the stub API in BackupAndRestore, to update keyword’s
value on backup or primary path. The stub API is triggered when
vpd-manager’s interface method UpdateKeyword/WriteKeyword is triggered.
This commit also implements using shared pointer to hold the
BackupAndRestore object in manager, and changes are made to use same in
the manager.
Change-Id: I078d28d1bb3e2cc13ae38a75543c3208ffb5cf3f
Signed-off-by: Anupama B R <anupama.b.r1@ibm.com>
diff --git a/vpd-manager/src/backup_restore.cpp b/vpd-manager/src/backup_restore.cpp
index e275ea2..d6a8a34 100644
--- a/vpd-manager/src/backup_restore.cpp
+++ b/vpd-manager/src/backup_restore.cpp
@@ -394,4 +394,40 @@
{
m_backupAndRestoreStatus = i_status;
}
+
+int BackupAndRestore::updateKeywordOnPrimaryOrBackupPath(
+ const std::string& i_fruPath,
+ [[maybe_unused]] const types::WriteVpdParams& i_paramsToWriteData)
+ const noexcept
+{
+ if (i_fruPath.empty())
+ {
+ logging::logMessage("Given FRU path is empty.");
+ return constants::FAILURE;
+ }
+
+ if (m_backupAndRestoreCfgJsonObj.contains("source") &&
+ m_backupAndRestoreCfgJsonObj["source"].value("hardwarePath", "") ==
+ i_fruPath &&
+ m_backupAndRestoreCfgJsonObj.contains("destination") &&
+ !m_backupAndRestoreCfgJsonObj["destination"]
+ .value("hardwarePath", "")
+ .empty())
+ {
+ // ToDo implementation needs to be added
+ }
+ else if (m_backupAndRestoreCfgJsonObj.contains("destination") &&
+ m_backupAndRestoreCfgJsonObj["destination"].value(
+ "hardwarePath", "") == i_fruPath &&
+ m_backupAndRestoreCfgJsonObj.contains("source") &&
+ !m_backupAndRestoreCfgJsonObj["source"]
+ .value("hardwarePath", "")
+ .empty())
+ {
+ // ToDo implementation needs to be added
+ }
+
+ return constants::SUCCESS;
+}
+
} // namespace vpd
diff --git a/vpd-manager/src/manager.cpp b/vpd-manager/src/manager.cpp
index 37fe02b..09d8b85 100644
--- a/vpd-manager/src/manager.cpp
+++ b/vpd-manager/src/manager.cpp
@@ -2,7 +2,6 @@
#include "manager.hpp"
-#include "backup_restore.hpp"
#include "constants.hpp"
#include "exceptions.hpp"
#include "logger.hpp"
@@ -61,6 +60,14 @@
// Set up minimal things that is needed before bus name is claimed.
m_worker->performInitialSetup();
+ const nlohmann::json& l_sysCfgJsonObj = m_worker->getSysCfgJsonObj();
+ if (!m_worker->getSysCfgJsonObj().empty() &&
+ jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj))
+ {
+ m_backupAndRestoreObj =
+ std::make_shared<BackupAndRestore>(l_sysCfgJsonObj);
+ }
+
// set callback to detect any asset tag change
registerAssetTagChangeCallback();
@@ -328,12 +335,9 @@
m_interface->set_property("CollectionStatus",
std::string("Completed"));
- const nlohmann::json& l_sysCfgJsonObj =
- m_worker->getSysCfgJsonObj();
- if (jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj))
+ if (m_backupAndRestoreObj)
{
- BackupAndRestore l_backupAndRestoreObj(l_sysCfgJsonObj);
- l_backupAndRestoreObj.backupAndRestore();
+ m_backupAndRestoreObj->backupAndRestore();
}
}
else
@@ -574,7 +578,19 @@
{
std::shared_ptr<Parser> l_parserObj =
std::make_shared<Parser>(l_fruPath, l_sysCfgJsonObj);
- return l_parserObj->updateVpdKeyword(i_paramsToWriteData);
+ auto l_rc = l_parserObj->updateVpdKeyword(i_paramsToWriteData);
+
+ if (l_rc != constants::FAILURE && m_backupAndRestoreObj)
+ {
+ if (m_backupAndRestoreObj->updateKeywordOnPrimaryOrBackupPath(
+ l_fruPath, i_paramsToWriteData) < constants::VALUE_0)
+ {
+ logging::logMessage(
+ "Write success, but backup and restore failed for file[" +
+ l_fruPath + "]");
+ }
+ }
+ return l_rc;
}
catch (const std::exception& l_exception)
{