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/include/backup_restore.hpp b/vpd-manager/include/backup_restore.hpp
index d3cd467..7f1cfaa 100644
--- a/vpd-manager/include/backup_restore.hpp
+++ b/vpd-manager/include/backup_restore.hpp
@@ -74,6 +74,30 @@
static void setBackupAndRestoreStatus(
const BackupAndRestoreStatus& i_status);
+ /**
+ * @brief An API to update keyword's value on primary or backup path.
+ *
+ * Updates the keyword's value based on the following,
+ * 1. If provided i_fruPath is primary(source) path in the backup restore
+ * config JSON, then API updates VPD on the backup(destination) path.
+ * 2. If i_fruPath is backup path, then API updates the VPD on the
+ * primary path.
+ *
+ * Note: The above condition is only valid,
+ * 1. If system's primary & backup VPD is on EEPROM path(and should be found
+ * in the backup and restore config JSON).
+ * 2. If the input record and keyword are found in the backup and restore
+ * config JSON.
+ *
+ * @param[in] i_fruPath - EEPROM path of the FRU.
+ * @param[in] i_paramsToWriteData - Input details.
+ *
+ * @return On success returns number of bytes written, -1 on failure.
+ */
+ int updateKeywordOnPrimaryOrBackupPath(
+ const std::string& i_fruPath,
+ const types::WriteVpdParams& i_paramsToWriteData) const noexcept;
+
private:
/**
* @brief An API to handle backup and restore of IPZ type VPD.
diff --git a/vpd-manager/include/manager.hpp b/vpd-manager/include/manager.hpp
index ad67694..94c5693 100644
--- a/vpd-manager/include/manager.hpp
+++ b/vpd-manager/include/manager.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "backup_restore.hpp"
#include "constants.hpp"
#include "gpio_monitor.hpp"
#include "types.hpp"
@@ -321,6 +322,9 @@
// Variable to hold current collection status
std::string m_vpdCollectionStatus = "NotStarted";
+
+ // Shared pointer to backup and restore class
+ std::shared_ptr<BackupAndRestore> m_backupAndRestoreObj;
};
} // namespace vpd
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)
{