entity-manager: function for building inventory/system path
Tested: on QEMU/yosemite4 with adapted config.
```
root@yosemite4:~# journalctl | grep entity-manager
Apr 03 13:35:06 yosemite4 entity-manager[503]: Clearing previous configuration
Apr 03 13:35:07 yosemite4 entity-manager[503]: dbus command syntax error {"BOARD_MANUFACTURER": "(Quanta|Ingrasys)", BOARD_PRODUCT_NAME": "Ventura FAN Board", "BOARD_INFO_AM4": "adc-max"}
Apr 03 13:35:08 yosemite4 entity-manager[503]: dbus command syntax error {"BOARD_MANUFACTURER": "(Quanta|Ingrasys)", BOARD_PRODUCT_NAME": "Ventura FAN Board", "BOARD_INFO_AM4": "adc-max"}
Apr 03 13:35:08 yosemite4 entity-manager[503]: Inventory Added: Yosemite 4 Management Board
Aug 19 00:22:52 yosemite4 entity-manager[503]: dbus command syntax error {"BOARD_MANUFACTURER": "(Quanta|Ingrasys)", BOARD_PRODUCT_NAME": "Ventura FAN Board", "BOARD_INFO_AM4": "adc-max"}
Aug 19 00:22:59 yosemite4 entity-manager[503]: dbus command syntax error {"BOARD_MANUFACTURER": "(Quanta|Ingrasys)", BOARD_PRODUCT_NAME": "Ventura FAN Board", "BOARD_INFO_AM4": "adc-max"}
root@yosemite4:~# busctl tree xyz.openbmc_project.EntityManager
`- /xyz
`- /xyz/openbmc_project
|- /xyz/openbmc_project/EntityManager
`- /xyz/openbmc_project/inventory
`- /xyz/openbmc_project/inventory/system
`- /xyz/openbmc_project/inventory/system/board
`- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/All_Fan
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P0V6_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P12V_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P1V0_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P1V2_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P1V8_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P2V5_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P3V3_RGM_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P3V3_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P3V_BAT_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P5V_USB_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P5V_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_TEMP_C
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/PID_NIC_TEMP
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_MGNT_TEMP
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_NIC_TEMP
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_SENTINEL_DOME_SLOT_PRESENT_PERCENTAGE
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_VIRTUAL_NIC_TEMP_C
`- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Zone_1
```
Change-Id: I603ea4707e3a9078968b0f76e4a649feb9fdd1c0
Signed-off-by: Christopher Meis <christopher.meis@9elements.com>
diff --git a/src/entity_manager/entity_manager.cpp b/src/entity_manager/entity_manager.cpp
index 29ee897..d3edf62 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -130,14 +130,9 @@
<< " reverting to Chassis.\n";
boardType = "Chassis";
}
- std::string boardtypeLower = boost::algorithm::to_lower_copy(boardType);
- std::regex_replace(boardName.begin(), boardName.begin(), boardName.end(),
- illegalDbusMemberRegex, "_");
- std::string boardPath = "/xyz/openbmc_project/inventory/system/";
- boardPath += boardtypeLower;
- boardPath += "/";
- boardPath += boardName;
+ const std::string boardPath =
+ em_utils::buildInventorySystemPath(boardName, boardType);
std::shared_ptr<sdbusplus::asio::dbus_interface> inventoryIface =
dbus_interface.createInterface(objServer, boardPath,
diff --git a/src/entity_manager/utils.cpp b/src/entity_manager/utils.cpp
index 90d53d1..8af3dce 100644
--- a/src/entity_manager/utils.cpp
+++ b/src/entity_manager/utils.cpp
@@ -3,6 +3,7 @@
#include "../variant_visitors.hpp"
#include "expression.hpp"
+#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/find.hpp>
#include <boost/algorithm/string/predicate.hpp>
@@ -12,6 +13,9 @@
#include <fstream>
#include <iostream>
+#include <regex>
+
+const std::regex illegalDbusMemberRegex("[^A-Za-z0-9_]");
namespace em_utils
{
@@ -219,4 +223,15 @@
return ret;
}
+std::string buildInventorySystemPath(std::string& boardName,
+ const std::string& boardType)
+{
+ std::string path = "/xyz/openbmc_project/inventory/system/";
+ std::string boardTypeLower = boost::algorithm::to_lower_copy(boardType);
+
+ std::regex_replace(boardName.begin(), boardName.begin(), boardName.end(),
+ illegalDbusMemberRegex, "_");
+
+ return std::format("{}{}/{}", path, boardTypeLower, boardName);
+}
} // namespace em_utils
diff --git a/src/entity_manager/utils.hpp b/src/entity_manager/utils.hpp
index 3bf20f2..b638239 100644
--- a/src/entity_manager/utils.hpp
+++ b/src/entity_manager/utils.hpp
@@ -34,4 +34,7 @@
nlohmann::json::iterator& keyPair, const DBusInterface& interface,
size_t index, const std::optional<std::string>& replaceStr = std::nullopt);
+std::string buildInventorySystemPath(std::string& boardName,
+ const std::string& boardType);
+
} // namespace em_utils