entity-manager: constructor arg to load config
Introduce a constructor arg to point EM to directories to load
configuration from.
This enables running unit tests without depending on a specific
directory layout from our rofs.
Tested: on Tyan S8030. Config parsed as expected.
```
Oct 02 11:22:52 s8030-bmc-30303035c0c1 systemd[1]: Starting Entity Manager...
Oct 02 11:22:52 s8030-bmc-30303035c0c1 systemd[1]: Started Entity Manager.
Oct 02 11:23:02 s8030-bmc-30303035c0c1 entity-manager[8265]: There's still template variable $PRODUCT_PART_NUMBER un-replaced. Removing it from the string.
Oct 02 11:23:02 s8030-bmc-30303035c0c1 entity-manager[8265]: There's still template variable $PRODUCT_ASSET_TAG un-replaced. Removing it from the string.
Oct 02 11:23:02 s8030-bmc-30303035c0c1 entity-manager[8265]: There's still template variable $PRODUCT_ASSET_TAG un-replaced. Removing it from the string.
Oct 02 11:23:02 s8030-bmc-30303035c0c1 entity-manager[8265]: There's still template variable $PRODUCT_ASSET_TAG un-replaced. Removing it from the string.
Oct 02 11:23:02 s8030-bmc-30303035c0c1 entity-manager[8265]: There's still template variable $PRODUCT_PART_NUMBER un-replaced. Removing it from the string.
Oct 02 11:23:04 s8030-bmc-30303035c0c1 entity-manager[8265]: Inventory Added: Supermicro PWS 920P SQ 0
Oct 02 11:23:04 s8030-bmc-30303035c0c1 entity-manager[8265]: Inventory Added: Supermicro PWS 920P SQ 1
Oct 02 11:23:04 s8030-bmc-30303035c0c1 entity-manager[8265]: Inventory Added: Tyan S8030 Baseboard
Oct 02 11:23:04 s8030-bmc-30303035c0c1 entity-manager[8265]: Inventory Added: MBX 1.57 Chassis
```
Change-Id: I8ce297847d3cafe2e2ae2040e9db261dc1d8f426
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/configuration.cpp b/src/entity_manager/configuration.cpp
index b6ece2b..99f7f66 100644
--- a/src/entity_manager/configuration.cpp
+++ b/src/entity_manager/configuration.cpp
@@ -15,7 +15,9 @@
#include <string>
#include <vector>
-Configuration::Configuration()
+Configuration::Configuration(
+ const std::vector<std::filesystem::path>& configurationDirectories) :
+ configurationDirectories(configurationDirectories)
{
loadConfigurations();
filterProbeInterfaces();
@@ -27,13 +29,13 @@
// find configuration files
std::vector<std::filesystem::path> jsonPaths;
- if (!findFiles(
- std::vector<std::filesystem::path>{configurationDirectory,
- hostConfigurationDirectory},
- R"(.*\.json)", jsonPaths))
+ if (!findFiles(configurationDirectories, R"(.*\.json)", jsonPaths))
{
- lg2::error("Unable to find any configuration files in {DIR}", "DIR",
- configurationDirectory);
+ for (const auto& configurationDirectory : configurationDirectories)
+ {
+ lg2::error("Unable to find any configuration files in {DIR}", "DIR",
+ configurationDirectory);
+ }
return;
}
diff --git a/src/entity_manager/configuration.hpp b/src/entity_manager/configuration.hpp
index f7f0b31..3cd94d4 100644
--- a/src/entity_manager/configuration.hpp
+++ b/src/entity_manager/configuration.hpp
@@ -6,21 +6,23 @@
#include <vector>
constexpr const char* globalSchema = "global.json";
-constexpr const char* hostConfigurationDirectory = SYSCONF_DIR "configurations";
-constexpr const char* configurationDirectory = PACKAGE_DIR "configurations";
constexpr const char* currentConfiguration = "/var/configuration/system.json";
constexpr const char* schemaDirectory = PACKAGE_DIR "schemas";
class Configuration
{
public:
- explicit Configuration();
+ explicit Configuration(
+ const std::vector<std::filesystem::path>& configurationDirectories);
std::unordered_set<std::string> probeInterfaces;
std::vector<nlohmann::json> configurations;
- private:
+ protected:
void loadConfigurations();
void filterProbeInterfaces();
+
+ private:
+ std::vector<std::filesystem::path> configurationDirectories;
};
bool writeJsonFiles(const nlohmann::json& systemConfiguration);
diff --git a/src/entity_manager/entity_manager.cpp b/src/entity_manager/entity_manager.cpp
index 796f6e7..a3b4a72 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -52,10 +52,11 @@
EntityManager::EntityManager(
std::shared_ptr<sdbusplus::asio::connection>& systemBus,
- boost::asio::io_context& io) :
+ boost::asio::io_context& io,
+ const std::vector<std::filesystem::path>& configurationDirectories) :
systemBus(systemBus),
objServer(sdbusplus::asio::object_server(systemBus, /*skipManager=*/true)),
- lastJson(nlohmann::json::object()),
+ configuration(configurationDirectories), lastJson(nlohmann::json::object()),
systemConfiguration(nlohmann::json::object()), io(io),
dbus_interface(io, objServer), powerStatus(*systemBus),
propertiesChangedTimer(io)
diff --git a/src/entity_manager/entity_manager.hpp b/src/entity_manager/entity_manager.hpp
index 33efb31..c21b94e 100644
--- a/src/entity_manager/entity_manager.hpp
+++ b/src/entity_manager/entity_manager.hpp
@@ -20,7 +20,8 @@
public:
explicit EntityManager(
std::shared_ptr<sdbusplus::asio::connection>& systemBus,
- boost::asio::io_context& io);
+ boost::asio::io_context& io,
+ const std::vector<std::filesystem::path>& configurationDirectories);
// disable copy
EntityManager(const EntityManager&) = delete;
diff --git a/src/entity_manager/main.cpp b/src/entity_manager/main.cpp
index ebd27f8..8b8ead5 100644
--- a/src/entity_manager/main.cpp
+++ b/src/entity_manager/main.cpp
@@ -10,10 +10,13 @@
int main()
{
+ const std::vector<std::filesystem::path> configurationDirectories = {
+ PACKAGE_DIR "configurations", SYSCONF_DIR "configurations"};
+
boost::asio::io_context io;
auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
systemBus->request_name("xyz.openbmc_project.EntityManager");
- EntityManager em(systemBus, io);
+ EntityManager em(systemBus, io, configurationDirectories);
boost::asio::post(io, [&]() { em.propertiesChangedCallback(); });
diff --git a/src/utils.cpp b/src/utils.cpp
index d88df36..b5bac09 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -40,7 +40,7 @@
return true;
}
-bool findFiles(const std::vector<fs::path>&& dirPaths,
+bool findFiles(const std::vector<fs::path>& dirPaths,
const std::string& matchString,
std::vector<fs::path>& foundPaths)
{
diff --git a/src/utils.hpp b/src/utils.hpp
index 107d97e..368de5a 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -24,7 +24,7 @@
bool findFiles(const std::filesystem::path& dirPath,
const std::string& matchString,
std::vector<std::filesystem::path>& foundPaths);
-bool findFiles(const std::vector<std::filesystem::path>&& dirPaths,
+bool findFiles(const std::vector<std::filesystem::path>& dirPaths,
const std::string& matchString,
std::vector<std::filesystem::path>& foundPaths);