diff --git a/src/external_data_ifaces.cpp b/src/external_data_ifaces.cpp index 619fce0..40518b8 100644 --- a/src/external_data_ifaces.cpp +++ b/src/external_data_ifaces.cpp @@ -9,7 +9,9 @@ namespace data_sync::ext_data sdbusplus::async::task<> ExternalDataIFaces::startExtDataFetches() { // NOLINTNEXTLINE - co_return co_await fetchBMCRedundancyMgrProps(); + co_return co_await sdbusplus::async::execution::when_all( + fetchBMCRedundancyMgrProps(), fetchSiblingBmcIP(), + fetchRbmcCredentials()); } BMCRole ExternalDataIFaces::bmcRole() const @@ -32,4 +34,23 @@ void ExternalDataIFaces::bmcRedundancy(const BMCRedundancy& bmcRedundancy) _bmcRedundancy = bmcRedundancy; } +const SiblingBmcIP& ExternalDataIFaces::siblingBmcIP() const +{ + return _siblingBmcIP; +} + +void ExternalDataIFaces::siblingBmcIP(const SiblingBmcIP& siblingBmcIP) +{ + _siblingBmcIP = siblingBmcIP; +} + +void ExternalDataIFaces::rbmcCredentials(const RbmcCredentials& rbmcCredentials) +{ + _rbmcCredentials = rbmcCredentials; +} + +const RbmcCredentials& ExternalDataIFaces::rbmcCredentials() const +{ + return _rbmcCredentials; +} } // namespace data_sync::ext_data diff --git a/src/external_data_ifaces.hpp b/src/external_data_ifaces.hpp index 02e0d4b..b0ebc59 100644 --- a/src/external_data_ifaces.hpp +++ b/src/external_data_ifaces.hpp @@ -11,6 +11,10 @@ namespace data_sync::ext_data using RBMC = sdbusplus::common::xyz::openbmc_project::state::bmc::Redundancy; using BMCRole = RBMC::Role; using BMCRedundancy = bool; +using SiblingBmcIP = std::string; +using RbmcUserName = std::string; +using RbmcPassword = std::string; +using RbmcCredentials = std::pair; /** * @class ExternalDataIFaces @@ -53,12 +57,36 @@ class ExternalDataIFaces */ BMCRedundancy bmcRedundancy() const; + /** + * @brief Used to obtain the Sibling BMC IP. + * + * @return The Sibling BMC IP + */ + const SiblingBmcIP& siblingBmcIP() const; + + /** + * @brief Used to obtain the BMC username and password + * + * @return BMC Username and Password + */ + const RbmcCredentials& rbmcCredentials() const; + protected: /** * @brief Used to retrieve the BMC role. */ virtual sdbusplus::async::task<> fetchBMCRedundancyMgrProps() = 0; + /** + * @brief Used to retrieve the Sibling BMC IP. + */ + virtual sdbusplus::async::task<> fetchSiblingBmcIP() = 0; + + /** + * @brief Used to retrieve the BMC Username and Password. + */ + virtual sdbusplus::async::task<> fetchRbmcCredentials() = 0; + /** * @brief A utility API to assign the retrieved BMC role. * @@ -77,6 +105,25 @@ class ExternalDataIFaces */ void bmcRedundancy(const BMCRedundancy& bmcRedundancy); + /** + * @brief A utility API to assign the retrieved Sibling BMC IP. + * + * @param[in] siblingBmcIP - The retrieved Sibling BMC IP. + * + * @return None. + */ + void siblingBmcIP(const SiblingBmcIP& siblingBmcIP); + + /** + * @brief A utility API to assign the retrieved BMC Username and Password. + * + * @param[in] rbmcCredentials - The retrieved Sibling BMC Username and + * Password. + * + * @return None. + */ + void rbmcCredentials(const RbmcCredentials& rbmcCredentials); + private: /** * @brief Holds the BMC role. @@ -87,6 +134,16 @@ class ExternalDataIFaces * @brief Indicates whether BMC redundancy is enabled in the system. */ BMCRedundancy _bmcRedundancy{false}; + + /** + * @brief hold the Sibling BMC IP + */ + SiblingBmcIP _siblingBmcIP; + + /** + * @brief This is Pair, hold the BMCs Username and Password + */ + RbmcCredentials _rbmcCredentials; }; } // namespace data_sync::ext_data diff --git a/src/external_data_ifaces_impl.cpp b/src/external_data_ifaces_impl.cpp index 95d94cf..3144e02 100644 --- a/src/external_data_ifaces_impl.cpp +++ b/src/external_data_ifaces_impl.cpp @@ -2,6 +2,7 @@ #include "external_data_ifaces_impl.hpp" +#include #include namespace data_sync::ext_data @@ -41,4 +42,57 @@ sdbusplus::async::task<> ExternalDataIFacesImpl::fetchBMCRedundancyMgrProps() co_return; } +// NOLINTNEXTLINE +sdbusplus::async::task<> ExternalDataIFacesImpl::fetchSiblingBmcIP() +{ + // TODO: Currently, the IP addresses for both BMCs are hardcoded. + // Once the network DBus exposes the IPs, update the logic to retrieve + // them dynamically from Dbus. + + // TODO: Handle the exception and exit gracefully, as the data sync relies + // heavily on these DBus properties and cannot function effectively + // without them. + + using SiblingBMCMgr = sdbusplus::client::xyz::openbmc_project::state::bmc:: + redundancy::Sibling<>; + + using SiblingBMC = sdbusplus::common::xyz::openbmc_project::state::bmc:: + redundancy::Sibling; + + std::string siblingBMCInstancePath = + std::string(SiblingBMC::namespace_path::value) + "/" + + SiblingBMC::namespace_path::bmc; + + auto siblingBMCMgr = SiblingBMCMgr(_ctx) + .service(SiblingBMC::interface) + .path(siblingBMCInstancePath); + + auto siblingBMCPosition = co_await siblingBMCMgr.bmc_position(); + + if (siblingBMCPosition == 0) + { + // Using the simics bmc0 eth0 IP address + siblingBmcIP("10.0.2.100"); + } + else + { + // Using the simics bmc1 eth0 IP address + siblingBmcIP("10.2.2.100"); + } + + co_return; +} + +// NOLINTNEXTLINE +sdbusplus::async::task<> ExternalDataIFacesImpl::fetchRbmcCredentials() +{ + // TODO: Currently, the username and password for BMCs are hardcoded. + // Once user management DBus exposes the username and the encrypted password + // available, update the logic to retrieve them dynamically. + + // here, username hardcode as service and password as 0penBmc0 + rbmcCredentials(std::make_pair("service", "0penBmc0")); + co_return; +} + } // namespace data_sync::ext_data diff --git a/src/external_data_ifaces_impl.hpp b/src/external_data_ifaces_impl.hpp index 11ba457..8471850 100644 --- a/src/external_data_ifaces_impl.hpp +++ b/src/external_data_ifaces_impl.hpp @@ -38,6 +38,16 @@ class ExternalDataIFacesImpl : public ExternalDataIFaces */ sdbusplus::async::task<> fetchBMCRedundancyMgrProps() override; + /** + * @brief Used to retrieve the Sibling BMC IP from Dbus. + */ + sdbusplus::async::task<> fetchSiblingBmcIP() override; + + /** + * @brief Used to retrieve the BMC Username and Password. + */ + sdbusplus::async::task<> fetchRbmcCredentials() override; + /** * @brief Used to get the async context */ diff --git a/test/manager_test.cpp b/test/manager_test.cpp index 7be80c0..13e64cd 100644 --- a/test/manager_test.cpp +++ b/test/manager_test.cpp @@ -77,6 +77,14 @@ TEST_F(ManagerTest, ParseDataSyncCfg) // NOLINTNEXTLINE .WillRepeatedly([]() -> sdbusplus::async::task<> { co_return; }); + EXPECT_CALL(*mockExtDataIfaces, fetchSiblingBmcIP()) + // NOLINTNEXTLINE + .WillRepeatedly([]() -> sdbusplus::async::task<> { co_return; }); + + EXPECT_CALL(*mockExtDataIfaces, fetchRbmcCredentials()) + // NOLINTNEXTLINE + .WillRepeatedly([]() -> sdbusplus::async::task<> { co_return; }); + sdbusplus::async::context ctx; data_sync::Manager manager{ctx, std::move(extDataIface), diff --git a/test/mock_ext_data_ifaces.hpp b/test/mock_ext_data_ifaces.hpp index 82a7927..bb5d451 100644 --- a/test/mock_ext_data_ifaces.hpp +++ b/test/mock_ext_data_ifaces.hpp @@ -14,6 +14,8 @@ class MockExternalDataIFaces : public ExternalDataIFaces MOCK_METHOD(sdbusplus::async::task<>, fetchBMCRedundancyMgrProps, (), (override)); + MOCK_METHOD(sdbusplus::async::task<>, fetchSiblingBmcIP, (), (override)); + MOCK_METHOD(sdbusplus::async::task<>, fetchRbmcCredentials, (), (override)); }; } // namespace data_sync::ext_data