Move OEM specific code
IBM specific implementation is being moved to OEM handler.
This is being done to keep OEM specific code under specific OEM file,
keeping rest of the code generic.
Change-Id: I316bd6835566f79ffae1a4e1f804a986ee4b8983
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/constants.hpp b/vpd-manager/include/constants.hpp
index 4efe464..d7ada0a 100644
--- a/vpd-manager/include/constants.hpp
+++ b/vpd-manager/include/constants.hpp
@@ -164,6 +164,8 @@
constexpr auto objectMapperInf = "xyz.openbmc_project.ObjectMapper";
constexpr auto systemVpdInvPath =
"/xyz/openbmc_project/inventory/system/chassis/motherboard";
+constexpr auto motherboardInterface =
+ "xyz.openbmc_project.Inventory.Item.Board.Motherboard";
constexpr auto assetTagInf = "xyz.openbmc_project.Inventory.Decorator.AssetTag";
constexpr auto hostObjectPath = "/xyz/openbmc_project/state/host0";
constexpr auto hostInterface = "xyz.openbmc_project.State.Host";
diff --git a/vpd-manager/include/worker.hpp b/vpd-manager/include/worker.hpp
index a42b63f..4e4f12f 100644
--- a/vpd-manager/include/worker.hpp
+++ b/vpd-manager/include/worker.hpp
@@ -60,13 +60,6 @@
~Worker() = default;
/**
- * @brief An API to check if system VPD is already published.
- *
- * @return Status, true if system is already collected else false.
- */
- bool isSystemVPDOnDBus() const;
-
- /**
* @brief API to process all FRUs presnt in config JSON file.
*
* This API based on config JSON passed/selected for the system, will
@@ -185,17 +178,6 @@
void performVpdRecollection();
/**
- * @brief An API to set appropriate device tree and JSON.
- *
- * This API based on system chooses corresponding device tree and JSON.
- * If device tree change is required, it updates the "fitconfig" and reboots
- * the system. Else it is NOOP.
- *
- * @throw std::exception
- */
- void setDeviceTreeAndJson();
-
- /**
* @brief API to set CollectionStatus property.
*
* This API updates the CollectionStatus property of the given FRU with the
@@ -207,6 +189,26 @@
void setCollectionStatusProperty(const std::string& i_fruPath,
const std::string& i_value) const noexcept;
+ /**
+ * @brief API to set symbolic link for system config JSON.
+ *
+ * Once correct device tree is set, symbolic link to the correct sytsem
+ * config JSON is set to be used in subsequent BMC boot.
+ *
+ * @param[in] i_systemJson - system config JSON.
+ */
+ void setJsonSymbolicLink(const std::string& i_systemJson);
+
+ /**
+ * @brief An API to parse and publish system VPD on D-Bus.
+ *
+ * Note: Throws exception in case of invalid VPD format.
+ * Moved temporarily to public space. Will be eventually moved to
+ * ibm-handler.
+ * @param[in] parsedVpdMap - Parsed VPD as a map.
+ */
+ void publishSystemVPD(const types::VPDMapVariant& parsedVpdMap);
+
private:
/**
* @brief An API to parse and publish a FRU VPD over D-Bus.
@@ -222,39 +224,6 @@
const std::string& i_vpdFilePath);
/**
- * @brief API to select system specific JSON.
- *
- * The API based on the IM value of VPD, will select appropriate JSON for
- * the system. In case no system is found corresponding to the extracted IM
- * value, error will be logged.
- *
- * @param[out] systemJson - System JSON name.
- * @param[in] parsedVpdMap - Parsed VPD map.
- */
- void getSystemJson(std::string& systemJson,
- const types::VPDMapVariant& parsedVpdMap);
-
- /**
- * @brief An API to parse given VPD file path.
- *
- * @throw std::exception
- *
- * @param[in] vpdFilePath - EEPROM file path.
- * @param[out] parsedVpd - Parsed VPD as a map.
- */
- void fillVPDMap(const std::string& vpdFilePath,
- types::VPDMapVariant& parsedVpd);
-
- /**
- * @brief An API to parse and publish system VPD on D-Bus.
- *
- * Note: Throws exception in case of invalid VPD format.
- *
- * @param[in] parsedVpdMap - Parsed VPD as a map.
- */
- void publishSystemVPD(const types::VPDMapVariant& parsedVpdMap);
-
- /**
* @brief An API to process extrainterfaces w.r.t a FRU.
*
* @param[in] singleFru - JSON block for a single FRU.
@@ -432,13 +401,6 @@
const std::optional<types::VPDMapVariant> i_parsedVpd = std::nullopt);
/**
- * @brief An API to perform backup or restore of VPD.
- *
- * @param[in,out] io_srcVpdMap - Source VPD map.
- */
- void performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap);
-
- /**
* @brief API to update "Functional" property.
*
* The API sets the default value for "Functional" property once if the
@@ -481,16 +443,6 @@
const types::VPDMapVariant& i_parsedVpdMap);
/**
- * @brief API to set symbolic link for system config JSON.
- *
- * Once correct device tree is set, symbolic link to the correct sytsem
- * config JSON is set to be used in subsequent BMC boot.
- *
- * @param[in] i_systemJson - system config JSON.
- */
- void setJsonSymbolicLink(const std::string& i_systemJson);
-
- /**
* @brief API to set present property.
*
* This API updates the present property of the given FRU with the given
diff --git a/vpd-manager/oem-handler/ibm_handler.cpp b/vpd-manager/oem-handler/ibm_handler.cpp
index d9e193a..fa3f064 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -2,6 +2,7 @@
#include "ibm_handler.hpp"
+#include "configuration.hpp"
#include "listener.hpp"
#include "parser.hpp"
@@ -57,7 +58,9 @@
// Set up minimal things that is needed before bus name is claimed.
performInitialSetup();
- if (!m_sysCfgJsonObj.empty() &&
+ // If the object is created, implies back up and restore took place in
+ // system VPD flow.
+ if ((m_backupAndRestoreObj == nullptr) && !m_sysCfgJsonObj.empty() &&
jsonUtility::isBackupAndRestoreRequired(m_sysCfgJsonObj, l_errCode))
{
try
@@ -430,6 +433,308 @@
}
}
+void IbmHandler::getSystemJson(std::string& o_systemJson,
+ const types::VPDMapVariant& i_parsedVpdMap)
+{
+ if (auto l_pVal = std::get_if<types::IPZVpdMap>(&i_parsedVpdMap))
+ {
+ uint16_t l_errCode = 0;
+ std::string l_hwKWdValue =
+ vpdSpecificUtility::getHWVersion(*l_pVal, l_errCode);
+ if (l_hwKWdValue.empty())
+ {
+ if (l_errCode)
+ {
+ throw DataException("Failed to fetch HW value. Reason: " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
+ throw DataException("HW value fetched is empty.");
+ }
+
+ const std::string& l_imKwdValue =
+ vpdSpecificUtility::getIMValue(*l_pVal, l_errCode);
+ if (l_imKwdValue.empty())
+ {
+ if (l_errCode)
+ {
+ throw DataException("Failed to fetch IM value. Reason: " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
+ throw DataException("IM value fetched is empty.");
+ }
+
+ auto l_itrToIM = config::systemType.find(l_imKwdValue);
+ if (l_itrToIM == config::systemType.end())
+ {
+ throw DataException("IM keyword does not map to any system type");
+ }
+
+ const types::HWVerList l_hwVersionList = l_itrToIM->second.second;
+ if (!l_hwVersionList.empty())
+ {
+ transform(l_hwKWdValue.begin(), l_hwKWdValue.end(),
+ l_hwKWdValue.begin(), ::toupper);
+
+ auto l_itrToHW =
+ std::find_if(l_hwVersionList.begin(), l_hwVersionList.end(),
+ [&l_hwKWdValue](const auto& l_aPair) {
+ return l_aPair.first == l_hwKWdValue;
+ });
+
+ if (l_itrToHW != l_hwVersionList.end())
+ {
+ if (!(*l_itrToHW).second.empty())
+ {
+ o_systemJson += (*l_itrToIM).first + "_" +
+ (*l_itrToHW).second + ".json";
+ }
+ else
+ {
+ o_systemJson += (*l_itrToIM).first + ".json";
+ }
+ return;
+ }
+ }
+ o_systemJson += l_itrToIM->second.first + ".json";
+ return;
+ }
+
+ throw DataException(
+ "Invalid VPD type returned from Parser. Can't get system JSON.");
+}
+
+static void setEnvAndReboot(const std::string& i_key,
+ const std::string& i_value)
+{
+ // set env and reboot and break.
+ commonUtility::executeCmd("/sbin/fw_setenv", i_key, i_value);
+ logging::logMessage("Rebooting BMC to pick up new device tree");
+
+ // make dbus call to reboot
+ auto l_bus = sdbusplus::bus::new_default_system();
+ auto l_method = l_bus.new_method_call(
+ "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager", "Reboot");
+ l_bus.call_noreply(l_method);
+}
+
+static std::string readFitConfigValue()
+{
+ std::vector<std::string> l_output =
+ commonUtility::executeCmd("/sbin/fw_printenv");
+ std::string l_fitConfigValue;
+
+ for (const auto& l_entry : l_output)
+ {
+ auto l_pos = l_entry.find("=");
+ auto l_key = l_entry.substr(0, l_pos);
+ if (l_key != "fitconfig")
+ {
+ continue;
+ }
+
+ if (l_pos + 1 < l_entry.size())
+ {
+ l_fitConfigValue = l_entry.substr(l_pos + 1);
+ }
+ }
+
+ return l_fitConfigValue;
+}
+
+bool IbmHandler::isBackupOnCache()
+{
+ try
+ {
+ uint16_t l_errCode = 0;
+ std::string l_backupAndRestoreCfgFilePath =
+ m_sysCfgJsonObj.value("backupRestoreConfigPath", "");
+
+ if (l_backupAndRestoreCfgFilePath.empty())
+ {
+ m_logger->logMessage(
+ "backupRestoreConfigPath is not found in JSON. Can't determne the backup path.");
+ return false;
+ }
+
+ nlohmann::json l_backupAndRestoreCfgJsonObj =
+ jsonUtility::getParsedJson(l_backupAndRestoreCfgFilePath,
+ l_errCode);
+ if (l_backupAndRestoreCfgJsonObj.empty() || l_errCode)
+ {
+ m_logger->logMessage(
+ "JSON parsing failed for file [ " +
+ std::string(l_backupAndRestoreCfgFilePath) +
+ " ], error : " + commonUtility::getErrCodeMsg(l_errCode));
+ return false;
+ }
+
+ // check if either of "source" or "destination" has inventory path.
+ // this indicates that this sytem has System VPD on hardware
+ // and other copy on D-Bus (BMC cache).
+ if (!l_backupAndRestoreCfgJsonObj.empty() &&
+ ((l_backupAndRestoreCfgJsonObj.contains("source") &&
+ l_backupAndRestoreCfgJsonObj["source"].contains(
+ "inventoryPath")) ||
+ (l_backupAndRestoreCfgJsonObj.contains("destination") &&
+ l_backupAndRestoreCfgJsonObj["destination"].contains(
+ "inventoryPath"))))
+ {
+ return true;
+ }
+ }
+ catch (const std::exception& l_ex)
+ {
+ m_logger->logMessage(
+ "Exception while checking for backup on cache. Reason:" +
+ std::string(l_ex.what()));
+ }
+
+ // In case of any failure/ambiguity. Don't perform back up and restore.
+ return false;
+}
+
+void IbmHandler::performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap)
+{
+ try
+ {
+ m_backupAndRestoreObj =
+ std::make_shared<BackupAndRestore>(m_sysCfgJsonObj);
+ auto [l_srcVpdVariant,
+ l_dstVpdVariant] = m_backupAndRestoreObj->backupAndRestore();
+
+ // ToDo: Revisit is this check is required or not.
+ if (auto l_srcVpdMap = std::get_if<types::IPZVpdMap>(&l_srcVpdVariant);
+ l_srcVpdMap && !(*l_srcVpdMap).empty())
+ {
+ io_srcVpdMap = std::move(l_srcVpdVariant);
+ }
+ }
+ catch (const std::exception& l_ex)
+ {
+ EventLogger::createSyncPel(
+ EventLogger::getErrorType(l_ex), types::SeverityType::Warning,
+ __FILE__, __FUNCTION__, 0,
+ std::string(
+ "Exception caught while backup and restore VPD keyword's.") +
+ EventLogger::getErrorMsg(l_ex),
+ std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+ }
+}
+
+void IbmHandler::setDeviceTreeAndJson()
+{
+ // JSON is madatory for processing of this API.
+ if (m_sysCfgJsonObj.empty())
+ {
+ throw JsonException("System config JSON is empty", m_sysCfgJsonObj);
+ }
+
+ // parse system VPD
+ auto l_parsedVpdMap = m_worker->parseVpdFile(SYSTEM_VPD_FILE_PATH);
+
+ // Implies it is default JSON.
+ std::string l_systemJson{JSON_ABSOLUTE_PATH_PREFIX};
+
+ // get system JSON as per the system configuration.
+ getSystemJson(l_systemJson, l_parsedVpdMap);
+
+ if (!l_systemJson.compare(JSON_ABSOLUTE_PATH_PREFIX))
+ {
+ throw DataException(
+ "No system JSON found corresponding to IM read from VPD.");
+ }
+
+ uint16_t l_errCode = 0;
+ // re-parse the JSON once appropriate JSON has been selected.
+ m_sysCfgJsonObj = jsonUtility::getParsedJson(l_systemJson, l_errCode);
+
+ if (l_errCode)
+ {
+ throw(JsonException(
+ "JSON parsing failed for file [ " + l_systemJson +
+ " ], error : " + commonUtility::getErrCodeMsg(l_errCode),
+ l_systemJson));
+ }
+
+ m_worker->setCollectionStatusProperty(SYSTEM_VPD_FILE_PATH,
+ constants::vpdCollectionInProgress);
+
+ std::string l_devTreeFromJson;
+ if (m_sysCfgJsonObj.contains("devTree"))
+ {
+ l_devTreeFromJson = m_sysCfgJsonObj["devTree"];
+
+ if (l_devTreeFromJson.empty())
+ {
+ EventLogger::createSyncPel(
+ types::ErrorType::JsonFailure, types::SeverityType::Error,
+ __FILE__, __FUNCTION__, 0,
+ "Mandatory value for device tree missing from JSON[" +
+ l_systemJson + "]",
+ std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+ }
+ }
+
+ auto l_fitConfigVal = readFitConfigValue();
+
+ if (l_devTreeFromJson.empty() ||
+ l_fitConfigVal.find(l_devTreeFromJson) != std::string::npos)
+ { // Skipping setting device tree as either devtree info is missing from
+ // Json or it is rightly set.
+
+ m_worker->setJsonSymbolicLink(l_systemJson);
+
+ const std::string& l_systemVpdInvPath =
+ jsonUtility::getInventoryObjPathFromJson(
+ m_sysCfgJsonObj, SYSTEM_VPD_FILE_PATH, l_errCode);
+
+ if (l_systemVpdInvPath.empty())
+ {
+ if (l_errCode)
+ {
+ throw JsonException(
+ "System vpd inventory path not found in JSON. Reason:" +
+ commonUtility::getErrCodeMsg(l_errCode),
+ INVENTORY_JSON_SYM_LINK);
+ }
+ throw JsonException("System vpd inventory path is missing in JSON",
+ INVENTORY_JSON_SYM_LINK);
+ }
+
+ // TODO: for backward compatibility this should also support motherboard
+ // interface.
+ std::vector<std::string> l_interfaceList{
+ constants::motherboardInterface};
+ const types::MapperGetObject& l_sysVpdObjMap =
+ dbusUtility::getObjectMap(l_systemVpdInvPath, l_interfaceList);
+
+ if (!l_sysVpdObjMap.empty())
+ {
+ if (isBackupOnCache() && jsonUtility::isBackupAndRestoreRequired(
+ m_sysCfgJsonObj, l_errCode))
+ {
+ performBackupAndRestore(l_parsedVpdMap);
+ }
+ else if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to check if backup and restore required. Reason : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
+ }
+
+ // proceed to publish system VPD.
+ m_worker->publishSystemVPD(l_parsedVpdMap);
+ m_worker->setCollectionStatusProperty(
+ SYSTEM_VPD_FILE_PATH, constants::vpdCollectionCompleted);
+ return;
+ }
+
+ setEnvAndReboot("fitconfig", l_devTreeFromJson);
+ exit(EXIT_SUCCESS);
+}
+
void IbmHandler::performInitialSetup()
{
try
@@ -443,12 +748,7 @@
m_sysCfgJsonObj = m_worker->getSysCfgJsonObj();
if (!dbusUtility::isChassisPowerOn())
{
- m_worker->setDeviceTreeAndJson();
-
- // Since the above function setDeviceTreeAndJson can change the json
- // which is used, we would need to reacquire the json object again
- // here.
- m_sysCfgJsonObj = m_worker->getSysCfgJsonObj();
+ setDeviceTreeAndJson();
}
// Update BMC postion for RBMC prototype system
diff --git a/vpd-manager/oem-handler/ibm_handler.hpp b/vpd-manager/oem-handler/ibm_handler.hpp
index 2eafc49..9060dd9 100644
--- a/vpd-manager/oem-handler/ibm_handler.hpp
+++ b/vpd-manager/oem-handler/ibm_handler.hpp
@@ -65,6 +65,49 @@
private:
/**
+ * @brief An API to set appropriate device tree and JSON.
+ *
+ * This API based on system chooses corresponding device tree and JSON.
+ * If device tree change is required, it updates the "fitconfig" and reboots
+ * the system. Else it is NOOP.
+ *
+ * @throw std::exception
+ */
+ void setDeviceTreeAndJson();
+
+ /**
+ * @brief API to detect if system vpd is backed up in cache.
+ *
+ * System vpd can be cached either in cache or some other location. The
+ * information is extracted from system config json.
+ *
+ * @return True if the location is cache, fale otherwise.
+ */
+ bool isBackupOnCache();
+
+ /**
+ * @brief API to select system specific JSON.
+ *
+ * The API based on the IM value of VPD, will select appropriate JSON for
+ * the system. In case no system is found corresponding to the extracted IM
+ * value, error will be logged.
+ *
+ * @throw DataException, std::exception
+ *
+ * @param[out] o_systemJson - System JSON name.
+ * @param[in] i_parsedVpdMap - Parsed VPD map.
+ */
+ void getSystemJson(std::string& o_systemJson,
+ const types::VPDMapVariant& i_parsedVpdMap);
+
+ /**
+ * @brief An API to perform backup or restore of VPD.
+ *
+ * @param[in,out] io_srcVpdMap - Source VPD map.
+ */
+ void performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap);
+
+ /**
* @brief Set timer to detect and set VPD collection status for the system.
*
* Collection of FRU VPD is triggered in a separate thread. Resulting in
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 9a05294..7f94cb7 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -3,7 +3,6 @@
#include "worker.hpp"
#include "backup_restore.hpp"
-#include "configuration.hpp"
#include "constants.hpp"
#include "exceptions.hpp"
#include "logger.hpp"
@@ -73,157 +72,6 @@
}
}
-static std::string readFitConfigValue()
-{
- std::vector<std::string> output =
- commonUtility::executeCmd("/sbin/fw_printenv");
- std::string fitConfigValue;
-
- for (const auto& entry : output)
- {
- auto pos = entry.find("=");
- auto key = entry.substr(0, pos);
- if (key != "fitconfig")
- {
- continue;
- }
-
- if (pos + 1 < entry.size())
- {
- fitConfigValue = entry.substr(pos + 1);
- }
- }
-
- return fitConfigValue;
-}
-
-bool Worker::isSystemVPDOnDBus() const
-{
- const std::string& mboardPath =
- m_parsedJson["frus"][SYSTEM_VPD_FILE_PATH].at(0).value(
- "inventoryPath", "");
-
- if (mboardPath.empty())
- {
- throw JsonException("System vpd file path missing in JSON",
- INVENTORY_JSON_SYM_LINK);
- }
-
- std::vector<std::string> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
-
- const types::MapperGetObject& objectMap =
- dbusUtility::getObjectMap(mboardPath, interfaces);
-
- if (objectMap.empty())
- {
- return false;
- }
- return true;
-}
-
-void Worker::fillVPDMap(const std::string& vpdFilePath,
- types::VPDMapVariant& vpdMap)
-{
- if (vpdFilePath.empty())
- {
- throw std::runtime_error("Invalid file path passed to fillVPDMap API.");
- }
-
- if (!std::filesystem::exists(vpdFilePath))
- {
- throw std::runtime_error("Can't Find physical file");
- }
-
- std::shared_ptr<Parser> vpdParser =
- std::make_shared<Parser>(vpdFilePath, m_parsedJson);
- vpdMap = vpdParser->parse();
-}
-
-void Worker::getSystemJson(std::string& systemJson,
- const types::VPDMapVariant& parsedVpdMap)
-{
- if (auto pVal = std::get_if<types::IPZVpdMap>(&parsedVpdMap))
- {
- uint16_t l_errCode = 0;
- std::string hwKWdValue =
- vpdSpecificUtility::getHWVersion(*pVal, l_errCode);
- if (hwKWdValue.empty())
- {
- if (l_errCode)
- {
- throw DataException("Failed to fetch HW value. Reason: " +
- commonUtility::getErrCodeMsg(l_errCode));
- }
- throw DataException("HW value fetched is empty.");
- }
-
- const std::string& imKwdValue =
- vpdSpecificUtility::getIMValue(*pVal, l_errCode);
- if (imKwdValue.empty())
- {
- if (l_errCode)
- {
- throw DataException("Failed to fetch IM value. Reason: " +
- commonUtility::getErrCodeMsg(l_errCode));
- }
- throw DataException("IM value fetched is empty.");
- }
-
- auto itrToIM = config::systemType.find(imKwdValue);
- if (itrToIM == config::systemType.end())
- {
- throw DataException("IM keyword does not map to any system type");
- }
-
- const types::HWVerList hwVersionList = itrToIM->second.second;
- if (!hwVersionList.empty())
- {
- transform(hwKWdValue.begin(), hwKWdValue.end(), hwKWdValue.begin(),
- ::toupper);
-
- auto itrToHW =
- std::find_if(hwVersionList.begin(), hwVersionList.end(),
- [&hwKWdValue](const auto& aPair) {
- return aPair.first == hwKWdValue;
- });
-
- if (itrToHW != hwVersionList.end())
- {
- if (!(*itrToHW).second.empty())
- {
- systemJson += (*itrToIM).first + "_" + (*itrToHW).second +
- ".json";
- }
- else
- {
- systemJson += (*itrToIM).first + ".json";
- }
- return;
- }
- }
- systemJson += itrToIM->second.first + ".json";
- return;
- }
-
- throw DataException(
- "Invalid VPD type returned from Parser. Can't get system JSON.");
-}
-
-static void setEnvAndReboot(const std::string& key, const std::string& value)
-{
- // set env and reboot and break.
- commonUtility::executeCmd("/sbin/fw_setenv", key, value);
- logging::logMessage("Rebooting BMC to pick up new device tree");
-
- // make dbus call to reboot
- auto bus = sdbusplus::bus::new_default_system();
- auto method = bus.new_method_call(
- "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager", "Reboot");
- bus.call_noreply(method);
-}
-
void Worker::setJsonSymbolicLink(const std::string& i_systemJson)
{
std::error_code l_ec;
@@ -296,105 +144,25 @@
"create_symlink system call failed with error: " + l_ec.message());
}
+ // update Worker json with the newly created symlink
+ uint16_t l_errCode = 0;
+ m_parsedJson =
+ jsonUtility::getParsedJson(INVENTORY_JSON_SYM_LINK, l_errCode);
+ if (l_errCode)
+ {
+ throw std::runtime_error(
+ "JSON parsing failed for file [ " +
+ std::string(INVENTORY_JSON_SYM_LINK) +
+ " ], error : " + commonUtility::getErrCodeMsg(l_errCode));
+ }
+
+ logging::logMessage("Worker JSON modified to: " + i_systemJson);
+
// If the flow is at this point implies the symlink was not present there.
// Considering this as factory reset.
m_isFactoryResetDone = true;
}
-void Worker::setDeviceTreeAndJson()
-{
- // JSON is madatory for processing of this API.
- if (m_parsedJson.empty())
- {
- throw JsonException("System config JSON is empty", m_configJsonPath);
- }
-
- types::VPDMapVariant parsedVpdMap;
- fillVPDMap(SYSTEM_VPD_FILE_PATH, parsedVpdMap);
-
- // Implies it is default JSON.
- std::string systemJson{JSON_ABSOLUTE_PATH_PREFIX};
-
- // ToDo: Need to check if INVENTORY_JSON_SYM_LINK pointing to correct system
- // This is required to support movement from rainier to Blue Ridge on the
- // fly.
-
- getSystemJson(systemJson, parsedVpdMap);
-
- if (!systemJson.compare(JSON_ABSOLUTE_PATH_PREFIX))
- {
- throw DataException(
- "No system JSON found corresponding to IM read from VPD.");
- }
-
- uint16_t l_errCode = 0;
-
- // re-parse the JSON once appropriate JSON has been selected.
- m_parsedJson = jsonUtility::getParsedJson(systemJson, l_errCode);
-
- if (l_errCode)
- {
- throw(JsonException(
- "JSON parsing failed for file [ " + systemJson +
- " ], error : " + commonUtility::getErrCodeMsg(l_errCode),
- systemJson));
- }
-
- setCollectionStatusProperty(SYSTEM_VPD_FILE_PATH,
- constants::vpdCollectionInProgress);
-
- std::string devTreeFromJson;
- if (m_parsedJson.contains("devTree"))
- {
- devTreeFromJson = m_parsedJson["devTree"];
-
- if (devTreeFromJson.empty())
- {
- EventLogger::createSyncPel(
- types::ErrorType::JsonFailure, types::SeverityType::Error,
- __FILE__, __FUNCTION__, 0,
- "Mandatory value for device tree missing from JSON[" +
- systemJson + "]",
- std::nullopt, std::nullopt, std::nullopt, std::nullopt);
- }
- }
-
- auto fitConfigVal = readFitConfigValue();
-
- if (devTreeFromJson.empty() ||
- fitConfigVal.find(devTreeFromJson) != std::string::npos)
- { // Skipping setting device tree as either devtree info is missing from
- // Json or it is rightly set.
-
- setJsonSymbolicLink(systemJson);
-
- if (isSystemVPDOnDBus())
- {
- uint16_t l_errCode = 0;
- if (jsonUtility::isBackupAndRestoreRequired(m_parsedJson,
- l_errCode))
- {
- performBackupAndRestore(parsedVpdMap);
- }
- else if (l_errCode)
- {
- logging::logMessage(
- "Failed to check if backup and restore required. Reason : " +
- commonUtility::getErrCodeMsg(l_errCode));
- }
- }
-
- // proceed to publish system VPD.
- publishSystemVPD(parsedVpdMap);
- setCollectionStatusProperty(SYSTEM_VPD_FILE_PATH,
- constants::vpdCollectionCompleted);
- return;
- }
-
- setEnvAndReboot("fitconfig", devTreeFromJson);
- exit(EXIT_SUCCESS);
-}
-
void Worker::populateIPZVPDpropertyMap(
types::InterfaceMap& interfacePropMap,
const types::IPZKwdValueMap& keyordValueMap,
@@ -1581,64 +1349,6 @@
}
}
-// ToDo: Move the API under IBM_SYSTEM
-void Worker::performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap)
-{
- try
- {
- uint16_t l_errCode = 0;
- std::string l_backupAndRestoreCfgFilePath =
- m_parsedJson.value("backupRestoreConfigPath", "");
-
- nlohmann::json l_backupAndRestoreCfgJsonObj =
- jsonUtility::getParsedJson(l_backupAndRestoreCfgFilePath,
- l_errCode);
-
- if (l_errCode)
- {
- throw JsonException(
- "JSON parsing failed for file [ " +
- l_backupAndRestoreCfgFilePath +
- " ], error : " + commonUtility::getErrCodeMsg(l_errCode),
- l_backupAndRestoreCfgFilePath);
- }
-
- // check if either of "source" or "destination" has inventory path.
- // this indicates that this sytem has System VPD on hardware
- // and other copy on D-Bus (BMC cache).
- if (!l_backupAndRestoreCfgJsonObj.empty() &&
- ((l_backupAndRestoreCfgJsonObj.contains("source") &&
- l_backupAndRestoreCfgJsonObj["source"].contains(
- "inventoryPath")) ||
- (l_backupAndRestoreCfgJsonObj.contains("destination") &&
- l_backupAndRestoreCfgJsonObj["destination"].contains(
- "inventoryPath"))))
- {
- BackupAndRestore l_backupAndRestoreObj(m_parsedJson);
- auto [l_srcVpdVariant,
- l_dstVpdVariant] = l_backupAndRestoreObj.backupAndRestore();
-
- // ToDo: Revisit is this check is required or not.
- if (auto l_srcVpdMap =
- std::get_if<types::IPZVpdMap>(&l_srcVpdVariant);
- l_srcVpdMap && !(*l_srcVpdMap).empty())
- {
- io_srcVpdMap = std::move(l_srcVpdVariant);
- }
- }
- }
- catch (const std::exception& l_ex)
- {
- EventLogger::createSyncPel(
- EventLogger::getErrorType(l_ex), types::SeverityType::Warning,
- __FILE__, __FUNCTION__, 0,
- std::string(
- "Exception caught while backup and restore VPD keyword's.") +
- EventLogger::getErrorMsg(l_ex),
- std::nullopt, std::nullopt, std::nullopt, std::nullopt);
- }
-}
-
void Worker::deleteFruVpd(const std::string& i_dbusObjPath)
{
if (i_dbusObjPath.empty())