From 31f3f766c9c6cc6c0b7c722030dbbf6de65b7e2f Mon Sep 17 00:00:00 2001 From: mansijos Date: Mon, 3 Jan 2022 19:44:09 +0000 Subject: [PATCH] Entity-manager: Add support to update assetTag Asset tag is an updateable property from User level interface like Redfish. User-level interface will update Asset tag in entity-manager, which will further update the needed FRU interface property exposed. Tested: Successfully updated in assetTag interface as well as in fru interface while using set-property and using redfish as well. The new value is preserved after BMC resets. Signed-off-by: mansijos --- src/EntityManager.cpp | 83 ++++++++++++++++++++++++++++++++++++++++--- src/PerformScan.cpp | 11 ++++++ 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp index d327f2b..5fade71 100644 --- a/src/EntityManager.cpp +++ b/src/EntityManager.cpp @@ -51,6 +51,13 @@ constexpr const char* currentConfiguration = "/var/configuration/system.json"; constexpr const char* globalSchema = "global.json"; constexpr const bool debug = false; +using foundProbeData = std::map; +static foundProbeData foundData; +static std::map mapFoundData; + +constexpr const char* fruConn = "xyz.openbmc_project.FruDevice"; +constexpr const char* fruIntf = "xyz.openbmc_project.FruDevice"; + const boost::container::flat_map probeTypes{{{"FALSE", probe_type_codes::FALSE_T}, {"TRUE", probe_type_codes::TRUE_T}, @@ -205,6 +212,43 @@ void addArrayToDbus(const std::string& name, const nlohmann::json& array, } } +template +bool persistAssetTag(const PropertyType& newVal, + const std::string& jsonPointerString) +{ + std::size_t found = jsonPointerString.find_last_of("/\\"); + std::string jsonPointerPath = jsonPointerString.substr(0, found); + + auto it = mapFoundData.find(jsonPointerPath); + if (it == mapFoundData.end()) + { + std::cerr << "Error in finding jsonPointerPath in mapFoundData" + << "\n"; + return false; + } + + foundProbeData& tmpMap = it->second; + auto foundPath = tmpMap.find("foundPath"); + if (foundPath == tmpMap.end()) + { + std::cerr << "No prob object data is avaliable in foundProbeData" + << "\n"; + return false; + } + + systemBus->async_method_call( + [](const boost::system::error_code& ec) { + if (ec) + { + std::cerr << "Error setting AssetTag in FRU interface " << ec + << "\n"; + } + }, + fruConn, foundPath->second, "org.freedesktop.DBus.Properties", "Set", + fruIntf, "PRODUCT_ASSET_TAG", std::variant(newVal)); + return true; +} + template void addProperty(const std::string& propertyName, const PropertyType& value, sdbusplus::asio::dbus_interface* iface, @@ -219,9 +263,18 @@ void addProperty(const std::string& propertyName, const PropertyType& value, } iface->register_property( propertyName, value, - [&systemConfiguration, + [propertyName, &systemConfiguration, jsonPointerString{std::string(jsonPointerString)}]( const PropertyType& newVal, PropertyType& val) { + if (propertyName == "AssetTag") + { + if (!persistAssetTag(newVal, jsonPointerString)) + { + std::cerr << "error setting AssetTag in FRU interface\n"; + return -1; + } + } + val = newVal; if (!setJsonFromPointer(jsonPointerString, val, systemConfiguration)) @@ -621,6 +674,9 @@ void postToDbus(const nlohmann::json& newConfiguration, populateInterfaceFromJson(systemConfiguration, jsonPointerPath, boardIface, boardValues, objServer); jsonPointerPath += "/"; + + std::string foundPath; + // iterate through board properties for (auto& boardField : boardValues.items()) { @@ -630,9 +686,28 @@ void postToDbus(const nlohmann::json& newConfiguration, createInterface(objServer, boardName, boardField.key(), boardKeyOrig); - populateInterfaceFromJson(systemConfiguration, - jsonPointerPath + boardField.key(), - iface, boardField.value(), objServer); + if (boardField.key() == "FoundProbe") + { + foundPath = boardField.value()["Path"]; + } + if (boardField.key() == + "xyz.openbmc_project.Inventory.Decorator.AssetTag") + { + foundData["foundPath"] = foundPath; + mapFoundData[jsonPointerPath + boardField.key()] = + foundData; + + populateInterfaceFromJson( + systemConfiguration, jsonPointerPath + boardField.key(), + iface, boardField.value(), objServer, + sdbusplus::asio::PropertyPermission::readWrite); + } + else + { + populateInterfaceFromJson( + systemConfiguration, jsonPointerPath + boardField.key(), + iface, boardField.value(), objServer); + } } } diff --git a/src/PerformScan.cpp b/src/PerformScan.cpp index 5978710..5261ef7 100644 --- a/src/PerformScan.cpp +++ b/src/PerformScan.cpp @@ -38,6 +38,8 @@ constexpr const int32_t maxMapperDepth = 0; constexpr const bool debug = false; +constexpr const char* foundObject = "FoundProbe"; + void getInterfaces( const std::tuple& call, const std::vector>& probeVector, @@ -359,6 +361,11 @@ void PerformScan::run() { continue; // non-numeric replacement } + + nlohmann::json recordVal = *recordPtr; + // Save the dbus path info of the device + recordVal[foundObject]["Path"] = std::get<1>(*itr); + usedNames.insert(nameIt.value()); auto usedIt = std::find(indexes.begin(), indexes.end(), index); @@ -436,6 +443,10 @@ void PerformScan::run() } } + // Save the dbus path info of the device + record[foundObject]["Path"] = + std::get<1>(foundDeviceAndPath); + if (replaceStr) { std::cerr << "Duplicates found, replacing " -- 2.17.1